hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { createEffect, createMemo, createSignal } from "solid-js"; |
| 2 | import { useNavigate } from "@tanstack/solid-router"; |
| 3 | import { FloatingActionButton, type FloatingAction } from "@/components/layout/floating-action-button"; |
| 4 | import { createNotificationFeed } from "@/components/layout/notification-feed"; |
| 5 | import { NotificationList } from "@/components/layout/notification-list"; |
| 6 | import { SidePanel } from "@/components/ui/side-panel"; |
| 7 | import { IconBell, IconMessage, IconSparkles } from "@/components/ui/icons"; |
| 8 | import { openCelebiPanel } from "@/stores/celebi-panel"; |
| 9 | import { useModules } from "@/stores/modules-context"; |
| 10 | import { useShellFeed } from "@/stores/shell-feed-context"; |
| 11 | import { useT } from "@/stores/preferences-context"; |
| 12 | |
| 13 | /** |
| 14 | * What the desktop header offers — messages, notifications, Çelebi — on a |
| 15 | * phone, behind the floating action button. Notifications open in a panel |
| 16 | * rather than the header's popover: a popover anchored to a button the user |
| 17 | * can drag anywhere would open off screen. |
| 18 | */ |
| 19 | export function MobileQuickActions(props: { hidden: boolean }) { |
| 20 | const t = useT(); |
| 21 | const navigate = useNavigate(); |
| 22 | const modules = useModules(); |
| 23 | const feed = useShellFeed(); |
| 24 | const notifications = createNotificationFeed(); |
| 25 | const [notificationsOpen, setNotificationsOpen] = createSignal(false); |
| 26 | |
| 27 | createEffect(() => { |
| 28 | if (notificationsOpen()) { |
| 29 | notifications.opened(); |
| 30 | notifications.refreshAll(); |
| 31 | } |
| 32 | }); |
| 33 | |
| 34 | const actions = createMemo(() => { |
| 35 | const list: FloatingAction[] = []; |
| 36 | if (modules.isEnabled("messages")) { |
| 37 | list.push({ |
| 38 | id: "messages", |
| 39 | label: t("nav.messages"), |
| 40 | Icon: IconMessage, |
| 41 | badge: feed.unreadMessages().total, |
| 42 | onSelect: () => void navigate({ to: "/messages" }), |
| 43 | }); |
| 44 | } |
| 45 | list.push({ |
| 46 | id: "notifications", |
| 47 | label: t("notifications.title"), |
| 48 | Icon: IconBell, |
| 49 | badge: notifications.unreadCount(), |
| 50 | onSelect: () => setNotificationsOpen(true), |
| 51 | }); |
| 52 | if (modules.isEnabled("chatbot")) { |
| 53 | list.push({ id: "celebi", label: t("ai.askCelebi"), Icon: IconSparkles, onSelect: openCelebiPanel }); |
| 54 | } |
| 55 | return list; |
| 56 | }); |
| 57 | |
| 58 | return ( |
| 59 | <> |
| 60 | {/* Unread messages are notifications too, so this one count covers both. */} |
| 61 | <FloatingActionButton |
| 62 | actions={actions()} |
| 63 | badge={notifications.unreadCount()} |
| 64 | hidden={props.hidden || notificationsOpen()} |
| 65 | /> |
| 66 | <SidePanel |
| 67 | open={notificationsOpen()} |
| 68 | onOpenChange={setNotificationsOpen} |
| 69 | title={t("notifications.title")} |
| 70 | bodyClass="px-2 py-2" |
| 71 | > |
| 72 | <NotificationList |
| 73 | feed={notifications} |
| 74 | showTitle={false} |
| 75 | scrollClass="" |
| 76 | onNavigate={(url) => { |
| 77 | setNotificationsOpen(false); |
| 78 | void navigate({ to: url }); |
| 79 | }} |
| 80 | /> |
| 81 | </SidePanel> |
| 82 | </> |
| 83 | ); |
| 84 | } |