-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathApiPanelToggle.tsx
More file actions
47 lines (44 loc) · 1.56 KB
/
ApiPanelToggle.tsx
File metadata and controls
47 lines (44 loc) · 1.56 KB
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
import { eq, useLiveQuery } from "@tanstack/react-db";
import { ActivityIcon } from "lucide-react";
import { userPreferencesCollection } from "@/collections/UserPreferences";
import { HighlightWrapper } from "@/utils/highlight-collection-related-info";
import { USER_PLACEHOLDER } from "@/utils/USER_PLACEHOLDER_CONSTANT";
import { Button } from "./ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
export function ApiPanelToggle() {
const { data: userPreferences } = useLiveQuery((q) =>
q
.from({
userPreferences: userPreferencesCollection,
})
.where(({ userPreferences }) =>
eq(userPreferences.id, USER_PLACEHOLDER.id),
)
.findOne(),
);
const isOpen = userPreferences?.networkPanel === "open";
return (
<HighlightWrapper highlightId="networkPanel_toggle">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant={isOpen ? "default" : "outline"}
size="icon"
onClick={() =>
userPreferencesCollection.update(USER_PLACEHOLDER.id, (draft) => {
draft.networkPanel =
draft.networkPanel === "open" ? "closed" : "open";
})
}
aria-label={isOpen ? "Hide API requests" : "Show API requests"}
>
<ActivityIcon className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>
<p>{isOpen ? "Hide API requests" : "Show API requests"}</p>
</TooltipContent>
</Tooltip>
</HighlightWrapper>
);
}