diff --git a/README.md b/README.md index 4dfa167..45db2ba 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,12 @@ yarn dev yarn test ``` +## Generate DB types +Replace `abcd12345` with project ID. +```sh +npx supabase gen types typescript --project-id abcd12345 > database.types.ts +``` + ## Deployment ```sh diff --git a/app/components/Navbar.tsx b/app/components/Navbar.tsx index 2eb75e3..376b8a4 100644 --- a/app/components/Navbar.tsx +++ b/app/components/Navbar.tsx @@ -1,37 +1,21 @@ import { useEffect, useState, useRef } from 'react' import { Link } from "@remix-run/react"; -import { useTheme } from '~/utils/ThemeProvider'; import titleLogoImage from "~/assets/title_logo.png" +import useScrollBehavior from '../utils/Navbar/useScrollBehavior'; -export default function Navbar(){ - const [theme, setTheme] = useTheme(); - const toggleTheme = () => { - setTheme((prevTheme) => (prevTheme === "light" ? "dark" : "light")); - }; - const lastScrollY = useRef(0); // useRef allows handler to read updated data - const [navIsShown, setNavIsShown] = useState(true); +type Props = { + setSidePanelIsShown: React.Dispatch>; +}; - const handleScroll = () => { - setNavIsShown(window.scrollY <= lastScrollY.current); - lastScrollY.current = window.scrollY; - }; - - // set up scroll event listener - useEffect(()=>{ - window.addEventListener("scroll", handleScroll); - return () => { - window.removeEventListener("scroll", handleScroll); - }; - }, []) - - const navShownStyle = navIsShown ? "top-0" : "-top-24"; - - return
- {/* */} +export default function Navbar( + {setSidePanelIsShown} +: Props){ + const {navIsShown} = useScrollBehavior(); + return
Profile - Store + - Cart + -
diff --git a/app/components/SidePanel.tsx b/app/components/SidePanel.tsx new file mode 100644 index 0000000..b0739ae --- /dev/null +++ b/app/components/SidePanel.tsx @@ -0,0 +1,25 @@ +import { useTheme } from '~/utils/Navbar/ThemeProvider'; + +type Props = { + sidePanelIsShown: boolean; + setSidePanelIsShown: React.Dispatch>; +}; + +export default function SidePanel( + {sidePanelIsShown, setSidePanelIsShown} +: Props){ + const [theme, setTheme] = useTheme(); + const toggleTheme = () => { + setTheme((prevTheme) => (prevTheme === "light" ? "dark" : "light")); + }; + + return
+ + +
+} \ No newline at end of file diff --git a/app/root.tsx b/app/root.tsx index 9fa9465..031d6b2 100644 --- a/app/root.tsx +++ b/app/root.tsx @@ -17,9 +17,13 @@ import { useLocation } from "@remix-run/react"; import stylesheet from "~/tailwind.css"; -import { ThemeProvider, useTheme, ThemeType } from '~/utils/ThemeProvider'; -import { getThemeSession } from './utils/theme.server'; +import { ThemeProvider, useTheme, ThemeType } from '~/utils/Navbar/ThemeProvider'; +import { getThemeSession } from './utils/Navbar/theme.server'; + + import Navbar from "./components/Navbar"; +import SidePanel from "./components/SidePanel"; + export const links: LinksFunction = () => [ { rel: "stylesheet", href: stylesheet }, @@ -67,10 +71,10 @@ function App() { const [theme] = useTheme(); + const [sidePanelIsShown, setSidePanelIsShown] = useState(false); - - // hide nav for specific routes + // hide for specific routes const location = useLocation(); const routesToHideNavigation = ['/login', '/signup']; const shouldHideNavigation = routesToHideNavigation.includes(location.pathname); @@ -86,7 +90,10 @@ function App() { - {shouldHideNavigation ? null : } + {shouldHideNavigation ? null : <> + + + } diff --git a/app/routes/action.set-theme.tsx b/app/routes/action.set-theme.tsx index 1bb7787..3da7797 100644 --- a/app/routes/action.set-theme.tsx +++ b/app/routes/action.set-theme.tsx @@ -1,8 +1,8 @@ import { json, redirect } from '@remix-run/node'; import type { ActionFunction, LoaderFunction } from '@remix-run/node'; -import { getThemeSession } from '~/utils/theme.server'; -import { isTheme } from '~/utils/ThemeProvider'; +import { getThemeSession } from '~/utils/Navbar/theme.server'; +import { isTheme } from '~/utils/Navbar/ThemeProvider'; export const action: ActionFunction = async ({ request }) => { const themeSession = await getThemeSession(request); diff --git a/app/tailwind.css b/app/tailwind.css index 293cbe9..3aca374 100644 --- a/app/tailwind.css +++ b/app/tailwind.css @@ -22,6 +22,13 @@ body * { } +/* CUSTOM CLASSES */ +.btn { + @apply font-bold py-2 px-4 rounded-lg text-secondary-color bg-primary-color; +} + + + /* SCROLLBAR */ /* width */ ::-webkit-scrollbar { diff --git a/app/utils/ThemeProvider.tsx b/app/utils/Navbar/ThemeProvider.tsx similarity index 100% rename from app/utils/ThemeProvider.tsx rename to app/utils/Navbar/ThemeProvider.tsx diff --git a/app/utils/theme.server.ts b/app/utils/Navbar/theme.server.ts similarity index 100% rename from app/utils/theme.server.ts rename to app/utils/Navbar/theme.server.ts diff --git a/app/utils/Navbar/useScrollBehavior.ts b/app/utils/Navbar/useScrollBehavior.ts new file mode 100644 index 0000000..f54a3e6 --- /dev/null +++ b/app/utils/Navbar/useScrollBehavior.ts @@ -0,0 +1,22 @@ +// navbar behavior: hide/show on scroll down/up +import { useEffect, useState, useRef } from 'react'; + +export default function useScrollBehavior(): ({navIsShown: boolean}){ + const lastScrollY = useRef(0); // useRef allows handler to read updated data + const [navIsShown, setNavIsShown] = useState(true); + + const handleScroll = () => { + setNavIsShown(window.scrollY <= lastScrollY.current); + lastScrollY.current = window.scrollY; + }; + + // set up scroll event listener + useEffect(()=>{ + window.addEventListener("scroll", handleScroll); + return () => { + window.removeEventListener("scroll", handleScroll); + }; + }, []) + + return { navIsShown }; +} \ No newline at end of file