Open History to see the last commit
1import { eq, useLiveQuery } from "@tanstack/react-db";
2import { ClientOnly } from "@tanstack/react-router";
3import { BugIcon, GithubIcon, LoaderIcon, RotateCwIcon } from "lucide-react";
4import { retryUnsyncedTodoItemsSync } from "@/collections/todoItems";
5import {
6 TODO_ITEMS_SYNC_STATE_ID,
7 todoItemsSyncCollection,
8} from "@/collections/todoItemsSync";
9import { ApiLatencyConfigurator } from "./ApiLatencyConfigurator";
10import { ApiPanelToggle } from "./ApiPanelToggle";
11import { ConfigureDB } from "./ConfigureDB";
12import { ModeToggle } from "./mode-toggle";
13import { ResetTheDbDialog } from "./ResetTheDbDialog";
14import { Button } from "./ui/button";
15import { SidebarTrigger } from "./ui/sidebar";
16import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
17
18function RetryTodoItemsSyncButton() {
19 const { data: syncState } = useLiveQuery((q) =>
20 q
21 .from({ syncState: todoItemsSyncCollection })
22 .where(({ syncState }) => eq(syncState.id, TODO_ITEMS_SYNC_STATE_ID))
23 .findOne(),
24 );
25
26 const failedCount = syncState?.failedItemIds.length ?? 0;
27 const inFlightCount = syncState?.inFlightItemIds.length ?? 0;
28
29 if (failedCount === 0) {
30 return null;
31 }
32
33 const tooltipText = `Retries failed sync requests (${failedCount} pending failure${failedCount > 1 ? "s" : ""}). Local changes stay in the UI.`;
34
35 return (
36 <Tooltip>
37 <TooltipTrigger asChild>
38 <span className="inline-flex">
39 <Button
40 variant="outline"
41 size="sm"
42 onClick={() => {
43 void retryUnsyncedTodoItemsSync();
44 }}
45 disabled={failedCount === 0}
46 >
47 {inFlightCount > 0 ? (
48 <LoaderIcon className="animate-spin" />
49 ) : (
50 <RotateCwIcon />
51 )}
52 Retry sync
53 {failedCount > 0 ? ` (${failedCount})` : ""}
54 </Button>
55 </span>
56 </TooltipTrigger>
57 <TooltipContent side="bottom">
58 <p className="max-w-72">{tooltipText}</p>
59 </TooltipContent>
60 </Tooltip>
61 );
62}
63
64export function Header() {
65 return (
66 <header className="flex gap-2 items-center justify-between px-4 py-2 border-b bg-background sticky top-0">
67 <SidebarTrigger className="md:hidden" />
68 <div className="flex items-center gap-1 text-sm font-medium">
69 <a
70 href="https://fulop.dev"
71 target="_blank"
72 rel="noreferrer"
73 className="group/fuko-link cursor-pointer transition-colors flex items-center gap-2"
74 >
75 <img
76 alt="fuko"
77 src="https://avatars.githubusercontent.com/u/43729152?s=96&v=4"
78 className="inline h-6 w-6 rounded-full border"
79 />
80 <span className="underline decoration-wavy group-hover/fuko-link:opacity-80 transition-opacity">
81 fuko's
82 </span>
83 </a>
84 guide to
85 <a
86 target="_blank"
87 href="https://tanstack.com/db/latest/docs/overview"
88 className="text-primary flex items-center cursor-pointer underline decoration-wavy hover:opacity-80"
89 rel="noopener"
90 >
91 @tanstack/db
92 </a>
93 </div>
94 <ClientOnly fallback={null}>
95 <div className="ml-auto">
96 <ConfigureDB />
97 </div>
98 </ClientOnly>
99 <ClientOnly fallback={null}>
100 <ResetTheDbDialog />
101 </ClientOnly>
102 <ClientOnly fallback={null}>
103 <ApiLatencyConfigurator />
104 </ClientOnly>
105 <ClientOnly fallback={null}>
106 <RetryTodoItemsSyncButton />
107 </ClientOnly>
108 <a
109 href="https://github.com/fulopkovacs/trytanstackdb.com"
110 target="_blank"
111 rel="noreferrer"
112 >
113 <Button variant={"outline"} size="icon">
114 <GithubIcon />
115 </Button>
116 </a>
117 <a
118 className="hidden lg:block"
119 href="https://github.com/fulopkovacs/trytanstackdb.com/issues/new"
120 target="_blank"
121 rel="noreferrer"
122 >
123 <Button variant={"outline"}>
124 <BugIcon /> Report a bug
125 </Button>
126 </a>
127 <a
128 className="block lg:hidden"
129 href="https://github.com/fulopkovacs/trytanstackdb.com/issues/new"
130 target="_blank"
131 rel="noreferrer"
132 >
133 <Button variant={"outline"} size="icon">
134 <BugIcon />
135 </Button>
136 </a>
137 <div className="flex items-center gap-4">
138 <ModeToggle />
139 </div>
140 <ClientOnly fallback={null}>
141 <ApiPanelToggle />
142 </ClientOnly>
143 </header>
144 );
145}