forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits

mobile-quick-actions.tsx84 lines, 2.8 KiBHistoryRawDownload
1import { createEffect, createMemo, createSignal } from "solid-js";
2import { useNavigate } from "@tanstack/solid-router";
3import { FloatingActionButton, type FloatingAction } from "@/components/layout/floating-action-button";
4import { createNotificationFeed } from "@/components/layout/notification-feed";
5import { NotificationList } from "@/components/layout/notification-list";
6import { SidePanel } from "@/components/ui/side-panel";
7import { IconBell, IconMessage, IconSparkles } from "@/components/ui/icons";
8import { openCelebiPanel } from "@/stores/celebi-panel";
9import { useModules } from "@/stores/modules-context";
10import { useShellFeed } from "@/stores/shell-feed-context";
11import { 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 */
19export 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}