Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion web-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.542.0",
"next-themes": "^0.4.6",
"posthog-js": "^1.249.0",
"react": "^18.2.0",
"react-cookie": "^7.2.2",
"react-dom": "^18.2.0",
"react-hot-toast": "^2.5.2",
"react-icons": "^5.4.0",
"react-icons": "^5.5.0",
"react-router": "^7.1.5",
"react-router-dom": "^7.1.5",
"react-select": "^5.10.1",
Expand All @@ -43,6 +44,7 @@
"devDependencies": {
"@eslint/js": "^9.19.0",
"@tailwindcss/postcss": "^4.1.13",
"@tailwindcss/vite": "^4.1.14",
"@types/node": "^22.13.4",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
Expand All @@ -53,6 +55,7 @@
"eslint-plugin-react-refresh": "^0.4.18",
"globals": "^15.14.0",
"postcss": "^8.5.2",
"rollup": "^4.16.4",
"tailwindcss": "^4.1.13",
"typescript": "~5.7.2",
"typescript-eslint": "^8.22.0",
Expand Down
23 changes: 13 additions & 10 deletions web-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BACKEND_URLS, META } from "./constants";
import { PostHogProvider } from "posthog-js/react";
import { PostHogConfig } from "posthog-js";
import { InvitationHandler } from "./pages/InvitationHandler";
import { ColorModeProvider } from "@/components/ui/color-mode";

const options: Partial<PostHogConfig> = {
api_host: "https://eu.i.posthog.com",
Expand Down Expand Up @@ -53,16 +54,18 @@ const Providers = ({ requireAuth, overrideRedirect = false }: { requireAuth: boo
<PostHogProvider apiKey="phc_qOumHIIkywfbcmxjoI84orWP5Wo2oZVamh83bOUeF5x" options={options}>
<QueryClientProvider client={queryClient}>
<QueryProvider>
<ReactQueryDevtools initialIsOpen={false} />
{!authToken && <Outlet />}
{authToken && (
<SidebarProvider>
<HoppSidebar />
<main className="p-8 w-full">
<Outlet />
</main>
</SidebarProvider>
)}
<ColorModeProvider>
<ReactQueryDevtools initialIsOpen={false} />
{!authToken && <Outlet />}
{authToken && (
<SidebarProvider>
<HoppSidebar />
<main className="p-8 w-full">
<Outlet />
</main>
</SidebarProvider>
)}
</ColorModeProvider>
</QueryProvider>
</QueryClientProvider>
</PostHogProvider>
Expand Down
24 changes: 14 additions & 10 deletions web-app/src/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Logo from "@/assets/Hopp.png";
import { Button } from "./ui/button";
import { resetAllStores, useHoppStore } from "@/store/store";
import { useAPI } from "@/hooks/useQueryClients";
import { ColorModeButton } from "@/components/ui/color-mode-button";

const items = [
{
Expand Down Expand Up @@ -82,16 +83,19 @@ export function HoppSidebar() {
</SidebarGroup>
</SidebarContent>
<SidebarFooter>
<Button
variant="outline"
className="w-full flex flex-row justify-start max-w-min items-start gap-2"
onClick={() => {
resetAllStores();
setAuthToken(null);
}}
>
<HiArrowRightStartOnRectangle /> Logout
</Button>
<div className="flex items-center gap-2 px-2">
<ColorModeButton />
<Button
variant="outline"
className="flex flex-row justify-start items-start gap-2"
onClick={() => {
resetAllStores();
setAuthToken(null);
}}
>
<HiArrowRightStartOnRectangle /> Logout
</Button>
</div>
</SidebarFooter>
</Sidebar>
);
Expand Down
18 changes: 18 additions & 0 deletions web-app/src/components/ui/color-mode-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Button } from "@/components/ui/button"
import { useColorMode } from "./color-mode"
import { LuMoon, LuSun } from "react-icons/lu"

export const ColorModeButton = () => {
const { toggleColorMode, colorMode } = useColorMode()
return (
<Button
onClick={toggleColorMode}
variant="outline"
size="icon"
className="size-9"
aria-label="Toggle color mode"
>
{colorMode === "light" ? <LuSun className="h-[1.2rem] w-[1.2rem]" /> : <LuMoon className="h-[1.2rem] w-[1.2rem]" />}
</Button>
)
}
43 changes: 43 additions & 0 deletions web-app/src/components/ui/color-mode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { createContext, useContext, useEffect, useState } from 'react'

type ColorMode = 'light' | 'dark'
type ColorModeContextType = {
colorMode: ColorMode
toggleColorMode: () => void
}

const ColorModeContext = createContext<ColorModeContextType | undefined>(undefined)

export function ColorModeProvider({ children }: { children: React.ReactNode }) {
const [colorMode, setColorMode] = useState<ColorMode>(() => {
// Check localStorage and system preference
const savedMode = localStorage.getItem('color-mode') as ColorMode
if (savedMode) return savedMode
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
})

useEffect(() => {
const root = window.document.documentElement
root.classList.remove('light', 'dark')
root.classList.add(colorMode)
localStorage.setItem('color-mode', colorMode)
}, [colorMode])

const toggleColorMode = () => {
setColorMode(prev => prev === 'light' ? 'dark' : 'light')
}

return (
<ColorModeContext.Provider value={{ colorMode, toggleColorMode }}>
{children}
</ColorModeContext.Provider>
)
}

export function useColorMode() {
const context = useContext(ColorModeContext)
if (context === undefined) {
throw new Error('useColorMode must be used within a ColorModeProvider')
}
return context
}
2 changes: 1 addition & 1 deletion web-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
)
Loading