-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathOpen.jsx
80 lines (77 loc) · 2.52 KB
/
Open.jsx
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
import { db } from "../../../data/db";
import { Banner } from "@douyinfe/semi-ui";
import { useLiveQuery } from "dexie-react-hooks";
import { useTranslation } from "react-i18next";
import { databases } from "../../../data/databases";
export default function Open({ selectedDiagramId, setSelectedDiagramId }) {
const diagrams = useLiveQuery(() => db.diagrams.toArray());
const { t } = useTranslation();
const getDiagramSize = (d) => {
const size = JSON.stringify(d).length;
let sizeStr;
if (size >= 1024 && size < 1024 * 1024)
sizeStr = (size / 1024).toFixed(1) + "KB";
else if (size >= 1024 * 1024)
sizeStr = (size / (1024 * 1024)).toFixed(1) + "MB";
else sizeStr = size + "B";
return sizeStr;
};
return (
<div>
{diagrams?.length === 0 ? (
<Banner
fullMode={false}
type="info"
bordered
icon={null}
closeIcon={null}
description={<div>You have no saved diagrams.</div>}
/>
) : (
<div className="max-h-[360px]">
<table className="w-full text-left border-separate border-spacing-x-0">
<thead>
<tr>
<th>{t("name")}</th>
<th>{t("last_modified")}</th>
<th>{t("size")}</th>
<th>{t("type")}</th>
</tr>
</thead>
<tbody>
{diagrams?.map((d) => {
return (
<tr
key={d.id}
className={`${
selectedDiagramId === d.id
? "bg-blue-300/30"
: "hover-1"
}`}
onClick={() => {
setSelectedDiagramId(d.id);
}}
>
<td className="py-1">
<i className="bi bi-file-earmark-text text-[16px] me-1 opacity-60" />
{d.name}
</td>
<td className="py-1">
{d.lastModified.toLocaleDateString() +
" " +
d.lastModified.toLocaleTimeString()}
</td>
<td className="py-1">{getDiagramSize(d)}</td>
<td className="py-1">
{databases[d.database].name ?? "Generic"}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
);
}