-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a8e5cd
commit 8410293
Showing
32 changed files
with
894 additions
and
260 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
packages/frontpage/app/(app)/_components/notification-indicator-client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
"use client"; | ||
|
||
import useSWR from "swr"; | ||
import { NotificationCountKey } from "./notification-indicator-shared"; | ||
|
||
async function fetchNotificationCount() { | ||
const response = await fetch("/api/notification-count"); | ||
if (!response.ok) { | ||
throw new Error("Failed to fetch notification count"); | ||
} | ||
const count = await response.json(); | ||
if (typeof count !== "number") { | ||
throw new Error("Invalid notification count"); | ||
} | ||
return count; | ||
} | ||
|
||
export function NotificationIndicatorCount() { | ||
const { data: count } = useSWR(NotificationCountKey, fetchNotificationCount, { | ||
suspense: true, | ||
revalidateOnMount: false, | ||
}); | ||
|
||
if (count === 0) return null; | ||
|
||
return ( | ||
<div | ||
className="absolute -top-1 -right-1 w-4 h-4 bg-red-500 text-white text-xs rounded-full flex items-center justify-center" | ||
aria-label={`${count} notifications.`} | ||
> | ||
{count > 9 ? "9+" : count} | ||
</div> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/frontpage/app/(app)/_components/notification-indicator-shared.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const NotificationCountKey = "notificationCount"; |
40 changes: 40 additions & 0 deletions
40
packages/frontpage/app/(app)/_components/notification-indicator.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { ReactNode, Suspense } from "react"; | ||
import { NotificationIndicatorCount } from "./notification-indicator-client"; | ||
import { SWRConfig } from "swr"; | ||
import { getUser } from "@/lib/data/user"; | ||
import { getNotificationCount } from "@/lib/data/db/notification"; | ||
import { ErrorBoundary } from "react-error-boundary"; | ||
import { NotificationCountKey } from "./notification-indicator-shared"; | ||
|
||
export async function NotificationIndicator({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) { | ||
const user = await getUser(); | ||
if (user === null) return null; | ||
return ( | ||
<div className="relative"> | ||
{children} | ||
<ErrorBoundary fallback={null}> | ||
<Suspense> | ||
<NotificationIndicatorInner /> | ||
</Suspense> | ||
</ErrorBoundary> | ||
</div> | ||
); | ||
} | ||
|
||
function NotificationIndicatorInner() { | ||
return ( | ||
<SWRConfig | ||
value={{ | ||
fallback: { | ||
[NotificationCountKey]: getNotificationCount(), | ||
}, | ||
}} | ||
> | ||
<NotificationIndicatorCount /> | ||
</SWRConfig> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
63 changes: 25 additions & 38 deletions
63
packages/frontpage/app/(app)/_components/theme-toggle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,36 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { SunIcon, MoonIcon } from "@radix-ui/react-icons"; | ||
import { SunIcon, MoonIcon, Half2Icon } from "@radix-ui/react-icons"; | ||
import { useTheme } from "next-themes"; | ||
|
||
import { Button } from "@/lib/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
DropdownMenuLabel, | ||
DropdownMenuRadioGroup, | ||
DropdownMenuRadioItem, | ||
DropdownMenuSeparator, | ||
} from "@/lib/components/ui/dropdown-menu"; | ||
|
||
export function ThemeToggle() { | ||
const { theme, setTheme } = useTheme(); | ||
|
||
export function ThemeToggleMenuGroup() { | ||
const { setTheme, theme } = useTheme(); | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="outline" size="icon"> | ||
<SunIcon className="h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" /> | ||
<MoonIcon className="absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" /> | ||
<span className="sr-only">Toggle theme</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="space-y-0.5" align="end"> | ||
<DropdownMenuItem | ||
className={`${theme === "light" ? "bg-accent" : ""}`} | ||
onClick={() => setTheme("light")} | ||
> | ||
Light | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
className={`${theme === "dark" ? "bg-accent" : ""}`} | ||
onClick={() => setTheme("dark")} | ||
> | ||
Dark | ||
</DropdownMenuItem> | ||
<DropdownMenuItem | ||
className={`${theme === "system" ? "bg-accent" : ""}`} | ||
onClick={() => setTheme("system")} | ||
> | ||
System | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
<> | ||
<DropdownMenuLabel className="truncate">Theme</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
<DropdownMenuRadioGroup value={theme} onValueChange={setTheme}> | ||
<DropdownMenuRadioItem value="light" className="flex gap-1.5"> | ||
<SunIcon className="size-4" /> | ||
<span>Light</span> | ||
</DropdownMenuRadioItem> | ||
<DropdownMenuRadioItem value="dark" className="flex gap-1.5"> | ||
<MoonIcon className="h-[1.2rem] w-[1.2rem]" /> | ||
<span>Dark</span> | ||
</DropdownMenuRadioItem> | ||
<DropdownMenuRadioItem value="system" className="flex gap-1.5"> | ||
<Half2Icon className="h-[1.2rem] w-[1.2rem]" /> | ||
<span>System</span> | ||
</DropdownMenuRadioItem> | ||
</DropdownMenuRadioGroup> | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.