summaryrefslogtreecommitdiff
path: root/apps/web/app/reader/_components/sidebar-footer.tsx
blob: 4b1b29377bdc7173134f22fd87c8b33246c4313d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"use client"

import { useState } from "react"
import Link from "next/link"
import { useUserInterfaceStore } from "@/lib/stores/user-interface-store"
import { useUserProfile } from "@/lib/queries/use-user-profile"
import { signOut } from "../actions"
import {
  NotificationPanel,
  useUnviewedNotificationCount,
} from "./notification-panel"

export function SidebarFooter() {
  const toggleSidebar = useUserInterfaceStore((state) => state.toggleSidebar)
  const setActiveSettingsTab = useUserInterfaceStore(
    (state) => state.setActiveSettingsTab
  )
  const [isNotificationPanelOpen, setIsNotificationPanelOpen] = useState(false)
  const unviewedNotificationCount = useUnviewedNotificationCount()
  const { data: userProfile } = useUserProfile()

  const displayName = userProfile?.displayName ?? "account"

  function closeSidebarOnMobile() {
    if (typeof window !== "undefined" && window.innerWidth < 768) {
      toggleSidebar()
    }
  }

  return (
    <div data-sidebar-footer className="border-t border-border p-2">
      <Link
        href="/reader/settings"
        onClick={() => {
          setActiveSettingsTab("account")
          closeSidebarOnMobile()
        }}
        className="block whitespace-nowrap truncate px-2 py-1 text-text-secondary transition-colors hover:bg-background-tertiary hover:text-text-primary"
      >
        {displayName}
      </Link>
      <Link
        href="/reader/settings"
        onClick={closeSidebarOnMobile}
        className="block whitespace-nowrap px-2 py-1 text-text-secondary transition-colors hover:bg-background-tertiary hover:text-text-primary"
      >
        settings
      </Link>
      <div className="relative">
        <button
          type="button"
          onClick={() => setIsNotificationPanelOpen(!isNotificationPanelOpen)}
          className="w-full whitespace-nowrap px-2 py-1 text-left text-text-secondary transition-colors hover:bg-background-tertiary hover:text-text-primary"
        >
          notifications
          {unviewedNotificationCount > 0 && (
            <span className="ml-1 inline-flex h-4 min-w-4 items-center justify-center bg-accent-primary px-1 text-[0.6875rem] text-background-primary">
              {unviewedNotificationCount}
            </span>
          )}
        </button>
        {isNotificationPanelOpen && (
          <NotificationPanel
            onClose={() => setIsNotificationPanelOpen(false)}
          />
        )}
      </div>
      <form action={signOut}>
        <button
          type="submit"
          onClick={closeSidebarOnMobile}
          className="w-full whitespace-nowrap px-2 py-1 text-left text-text-secondary transition-colors hover:bg-background-tertiary hover:text-text-primary"
        >
          sign out
        </button>
      </form>
    </div>
  )
}