-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeader.tsx
97 lines (96 loc) · 2.99 KB
/
Header.tsx
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import Card from "~/components/Card.tsx";
import { Download, RefreshCcw, Upload } from "lucide-preact";
import {
buildManifest,
labelled,
labelMap,
labels,
manifest,
updatedLabelled,
} from "~/signals/state.ts";
import { entryFiles } from "~/signals/state.ts";
export default function Header() {
return (
<Card>
<div class="w-full flex items-center justify-between">
<div class="flex flex-wrap items-center">
{labels.value.map((label) => (
<div class="border-r border-border px-2" key={label}>
{label} ({labelMap.value[label]?.length ?? 0})
</div>
))}
<div class="px-2">
unresolved ({entryFiles.value.length - Object.keys(
labelled.value,
).length})
</div>
</div>
<div class="flex gap-4">
<div>
<button
class="flex gap-2 hover:bg-muted p-2 rounded-md"
onClick={() => {
localStorage.setItem(
"recent-manifest",
JSON.stringify(buildManifest()),
);
}}
>
<RefreshCcw />
</button>
</div>
<div
onDrop={async (ev) => {
ev.preventDefault();
if (ev.dataTransfer?.items) {
const item = [...ev.dataTransfer.items][0];
const file = item.getAsFile();
if (!file) return;
const text = new TextDecoder().decode(await file.arrayBuffer());
const json = JSON.parse(text);
manifest.value = json;
}
}}
>
<button
class="flex gap-2 hover:bg-muted p-2 rounded-md"
onClick={() => {
const input = document.createElement("input");
input.type = "file";
input.addEventListener("change", async () => {
if (!input.files) return;
const text = new TextDecoder().decode(
await input.files[0].arrayBuffer(),
);
const json = JSON.parse(text);
manifest.value = json;
});
input.click();
}}
>
<Upload />
<span>upload manifest</span>
</button>
</div>
<div>
<button
class="flex gap-2 hover:bg-muted p-2 rounded-md"
onClick={() => {
const href = URL.createObjectURL(
new Blob([JSON.stringify(buildManifest(), null, 2)]),
);
const a = document.createElement("a");
a.href = href;
a.download = "manifest.json";
a.click();
}}
>
<Download />
<span>download manifest</span>
</button>
</div>
</div>
</div>
</Card>
);
}