Made bottom arrows optional and refactored routes (Closes #72) #76

Merged
snedadah merged 5 commits from opt-arrows into main 2022-11-05 14:06:25 -04:00
8 changed files with 100 additions and 62 deletions

View File

@ -63,7 +63,7 @@
transform: rotate(180deg);
}
@media screen and (max-width: 768px) {
@media screen and (max-width: 1000px) {
.subBox {
flex-direction: column;
align-items: flex-start;
@ -93,6 +93,14 @@
}
.arrow {
width: calc(200rem / 16);
width: 100%;
Review

fixes a horizontal scrolling issue on mobile

fixes a horizontal scrolling issue on mobile
}
}
.containerOnlyRightArrow {
justify-content: flex-end;
}
.containerOnlyLeftArrow {
justify-content: flex-start;
}

View File

@ -4,35 +4,49 @@ import React from "react";
import styles from "./BottomNav.module.css";
interface PagesInfo {
leftPageLink: string;
leftPageName: string;
rightPageLink: string;
rightPageName: string;
leftPage?: {
url: string;
name: string;
};
rightPage?: {
url: string;
name: string;
};
}
export function BottomNav(props: PagesInfo) {
const onlyRightArrow = props.rightPage && !props.leftPage;
const onlyLeftArrow = !props.rightPage && props.leftPage;
return (
<div className={styles.container}>
<div className={styles.subBox + " " + styles.subBoxLeft}>
<Link href={props.leftPageLink}>
<a>
<Arrow />
</a>
</Link>
<Link href={props.leftPageLink}>
<a className={styles.item}>{props.leftPageName}</a>
</Link>
</div>
<div className={styles.subBox}>
<Link href={props.rightPageLink}>
<a className={styles.item}>{props.rightPageName}</a>
</Link>
<Link href={props.rightPageLink}>
<a>
<Arrow isPointingRight />
</a>
</Link>
</div>
<div
className={`${styles.container}
${onlyRightArrow ? styles.containerOnlyRightArrow : ""}
${onlyLeftArrow ? styles.containerOnlyLeftArrow : ""}`}
>
{props.leftPage ? (
<div className={styles.subBox + " " + styles.subBoxLeft}>
<Link href={props.leftPage.url}>
<a>
<Arrow />
</a>
</Link>
<Link href={props.leftPage.url}>
<a className={styles.item}>{props.leftPage.name}</a>
</Link>
</div>
) : null}
{props.rightPage ? (
<div className={styles.subBox}>
<Link href={props.rightPage.url}>
<a className={styles.item}>{props.rightPage.name}</a>
</Link>
<Link href={props.rightPage.url}>
<a>
<Arrow isPointingRight />
</a>
</Link>
</div>
) : null}
</div>
);
}

View File

@ -3,7 +3,7 @@
display: flex;
padding: calc(40rem / 16) calc(50rem / 16);
margin: calc(65rem / 16) 0;
width: 90%;
width: 88%;
}
.wrapperRight {
@ -48,7 +48,7 @@
align-items: center;
}
@media screen and (max-width: 768px) {
@media screen and (max-width: 900px) {
.sideWrapperCommon {
margin: auto;
flex-direction: column;
@ -57,6 +57,10 @@
border-radius: 0;
width: 100%;
}
.wrapperCenter {
padding: 0;
}
}
.internalWrapper {

View File

@ -1,4 +1,4 @@
import { sectionsData } from "data/routes";
import { pageRoutes } from "data/routes";
import Link from "next/link";
import React, { useState } from "react";
@ -61,7 +61,7 @@ export function Header() {
</button>
</div>
<div className={styles.sectionsWrapper}>
<Sections data={sectionsData} showHeader={false} />
<Sections data={pageRoutes} showHeader={false} />
</div>
</div>
</>

View File

@ -1,16 +1,12 @@
import { PageRoutes } from "data/routes";
import React from "react";
import styles from "./Sections.module.css";
interface SectionsData {
name: string;
url: string;
}
interface SectionsProps {
/* Whether to display the "Sections" title and separator that appears on the left. */
showHeader?: boolean;
data: SectionsData[];
data: PageRoutes;
}
export function Sections({ data, showHeader = true }: SectionsProps) {
@ -26,7 +22,7 @@ export function Sections({ data, showHeader = true }: SectionsProps) {
)}
<nav className={styles.nav}>
<ul>
{data.map((datum, index) => {
{Object.values(data).map((datum, index) => {
return (
<li key={`${datum.name}-${index}`}>
<a href={datum.url}>

View File

@ -1,46 +1,65 @@
export const sectionsData = [
{
export interface PageRoute {
name: string;
url: string;
}
type PageID =
| "demographics"
| "academics"
| "coop"
| "lifestyleAndInterests"
| "intimacyAndDrugs"
| "postGrad"
| "friends"
| "miscellaneous"
| "mentalHealth"
| "personal"
| "contributors";
export type PageRoutes = { [key in PageID]: PageRoute };
export const pageRoutes: PageRoutes = {
demographics: {
name: "Demographics",
url: "/demographics",
},
{
academics: {
name: "Academics",
url: "/academics",
},
{
coop: {
name: "Co-op",
url: "/coop",
},
{
lifestyleAndInterests: {
name: "Lifestyle and Interests",
url: "/lifestyle-and-interests",
},
{
intimacyAndDrugs: {
name: "Intimacy and Drugs",
url: "/intimacy-and-drugs",
},
{
postGrad: {
name: "Post-grad",
url: "/postgrad",
url: "/post-grad",
},
{
friends: {
name: "Friends",
url: "/friends",
},
{
miscellaneous: {
name: "Miscellaneous",
url: "/miscellaneous",
},
{
mentalHealth: {
name: "Mental Health",
url: "/mental-health",
},
{
personal: {
name: "Personal",
url: "/personal",
},
{
contributors: {
name: "Contributors",
url: "/contributors",
},
];
};

View File

@ -13,7 +13,7 @@ import {
mockTimelineData,
mockGroupedBarGraphData,
} from "data/mocks";
import { sectionsData } from "data/routes";
import { pageRoutes } from "data/routes";
import React from "react";
import { Color } from "utils/Color";
@ -208,7 +208,7 @@ export default function Home() {
<h2>
<code>{"<Sections />"}</code>
</h2>
<Sections data={sectionsData} />
<Sections data={pageRoutes} />
<h2>
<code>{"<About />"}</code>
@ -245,10 +245,8 @@ export default function Home() {
<code>{"<BottomNav />"}</code>
</h2>
<BottomNav
leftPageLink="/"
leftPageName="Demographics"
rightPageLink="/"
rightPageName="Co-ops"
leftPage={pageRoutes.demographics}
rightPage={pageRoutes.coop}
></BottomNav>
<h2>

View File

@ -1,4 +1,5 @@
import { mockCategoricalData, moreMockCategoricalData } from "data/mocks";
import { pageRoutes } from "data/routes";
import React from "react";
import { useWindowDimensions } from "utils/getWindowDimensions";
import { useIsMobile } from "utils/isMobile";
@ -186,10 +187,8 @@ export default function SamplePage() {
</ComponentWrapper>
<BottomNav
leftPageLink="/"
leftPageName="Demographics"
rightPageLink="/"
rightPageName="Co-ops"
leftPage={pageRoutes.demographics}
rightPage={pageRoutes.contributors}
></BottomNav>
</div>
);