Skip to content

Commit

Permalink
move nav to top
Browse files Browse the repository at this point in the history
  • Loading branch information
AlaraBread committed Apr 15, 2024
1 parent 22b892d commit 7209adc
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 35 deletions.
8 changes: 6 additions & 2 deletions src/app/(pages)/global.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@
border-bottom-style: none;
}

.main_content_minimal {
background-color: var(--bg-color);
}

@media (max-width: 1000px) {
.main_content {
border: none;
border-top: var(--accent-color) solid 0.25rem;
border-radius: 0;
border-top: 0.25rem solid var(--accent-color);
padding: 2rem 1rem;
margin-top: 0rem;
}
.main_content_minimal {
border-top: var(--accent-color) solid 0.25rem;
border-top: 0.25rem solid var(--accent-color);
}
}

Expand Down
21 changes: 6 additions & 15 deletions src/app/(pages)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import type { Metadata } from "next";
import "./globals.scss";
import Players from "./players/players";
import Schedule from "./schedule";
import styles from "./layout.module.scss";
import Navigation from "./navigation";
import RememberTheme from "./remember_theme";
import Script from "next/script";
import { ReactNode } from "react";
import Layout from "./layout_client";

export const metadata: Metadata = {
title: "WJTB Radio",
Expand All @@ -15,7 +11,7 @@ export const metadata: Metadata = {
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
children: ReactNode
}>) {
let basePath = "/";
if(process.env.NEXT_PUBLIC_BASE_PATH != null) {
Expand All @@ -24,14 +20,9 @@ export default function RootLayout({
return (
<html lang="en">
<body>
<Script src={basePath+"js/smoothscroll.min.js"} />
<RememberTheme />
<div className={styles.players}>
<Players />
<Schedule />
</div>
<Navigation />
{children}
<Layout>
{children}
</Layout>
</body>
</html>
);
Expand Down
36 changes: 36 additions & 0 deletions src/app/(pages)/layout_client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use client';

import "./globals.scss";
import { ReactNode } from "react";
import { useWidth } from "../utils/use_width";
import Script from "next/script";
import RememberTheme from "./remember_theme";
import Players from "./players/players";
import Schedule from "./schedule";
import Navigation from "./navigation";
import styles from "./layout.module.scss";

export default function Layout({
children
}: Readonly<{
children: ReactNode
}>) {
let basePath = "/";
if(process.env.NEXT_PUBLIC_BASE_PATH != null) {
basePath = process.env.NEXT_PUBLIC_BASE_PATH.endsWith("/")?process.env.NEXT_PUBLIC_BASE_PATH:process.env.NEXT_PUBLIC_BASE_PATH+"/";
}
let width = useWidth().width;
return (
<>
<Script src={basePath+"js/smoothscroll.min.js"} />
<RememberTheme />
<div className={styles.players}>
<Players />
{width < 1000 ? <Navigation /> : undefined}
<Schedule />
</div>
{width >= 1000 ? <Navigation /> : undefined}
{children}
</>
);
}
2 changes: 1 addition & 1 deletion src/app/(pages)/navigation.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
left: 0;
border: var(--button-width) solid transparent;
border-left-color: var(--text-color);
transition: border-left-color 0.15s ease-out, rotate 0.15s ease-out;
transition: border-left-color 0.15s ease-out, rotate 0.05s ease-out;
rotate: 0deg;
--overall-scale: 1.5;
scale: calc(1.0 * var(--overall-scale)) calc(0.5 * var(--overall-scale));
Expand Down
16 changes: 1 addition & 15 deletions src/app/(pages)/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import styles from "./navigation.module.scss";
import { usePathname } from "next/navigation";
import { Content, Root, Trigger } from "@radix-ui/react-collapsible";
import { useCallback, useEffect, useState } from "react";
import { useWidth } from "../utils/use_width";

function NavLink(props: {href: string, currentPath: string, onClick: () => void, children: React.ReactNode}) {
return (
Expand All @@ -14,21 +15,6 @@ function NavLink(props: {href: string, currentPath: string, onClick: () => void,
);
}

const defaultWidth = 2000;
// from https://blog.logrocket.com/developing-responsive-layouts-with-react-hooks/
const useWidth = () => {
const [width, setWidth] = useState(defaultWidth);

useEffect(() => {
const handleWindowResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleWindowResize);
handleWindowResize();
return () => window.removeEventListener("resize", handleWindowResize);
}, []);

return { width };
}

const pathNames: {[id: string]: string} = {
"/": "Home",
"/request/": "Request Us",
Expand Down
1 change: 0 additions & 1 deletion src/app/(pages)/schedule.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
max-height: 20rem;
border: unset;
border-top: 0.25rem solid var(--accent-color);
border-bottom: 0.25rem solid var(--accent-color);
font-size: 1.25rem;
}
.hide_on_mobile {
Expand Down
1 change: 0 additions & 1 deletion src/app/(pages)/shows/shows.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,5 @@
top: var(--time);
width: 100%;
height: 0;
z-index: -1;
border-bottom: 0.25rem dotted var(--text-light-color);
}
1 change: 1 addition & 0 deletions src/app/(pages)/themes/themes.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use "../global.module.scss";

.container {
@extend .main_content_minimal;
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 1rem;
Expand Down
17 changes: 17 additions & 0 deletions src/app/utils/use_width.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useEffect, useState } from "react";

export const defaultWidth = 2000;

// from https://blog.logrocket.com/developing-responsive-layouts-with-react-hooks/
export function useWidth() {
const [width, setWidth] = useState(defaultWidth);

useEffect(() => {
const handleWindowResize = () => setWidth(window.innerWidth);
window.addEventListener("resize", handleWindowResize);
handleWindowResize();
return () => window.removeEventListener("resize", handleWindowResize);
}, []);

return { width };
}

0 comments on commit 7209adc

Please sign in to comment.