From 6a2dc0d4d8622c2f16444d4f0427d9485e35d9aa Mon Sep 17 00:00:00 2001 From: Neshura Date: Sat, 17 Dec 2022 01:20:58 +0100 Subject: [PATCH 1/3] Progress on #18 --- components/styles/content.tsx | 152 ++++++++++++++++++----- components/styles/generic.tsx | 15 ++- interfaces/{Services.ts => CardTypes.ts} | 20 ++- interfaces/LinkTypes.ts | 17 --- pages/api/services.tsx | 4 +- pages/games.tsx | 26 +--- pages/services.tsx | 42 +++---- 7 files changed, 167 insertions(+), 109 deletions(-) rename interfaces/{Services.ts => CardTypes.ts} (63%) delete mode 100644 interfaces/LinkTypes.ts diff --git a/components/styles/content.tsx b/components/styles/content.tsx index a0b6564..f0e6461 100644 --- a/components/styles/content.tsx +++ b/components/styles/content.tsx @@ -1,8 +1,7 @@ import Link from 'next/link'; import Image from 'next/image'; -import styled, { DefaultTheme } from 'styled-components'; -import { CustomLink } from '../../interfaces/LinkTypes'; -import { Service } from '../../interfaces/Services'; +import styled, { css, DefaultTheme } from 'styled-components'; +import { Service, Game } from '../../interfaces/CardTypes'; // needed for Online Status checks // TODO: migrate to shared Status type for Games and Services @@ -16,7 +15,7 @@ export const PageTitle = styled.h1` line-height: 1.15; font-size: 4rem; text-align: center; -` +`; // replaces .description export const PageDescription = styled.p` @@ -24,7 +23,7 @@ export const PageDescription = styled.p` line-height: 1.5; font-size: 1.5rem; text-align: center; -` +`; // replaces .grid export const PageContentBox = styled.div` @@ -33,12 +32,29 @@ export const PageContentBox = styled.div` justify-content: center; flex-wrap: wrap; max-width: 80%; -` +`; + +const CardStyle = css` + display: flex; + flex-direction: column; + align-items: center; + position: relative; + width: 332px; + height: 240px; +`; + +const CardLink = styled(Link)` + ${CardStyle} +`; + +const CardStyleWrap = styled.div` + ${CardStyle} +`; // replaces .card & .contentcard export const PageCard = styled.div` margin: 1rem; - padding: 1rem; + padding: 1.5rem 0.7rem 1.5rem 0.7rem; text-align: center; color: ${({ theme }) => theme.colors.primary}; text-decoration: none; @@ -46,7 +62,11 @@ export const PageCard = styled.div` border-radius: 10px; border-color: ${({ theme }) => theme.colors.primary}; transition: color 0.15s ease, border-color 0.15s ease; - max-width: 300px; + width: 300px; + height: 200px; + display: flex; + flex-direction: column; + justify-content: space-between; h2 { margin: 0 0 1rem 0; @@ -55,15 +75,20 @@ export const PageCard = styled.div` p { margin: 0; - font-size: 1.2rem; + font-size: 1rem; line-height: 1.5; } - &:focus,:active,:hover { + ${CardStyleWrap}:focus,${CardStyleWrap}:active,${CardStyleWrap}:hover & { color: ${({ theme }) => theme.colors.secondary}; border-color: ${({ theme }) => theme.colors.secondary}; } -` + + ${CardLink}:focus,${CardLink}:active,${CardLink}:hover & { + color: ${({ theme }) => theme.colors.secondary}; + border-color: ${({ theme }) => theme.colors.secondary}; + } +`; // replaces the three status classes const OnlineStatus = styled.p` @@ -84,12 +109,31 @@ const OnlineStatus = styled.p` } return ret; }}; -` + padding: 0.2rem; + background-color: ${({ theme }) => theme.colors.background}; + border: 1px solid; + border-color: ${({ theme }) => theme.colors.primary}; + border-radius: 5px; + width: min-content; + position: absolute; + top: 100; right: 50; bottom: 0; left: 50; + offset-position: bottom 10px; + transition: color 0.15s ease, border-color 0.15s ease; + + ${CardStyleWrap}:focus,${CardStyleWrap}:active,${CardStyleWrap}:hover & { + border-color: ${({ theme }) => theme.colors.secondary}; + } + + ${CardLink}:focus,${CardLink}:active,${CardLink}:hover & { + border-color: ${({ theme }) => theme.colors.secondary}; + } +`; // replaces .cardwarn const CardContentWarning = styled.p` color: ${({ theme }) => theme.colors.secondary}; -` + +`; // replaces .contentIcon const CardContentTitleIcon = styled.div` @@ -98,7 +142,7 @@ const CardContentTitleIcon = styled.div` position: relative; aspect-ratio: 1; height: 1.5rem; -` +`; // replaces .contentTitle const CardContentTitleWrap = styled.div` @@ -112,9 +156,9 @@ const CardContentTitleWrap = styled.div` margin: 0; white-space: nowrap; } -` +`; -const CardContentTitle = ({ content }: { content: Service | CustomLink }) => { +const CardContentTitle = ({ content }: { content: Service | Game }) => { return ( { @@ -130,25 +174,67 @@ const CardContentTitle = ({ content }: { content: Service | CustomLink }) => { } // Card Content Component for Games Page -export const CardContentGame = ({ content }: { content: CustomLink }) => { - return ( - <> - -

