From de9cf0a45227da9d33feabe9c51a71845dad6763 Mon Sep 17 00:00:00 2001
From: MohamedBassem <me@mbassem.com>
Date: Sun, 13 Oct 2024 01:49:13 +0000
Subject: feature: Allow importing hoarder's own bookmark file. Fixes #527

---
 .../components/dashboard/settings/ImportExport.tsx | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

(limited to 'apps/web/components/dashboard/settings/ImportExport.tsx')

diff --git a/apps/web/components/dashboard/settings/ImportExport.tsx b/apps/web/components/dashboard/settings/ImportExport.tsx
index 2bc930f7..f3ef13ef 100644
--- a/apps/web/components/dashboard/settings/ImportExport.tsx
+++ b/apps/web/components/dashboard/settings/ImportExport.tsx
@@ -9,6 +9,7 @@ import { Progress } from "@/components/ui/progress";
 import { toast } from "@/components/ui/use-toast";
 import {
   ParsedBookmark,
+  parseHoarderBookmarkFile,
   parseNetscapeBookmarkFile,
   parsePocketBookmarkFile,
 } from "@/lib/importBookmarkParser";
@@ -66,10 +67,10 @@ export function ImportExportRow() {
       if (bookmark.url === undefined) {
         throw new Error("URL is undefined");
       }
-      const url = new URL(bookmark.url);
+      new URL(bookmark.url);
       const created = await createBookmark({
         type: BookmarkTypes.LINK,
-        url: url.toString(),
+        url: bookmark.url,
       });
 
       await Promise.all([
@@ -81,6 +82,7 @@ export function ImportExportRow() {
               createdAt: bookmark.addDate
                 ? new Date(bookmark.addDate * 1000)
                 : undefined,
+              note: bookmark.notes,
             }).catch(() => {
               /* empty */
             })
@@ -120,12 +122,14 @@ export function ImportExportRow() {
       source,
     }: {
       file: File;
-      source: "html" | "pocket";
+      source: "html" | "pocket" | "hoarder";
     }) => {
       if (source === "html") {
         return await parseNetscapeBookmarkFile(file);
       } else if (source === "pocket") {
         return await parsePocketBookmarkFile(file);
+      } else if (source === "hoarder") {
+        return await parseHoarderBookmarkFile(file);
       } else {
         throw new Error("Unknown source");
       }
@@ -213,6 +217,18 @@ export function ImportExportRow() {
           <Upload />
           <p>Import Bookmarks from Pocket export</p>
         </FilePickerButton>
+        <FilePickerButton
+          loading={false}
+          accept=".json"
+          multiple={false}
+          className="flex items-center gap-2"
+          onFileSelect={(file) =>
+            runUploadBookmarkFile({ file, source: "hoarder" })
+          }
+        >
+          <Upload />
+          <p>Import Bookmarks from Hoarder export</p>
+        </FilePickerButton>
         <ExportButton />
       </div>
       {importProgress && (
-- 
cgit v1.2.3-70-g09d2

