From 1ed8634b88637bfc9162171d97963e1d8c96a05d Mon Sep 17 00:00:00 2001 From: DrMint Date: Sun, 7 Nov 2021 20:17:54 +0100 Subject: [PATCH] Added components like Return buttons and Navoption --- src/components/Panels/MainPanel.tsx | 68 +++++++++++++++-------- src/components/Panels/NavOption.tsx | 28 ++++++++++ src/components/Panels/ReturnButton.tsx | 17 ++++++ src/pages/chronology/index.tsx | 29 +++++++++- src/pages/chronology/overview.tsx | 31 ++++++++--- src/queries/queries.ts | 10 +--- src/styles/Panels/NavOption.module.css | 46 +++++++++++++++ src/styles/Panels/Panels.module.css | 37 ------------ src/styles/Panels/ReturnButton.module.css | 0 9 files changed, 187 insertions(+), 79 deletions(-) create mode 100644 src/components/Panels/NavOption.tsx create mode 100644 src/components/Panels/ReturnButton.tsx create mode 100644 src/styles/Panels/NavOption.module.css create mode 100644 src/styles/Panels/ReturnButton.module.css diff --git a/src/components/Panels/MainPanel.tsx b/src/components/Panels/MainPanel.tsx index 0042902..26c7280 100644 --- a/src/components/Panels/MainPanel.tsx +++ b/src/components/Panels/MainPanel.tsx @@ -1,26 +1,10 @@ import Link from 'next/link' -import { useRouter } from 'next/router' import styles from 'styles/Panels/MainPanel.module.css' import panelStyles from 'styles/Panels/Panels.module.css' +import NavOption from 'components/Panels/NavOption' export default function MainPanel() { - const router = useRouter(); - - function generateMenuOption(url: string, icon: string, title: string, subtitle?: string) { - console.log(router.asPath, url) - const classActive = router.asPath.startsWith(url) ? panelStyles.active : null; - return ( - -
- -

{title}

-

{subtitle}

-
- - ) - } - return (
@@ -36,16 +20,52 @@ export default function MainPanel() {
- {generateMenuOption("/library", "/icons/book-solid.svg", "Library", "Browse all physical and digital media")} - {generateMenuOption("/hubs", "/icons/hubs.svg", "Hubs", "Explore all content of a specific game/series")} - {generateMenuOption("/chronology", "/icons/timeline-solid.svg", "Chronology", "Follow all events in chronological order")} + + + + +
- {generateMenuOption("/archive", "/icons/box-archive-solid.svg", "Archive")} - {generateMenuOption("/news", "/icons/newspaper-solid.svg", "News")} - {generateMenuOption("/gallery", "/icons/images-solid.svg", "Gallery")} - {generateMenuOption("/about-us", "/icons/circle-info-solid.svg", "About us")} + + + + + + +
diff --git a/src/components/Panels/NavOption.tsx b/src/components/Panels/NavOption.tsx new file mode 100644 index 0000000..3be719f --- /dev/null +++ b/src/components/Panels/NavOption.tsx @@ -0,0 +1,28 @@ +import { useRouter } from 'next/router' +import styles from 'styles/Panels/NavOption.module.css' +import Link from 'next/link' + +type NavOptionProps = { + url: string, + icon?: string, + title: string, + subtitle?: string + border?: boolean +} + +export default function NavOption(pageProps: NavOptionProps) { + const router = useRouter(); + let classNames = [styles.menuOption] + if (router.asPath.startsWith(pageProps.url)) classNames.push(styles.active) + if (pageProps.icon) classNames.push(styles.icon) + if (pageProps.border === true) classNames.push(styles.border) + return ( + +
+ {pageProps.icon && } +

{pageProps.title}

+ {pageProps.subtitle &&

{pageProps.subtitle}

} +
+ + ) +} \ No newline at end of file diff --git a/src/components/Panels/ReturnButton.tsx b/src/components/Panels/ReturnButton.tsx new file mode 100644 index 0000000..3fa195f --- /dev/null +++ b/src/components/Panels/ReturnButton.tsx @@ -0,0 +1,17 @@ +import styles from 'styles/Panels/ReturnButton.module.css' +import Link from 'next/link' + +type ReturnButtonProps = { + url: string, + title: string +} + +export default function ReturnButton(pageProps: ReturnButtonProps) { + return ( + + + + ) +} \ No newline at end of file diff --git a/src/pages/chronology/index.tsx b/src/pages/chronology/index.tsx index ad60111..e782af0 100644 --- a/src/pages/chronology/index.tsx +++ b/src/pages/chronology/index.tsx @@ -1,13 +1,40 @@ import type { NextPage } from 'next' import SubPanel from 'components/Panels/SubPanel' +import styles from 'styles/Panels/SubPanel.module.css' +import NavOption from 'components/Panels/NavOption' const Chronology: NextPage = () => { return ( <> - Hello +

Chronology

+

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vulputate facilisis blandit. Aliquam blandit neque sem, ac pulvinar leo ultricies sit amet.

+
+ + + + + + +
+ ) } diff --git a/src/pages/chronology/overview.tsx b/src/pages/chronology/overview.tsx index 5066575..8b19493 100644 --- a/src/pages/chronology/overview.tsx +++ b/src/pages/chronology/overview.tsx @@ -1,25 +1,30 @@ import type { NextPage } from 'next' -import Head from 'next/head' import { useRouter } from 'next/router' import { GetStaticProps } from 'next' import ContentPanel from 'components/Panels/ContentPanel' import SubPanel from 'components/Panels/SubPanel' - +import ReturnButton from 'components/Panels/ReturnButton' +import NavOption from 'components/Panels/NavOption' import { getChronologyItems } from 'queries/queries' -export const getStaticProps: GetStaticProps = async (context) => { - return await getChronologyItems() -} - -const ChronologyOverview: NextPage = ({ chronologyItems }) => { +const ChronologyOverview: NextPage = ( props ) => { const router = useRouter() return ( <> - Hello + + +
+ +
- {chronologyItems.map((item: any) => ( + {props.chronologyItems.map((item: any) => (
{item.year} -{' '} { item.translations.map((translation: any) => ( @@ -39,3 +44,11 @@ const ChronologyOverview: NextPage = ({ chronologyItems }) => { ) } export default ChronologyOverview + +export const getStaticProps: GetStaticProps = async (context) => { + return { + props: { + chronologyItems: await getChronologyItems(), + }, + } +} diff --git a/src/queries/queries.ts b/src/queries/queries.ts index 64df291..9a92ed5 100644 --- a/src/queries/queries.ts +++ b/src/queries/queries.ts @@ -1,7 +1,6 @@ export const getChronologyItems = async () => { const res = await fetch( - process.env.NEXT_PUBLIC_GRAPHQL + `?query={ - + process.env.GRAPHQL + '?access_token=' + process.env.ACCESS_TOKEN + `&query={ chronology_items { id, year, @@ -17,10 +16,5 @@ export const getChronologyItems = async () => { }`) - const data = (await res.json()).data.chronology_items - return { - props: { - chronologyItems: data, - }, - } + return (await res.json()).data.chronology_items } \ No newline at end of file diff --git a/src/styles/Panels/NavOption.module.css b/src/styles/Panels/NavOption.module.css new file mode 100644 index 0000000..7c337cf --- /dev/null +++ b/src/styles/Panels/NavOption.module.css @@ -0,0 +1,46 @@ +.menuOption { + display: grid; + grid-template-areas: 'title' 'subtitle'; + align-items: center; + border-radius: 1em; + grid-column-gap: 1em; + cursor: pointer; + padding: 0.6em 1.2em; + width: 100%; + transition: .1s background-color; + text-align: center; +} + +.menuOption.icon { + grid-template-areas: 'icon title' '. subtitle'; + grid-template-columns: auto 1fr; + text-align: start; +} + +.menuOption.border { + border: 1px solid var(--color-main-base); +} + + +.menuOption:hover, .menuOption.active { + background-color: var(--color-main-base); +} + +.menuOption > * { + margin: 0; +} + +.menuOption > img { + width: 1.2em; + height: auto; + grid-area: icon; +} + +.menuOption > h3 { + grid-area: title; + font-size: 150%; +} + +.menuOption > p { + grid-area: subtitle; +} \ No newline at end of file diff --git a/src/styles/Panels/Panels.module.css b/src/styles/Panels/Panels.module.css index 048fe8c..c65d340 100644 --- a/src/styles/Panels/Panels.module.css +++ b/src/styles/Panels/Panels.module.css @@ -21,41 +21,4 @@ border: none; border-top: 0.3rem dotted black; margin: 2rem; -} - -.menuOption { - justify-self: start; - display: grid; - grid-template-areas: 'img title' '. subtitle'; - grid-template-columns: auto 1fr; - align-items: center; - border-radius: 1em; - grid-column-gap: 1em; - cursor: pointer; - padding: 0.6em 1.2em; - width: 100%; - transition: .1s background-color; -} - -.menuOption:hover, .menuOption.active { - background-color: var(--color-main-base); -} - -.menuOption > * { - margin: 0; -} - -.menuOption > img { - width: 1.2em; - height: auto; - grid-area: img; -} - -.menuOption > h3 { - grid-area: title; - font-size: 150%; -} - -.menuOption > p { - grid-area: subtitle; } \ No newline at end of file diff --git a/src/styles/Panels/ReturnButton.module.css b/src/styles/Panels/ReturnButton.module.css new file mode 100644 index 0000000..e69de29