{content.desc}

-

{content.ip}

- {content.status} - - ) +export const CardContentGame = ({ content }: { content: Game }) => { + let ret; + if (content.href) { + ret = ( + + + +

{content.desc}

+

{content.ip}

+
+ {content.status ? + {content.status} + : <> + } +
+ ) + } + else { + ret = ( + + + +

{content.desc}

+

{content.ip}

+
+ {content.status ? + {content.status} + : <> + } +
+ ) + } + return ret; } // Card Content Component for Services Page export const CardContentService = ({ content }: { content: Service }) => { - return ( - <> - - {content.status} -

{content.desc}

- {content.warn} - - ) + let ret; + if (content.href) { + ret = ( + + + +

{content.desc}

+ {content.warn} +
+ {content.status} +
+ ) + } + else { + ret = ( + + + +

{content.desc}

+ {content.warn} +
+ {content.status} +
+ ) + } + return ret; } \ No newline at end of file diff --git a/components/styles/generic.tsx b/components/styles/generic.tsx index bf14ba1..31298ed 100644 --- a/components/styles/generic.tsx +++ b/components/styles/generic.tsx @@ -31,12 +31,11 @@ export const Footer = styled.footer` border-top: 1px solid ${({ theme }) => theme.colors.primary }; justify-content: center; align-items: center; -` -// TODO -/* .footer a { - display: flex; - justify-content: center; - align-items: center; - flex-grow: 1; -} */ + a { + display: flex; + justify-content: center; + align-items: center; + flex-grow: 1; + } +` diff --git a/interfaces/Services.ts b/interfaces/CardTypes.ts similarity index 63% rename from interfaces/Services.ts rename to interfaces/CardTypes.ts index 29178b4..aabe411 100644 --- a/interfaces/Services.ts +++ b/interfaces/CardTypes.ts @@ -1,3 +1,16 @@ +export interface EntryList { + services: Service[], + games: Game[] +} +export interface Game { + name: string, + icon: string, + href: string, + desc: string, + ip: string, + status: Status, +} + export interface Service { name: string, icon: string, @@ -7,10 +20,10 @@ export interface Service { type: ServiceType, docker_container_name: string, location: ServiceLocation, - status: ServiceStatus + status: Status, } -export enum ServiceStatus { +export enum Status { online = "Online", offline = "Offline", loading = "Loading", @@ -25,4 +38,5 @@ export enum ServiceLocation { export enum ServiceType { docker = "docker", app = "app" -} \ No newline at end of file +} + diff --git a/interfaces/LinkTypes.ts b/interfaces/LinkTypes.ts deleted file mode 100644 index be23ed4..0000000 --- a/interfaces/LinkTypes.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Service } from "./Services" - -export interface EntryList { - services: Service[], - games: CustomLink[] -} -export interface CustomLink { - name: string, - href: string, - desc: string, - ip: string, - type: string, - location: string, - status: string, - docker_container_name: string -} - diff --git a/pages/api/services.tsx b/pages/api/services.tsx index 0adf0a8..a2627b4 100644 --- a/pages/api/services.tsx +++ b/pages/api/services.tsx @@ -1,6 +1,6 @@ import fsPromises from 'fs/promises' import path from 'path' -import { Service, ServiceStatus } from '../../interfaces/Services'; +import { Service, Status } from '../../interfaces/CardTypes'; export default async function ServicesAPI(req: any, res: any) { try { @@ -8,7 +8,7 @@ export default async function ServicesAPI(req: any, res: any) { const data = await fsPromises.readFile(filePath) .then((file) => JSON.parse(file.toString())); data.services.forEach((service: Service) => { - service.status = ServiceStatus.loading; + service.status = Status.loading; }); res.status(200).json(data.services); diff --git a/pages/games.tsx b/pages/games.tsx index ab71b03..6992a26 100644 --- a/pages/games.tsx +++ b/pages/games.tsx @@ -1,8 +1,8 @@ import Head from 'next/head' import fsPromises from 'fs/promises' import path from 'path' -import type { CustomLink, EntryList } from '../interfaces/LinkTypes' -import { PageContentBox, PageCard, PageDescription, PageTitle, CardContentGame } from '../components/styles/content' +import { EntryList, Game } from '../interfaces/CardTypes'; +import { PageContentBox, PageDescription, PageTitle, CardContentGame } from '../components/styles/content' import Link from 'next/link' function Servers(props: EntryList) { @@ -24,25 +24,9 @@ function Servers(props: EntryList) { - {Object.values(serverList).map((item: CustomLink) => { - if (item.href != null) { - return ( - - - - - - ) - } - else { - return ( - - - - ) - } - } - )} + {Object.values(serverList).map((item: Game) => ( + + ))} ) diff --git a/pages/services.tsx b/pages/services.tsx index 3921a80..360b689 100644 --- a/pages/services.tsx +++ b/pages/services.tsx @@ -1,6 +1,6 @@ import Head from 'next/head' import Link from 'next/link' -import { Service, ServiceStatus, ServiceType, ServiceLocation } from '../interfaces/Services'; +import { Service, Status, ServiceType, ServiceLocation } from '../interfaces/CardTypes'; import Dockerode from 'dockerode'; import { ReactElement } from 'react' import useSWR from 'swr'; @@ -19,11 +19,7 @@ function Services() { content = {initialData?.map((item: Service) => ( - - - - - + ))} @@ -32,11 +28,7 @@ function Services() { content = {fullData.map((item: Service) => ( - - - - - + ))} } @@ -81,19 +73,19 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[]) case 200: case 301: case 302: - entry.status = ServiceStatus.online; + entry.status = Status.online; break; default: - entry.status = ServiceStatus.offline; + entry.status = Status.offline; } } else { - entry.status = ServiceStatus.offline; + entry.status = Status.offline; } }) .catch((error) => { console.error("Error pinging Website: ", error); - entry.status = ServiceStatus.error; + entry.status = Status.error; }) } // Type Docker @@ -107,11 +99,11 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[]) // so far only "running" is properly implemented, mroe cases to follow as needed switch (container.State) { case "running": - entry.status = ServiceStatus.online; + entry.status = Status.online; break; default: console.log("Container Status " + container.State + " has no case implemented"); - entry.status = ServiceStatus.offline; + entry.status = Status.offline; } found = true; // cancel the for @@ -119,7 +111,7 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[]) } // If container name is not missing the container is set to offline else { - entry.status = ServiceStatus.offline; + entry.status = Status.offline; } } if (!found) { @@ -129,13 +121,13 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[]) // if name is null do not enter for loop else { console.error("Container Name not specified"); - entry.status = ServiceStatus.error; + entry.status = Status.error; } } // If no Type matches else { console.warn("Service Type for Service " + entry.name + " not specified or invalid"); - entry.status = ServiceStatus.error; + entry.status = Status.error; } } // Location Other @@ -149,25 +141,25 @@ async function getStatus(entry: Service, containers: Dockerode.ContainerInfo[]) case 200: case 301: case 302: - entry.status = ServiceStatus.online; + entry.status = Status.online; break; default: - entry.status = ServiceStatus.offline; + entry.status = Status.offline; } } else { - entry.status = ServiceStatus.offline; + entry.status = Status.offline; } }) .catch((error) => { console.error("Error pinging Website: ", error); - entry.status = ServiceStatus.error; + entry.status = Status.error; }) } // If no Location matches else { console.warn("Service Location for Service " + entry.name + " not specified"); - entry.status = ServiceStatus.error; + entry.status = Status.error; } return entry; } From 5ec6bf8c2922dcb7f4cbcb8320dbd05cd450158f Mon Sep 17 00:00:00 2001 From: Neshura Date: Sat, 17 Dec 2022 01:56:41 +0100 Subject: [PATCH 2/3] Progress on #18, #3 --- components/styles/navbar.tsx | 1 + components/styles/themedropdown.tsx | 31 ++++++++++++++++++++++++----- components/themeselector.tsx | 2 +- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/components/styles/navbar.tsx b/components/styles/navbar.tsx index 01eb8e3..fda435e 100644 --- a/components/styles/navbar.tsx +++ b/components/styles/navbar.tsx @@ -27,6 +27,7 @@ export const NavLink = styled(Link)` color: ${props => props.active ? ({ theme }) => theme.colors.secondary : ({ theme }) => theme.colors.primary}; margin: 0.2rem; border: 1px solid; + border-radius: 5px; padding: 0.2rem 0.5rem; display: flex; justify-content: center; diff --git a/components/styles/themedropdown.tsx b/components/styles/themedropdown.tsx index 43f9528..a11879b 100644 --- a/components/styles/themedropdown.tsx +++ b/components/styles/themedropdown.tsx @@ -16,36 +16,57 @@ export const ThemeDropDown = styled.div` flex-direction: column; ` -export const ThemeDropDownButton = styled.button` - width: 90%; +export const ThemeDropDownButton = styled.button` + width: 160px; border: 1px solid; + border-radius: 5px; background-color: ${({ theme }) => theme.colors.background}; padding: 0.2rem 0.5rem; cursor: pointer; color: ${({ theme }) => theme.colors.primary}; - transition: color 0.15s ease; + + transition-property: color, border-bottom-left-radius, border-bottom-right-radius; + transition-timing-function: ease; + transition-duration: 0.15s; &:focus,:hover { color: ${({ theme }) => theme.colors.secondary}; } + + border-bottom-left-radius: ${ props => props.show ? "0" : "" }; + border-bottom-right-radius: ${ props => props.show ? "0" : "" }; ` export const ThemeDropDownOptions = styled.div` position: absolute; color: ${({ theme }) => theme.colors.primary}; background-color: ${({ theme }) => theme.colors.background}; - display: ${ props => props.show ? "flex" : "none" }; + display: flex; flex-direction: column; min-width: 160px; + border: 1px solid; + border-top: 0; + border-radius: 5px; + border-top-left-radius: 0px; border-top-right-radius: 0px; z-index: 1; + overflow: hidden; + max-height: ${ props => props.show ? "20%" : "0%" }; + visibility: ${ props => props.show ? "visible" : "hidden" }; + + transition-property: max-height, visibility; + transition-timing-function: ease-in-out; + transition-duration: 0.6s, 0s; + transition-delay: 0s, ${ props => props.show ? "0s" : "0.5s" }; ` export const ThemeDropDownOption = styled.button` color: ${ props => props.active ? ({ theme }) => theme.colors.secondary : ({ theme }) => theme.colors.primary }; background-color: ${({ theme }) => theme.colors.background}; - border: 1px solid; + align-self: center; + border: 0px solid; padding: 0.2rem 0.5rem; text-decoration: none; + width: 90%; &:hover { color: ${({ theme }) => theme.colors.secondary}; diff --git a/components/themeselector.tsx b/components/themeselector.tsx index 8e771a6..8db0066 100644 --- a/components/themeselector.tsx +++ b/components/themeselector.tsx @@ -55,7 +55,7 @@ export const StyleSelector = () => { return ( handleBlur(event)}> - setTest(test => !test)}>{selectedTheme.themeName} + setTest(test => !test)}>{selectedTheme.themeName} {themes.map((theme) => ( updateThemeWithStorage(theme)}> From 3d5d712eb91e7cd60e5b41d8621c5d13163acf8e Mon Sep 17 00:00:00 2001 From: Neshura Date: Sat, 17 Dec 2022 02:17:54 +0100 Subject: [PATCH 3/3] reduced NavBar padding to 1rem --- components/styles/navbar.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/styles/navbar.tsx b/components/styles/navbar.tsx index fda435e..d3642ed 100644 --- a/components/styles/navbar.tsx +++ b/components/styles/navbar.tsx @@ -17,7 +17,7 @@ export const NavBar = styled.nav` margin-right: 1%; display: flex; flex: 1; - padding: 2rem 0; + padding: 1rem 0; flex-wrap: nowrap; justify-content: center; align-items: center;