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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
"use client";
import { useState } from "react";
import Link from "next/link";
import { buttonVariants } from "@/components/ui/button";
import FilePickerButton from "@/components/ui/file-picker-button";
import { Progress } from "@/components/ui/progress";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { useBookmarkImport } from "@/lib/hooks/useBookmarkImport";
import { useTranslation } from "@/lib/i18n/client";
import { cn } from "@/lib/utils";
import { Download, Upload } from "lucide-react";
import { Card, CardContent } from "../ui/card";
function ImportCard({
text,
description,
children,
}: {
text: string;
description: string;
children: React.ReactNode;
}) {
return (
<Card className="transition-all hover:shadow-md">
<CardContent className="flex items-center gap-3 p-4">
<div className="rounded-full bg-primary/10 p-2">
<Download className="h-5 w-5 text-primary" />
</div>
<div className="flex-1">
<h3 className="font-medium">{text}</h3>
<p>{description}</p>
</div>
{children}
</CardContent>
</Card>
);
}
function ExportButton() {
const { t } = useTranslation();
const [format, setFormat] = useState<"json" | "netscape">("json");
return (
<Card className="transition-all hover:shadow-md">
<CardContent className="flex items-center gap-3 p-4">
<div className="rounded-full bg-primary/10 p-2">
<Upload className="h-5 w-5 text-primary" />
</div>
<div className="flex-1">
<h3 className="font-medium">Export File</h3>
<p>{t("settings.import.export_links_and_notes")}</p>
<Select
value={format}
onValueChange={(value) => setFormat(value as "json" | "netscape")}
>
<SelectTrigger className="mt-2 w-[180px]">
<SelectValue placeholder="Format" />
</SelectTrigger>
<SelectContent>
<SelectItem value="json">JSON (Karakeep format)</SelectItem>
<SelectItem value="netscape">HTML (Netscape format)</SelectItem>
</SelectContent>
</Select>
</div>
<Link
href={`/api/bookmarks/export?format=${format}`}
className={cn(
buttonVariants({ variant: "default", size: "sm" }),
"flex items-center gap-2",
)}
>
<p>Export</p>
</Link>
</CardContent>
</Card>
);
}
export function ImportExportRow() {
const { t } = useTranslation();
const { importProgress, runUploadBookmarkFile } = useBookmarkImport();
return (
<div className="flex flex-col gap-3">
<div className="grid gap-4 md:grid-cols-2">
<ImportCard
text="HTML File"
description={t("settings.import.import_bookmarks_from_html_file")}
>
<FilePickerButton
size={"sm"}
loading={false}
accept=".html"
multiple={false}
className="flex items-center gap-2"
onFileSelect={(file) =>
runUploadBookmarkFile({ file, source: "html" })
}
>
<p>Import</p>
</FilePickerButton>
</ImportCard>
<ImportCard
text="Pocket"
description={t("settings.import.import_bookmarks_from_pocket_export")}
>
<FilePickerButton
size={"sm"}
loading={false}
accept=".csv"
multiple={false}
className="flex items-center gap-2"
onFileSelect={(file) =>
runUploadBookmarkFile({ file, source: "pocket" })
}
>
<p>Import</p>
</FilePickerButton>
</ImportCard>
<ImportCard
text="Omnivore"
description={t(
"settings.import.import_bookmarks_from_omnivore_export",
)}
>
<FilePickerButton
size={"sm"}
loading={false}
accept=".json"
multiple={false}
className="flex items-center gap-2"
onFileSelect={(file) =>
runUploadBookmarkFile({ file, source: "omnivore" })
}
>
<p>Import</p>
</FilePickerButton>
</ImportCard>
<ImportCard
text="Linkwarden"
description={t(
"settings.import.import_bookmarks_from_linkwarden_export",
)}
>
<FilePickerButton
size={"sm"}
loading={false}
accept=".json"
multiple={false}
className="flex items-center gap-2"
onFileSelect={(file) =>
runUploadBookmarkFile({ file, source: "linkwarden" })
}
>
<p>Import</p>
</FilePickerButton>
</ImportCard>
<ImportCard
text="Tab Session Manager"
description={t(
"settings.import.import_bookmarks_from_tab_session_manager_export",
)}
>
<FilePickerButton
size={"sm"}
loading={false}
accept=".json"
multiple={false}
className="flex items-center gap-2"
onFileSelect={(file) =>
runUploadBookmarkFile({ file, source: "tab-session-manager" })
}
>
<p>Import</p>
</FilePickerButton>
</ImportCard>
<ImportCard
text="Karakeep"
description={t(
"settings.import.import_bookmarks_from_karakeep_export",
)}
>
<FilePickerButton
size={"sm"}
loading={false}
accept=".json"
multiple={false}
className="flex items-center gap-2"
onFileSelect={(file) =>
runUploadBookmarkFile({ file, source: "karakeep" })
}
>
<p>Import</p>
</FilePickerButton>
</ImportCard>
<ExportButton />
</div>
{importProgress && (
<div className="flex flex-col gap-2">
<p className="shrink-0 text-sm">
Processed {importProgress.done} of {importProgress.total} bookmarks
</p>
<div className="w-full">
<Progress
value={(importProgress.done * 100) / importProgress.total}
/>
</div>
</div>
)}
</div>
);
}
export default function ImportExport() {
const { t } = useTranslation();
return (
<div className="flex w-full flex-col gap-2">
<p className="mb-4 text-lg font-medium">
{t("settings.import.import_export_bookmarks")}
</p>
<ImportExportRow />
</div>
);
}
|