⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.
TypeScript bookmarkbookmark-managercollaborationnextjsreact-nativeread-it-laterself-hostedtypescript
Made the import links dropdown menu reusable to avoid code duplication
dereulenspiegel95f818959bf6
diff --git a/components/ImportDropdown.tsx b/components/ImportDropdown.tsxnew file mode 100644index 00000000..a980bf9c--- /dev/null+++ b/components/ImportDropdown.tsx@@ -0,0 +1,112 @@+import React from "react";+import importBookmarks from "@/lib/client/importBookmarks";+import { MigrationFormat } from "@/types/global";+import { useTranslation } from "next-i18next";+import { dropdownTriggerer } from "@/lib/client/utils";++type Props = {};+const ImportDropdown = ({ }: Props) => {+ const { t } = useTranslation();+ return (+ <div className="dropdown dropdown-bottom">+ <div+ tabIndex={0}+ role="button"+ onMouseDown={dropdownTriggerer}+ className="inline-flex items-center gap-2 text-sm btn bg-neutral-content text-secondary-foreground hover:bg-neutral-content/80 border border-neutral/30 hover:border hover:border-neutral/30"+ id="import-dropdown"+ >+ <i className="bi-cloud-upload text-xl duration-100"></i>+ <p>{t("import_links")}</p>+ </div>+ <ul className="shadow menu dropdown-content z-[1] bg-base-200 border border-neutral-content rounded-box mt-1">+ <li>+ <label+ tabIndex={0}+ role="button"+ htmlFor="import-linkwarden-file"+ title={t("from_linkwarden")}+ className="whitespace-nowrap"+ >+ {t("from_linkwarden")}+ <input+ type="file"+ name="photo"+ id="import-linkwarden-file"+ accept=".json"+ className="hidden"+ onChange={(e) =>+ importBookmarks(e, MigrationFormat.linkwarden)+ }+ />+ </label>+ </li>+ <li>+ <label+ tabIndex={0}+ role="button"+ htmlFor="import-html-file"+ title={t("from_html")}+ className="whitespace-nowrap"+ >+ {t("from_html")}+ <input+ type="file"+ name="photo"+ id="import-html-file"+ accept=".html"+ className="hidden"+ onChange={(e) =>+ importBookmarks(e, MigrationFormat.htmlFile)+ }+ />+ </label>+ </li>+ <li>+ <label+ tabIndex={0}+ role="button"+ htmlFor="import-wallabag-file"+ title={t("from_wallabag")}+ className="whitespace-nowrap"+ >+ {t("from_wallabag")}+ <input+ type="file"+ name="photo"+ id="import-wallabag-file"+ accept=".json"+ className="hidden"+ onChange={(e) =>+ importBookmarks(e, MigrationFormat.wallabag)+ }+ />+ </label>+ </li>+ <li>+ <label+ tabIndex={0}+ role="button"+ htmlFor="import-omnivore-file"+ title={t("from_omnivore")}+ className="whitespace-nowrap"+ >+ {t("from_omnivore")}+ <input+ type="file"+ name="photo"+ id="import-omnivore-file"+ accept=".zip"+ className="hidden"+ onChange={(e) =>+ importBookmarks(e, MigrationFormat.omnivore)+ }+ />+ </label>+ </li>+ </ul>+ </div>+ );+};++export default ImportDropdown;\ No newline at end of filediff --git a/pages/dashboard.tsx b/pages/dashboard.tsxindex 38227d73..4fdd9b9c 100644--- a/pages/dashboard.tsx+++ b/pages/dashboard.tsx@@ -3,12 +3,11 @@ import { useEffect, useMemo, useState } from "react";import Link from "next/link";import React from "react";import { toast } from "react-hot-toast";-import { MigrationFormat, MigrationRequest, ViewMode } from "@/types/global";+import { ViewMode } from "@/types/global";import DashboardItem from "@/components/DashboardItem";import NewLinkModal from "@/components/ModalContent/NewLinkModal";import PageHeader from "@/components/PageHeader";import ViewDropdown from "@/components/ViewDropdown";-import { dropdownTriggerer } from "@/lib/client/utils";import getServerSideProps from "@/lib/client/getServerSideProps";import { useTranslation } from "next-i18next";import { useCollections } from "@/hooks/store/collections";@@ -18,7 +17,7 @@ import Links from "@/components/LinkViews/Links";import useLocalSettingsStore from "@/store/localSettings";import { useUpdateUser, useUser } from "@/hooks/store/user";import SurveyModal from "@/components/ModalContent/SurveyModal";-import importBookmarks from "@/lib/client/importBookmarks"+import ImportDropdown from "@/components/ImportDropdown";export default function Dashboard() {const { t } = useTranslation();@@ -217,104 +216,8 @@ export default function Dashboard() {</span></div>- <div className="dropdown dropdown-bottom">- <div- tabIndex={0}- role="button"- onMouseDown={dropdownTriggerer}- className="inline-flex items-center gap-2 text-sm btn bg-neutral-content text-secondary-foreground hover:bg-neutral-content/80 border border-neutral/30 hover:border hover:border-neutral/30"- id="import-dropdown"- >- <i className="bi-cloud-upload text-xl duration-100"></i>- <p>{t("import_links")}</p>- </div>- <ul className="shadow menu dropdown-content z-[1] bg-base-200 border border-neutral-content rounded-box mt-1">- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-linkwarden-file"- title={t("from_linkwarden")}- className="whitespace-nowrap"- >- {t("from_linkwarden")}- <input- type="file"- name="photo"- id="import-linkwarden-file"- accept=".json"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.linkwarden)- }- />- </label>- </li>- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-html-file"- title={t("from_html")}- className="whitespace-nowrap"- >- {t("from_html")}- <input- type="file"- name="photo"- id="import-html-file"- accept=".html"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.htmlFile)- }- />- </label>- </li>- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-wallabag-file"- title={t("from_wallabag")}- className="whitespace-nowrap"- >- {t("from_wallabag")}- <input- type="file"- name="photo"- id="import-wallabag-file"- accept=".json"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.wallabag)- }- />- </label>- </li>- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-omnivore-file"- title={t("from_omnivore")}- className="whitespace-nowrap"- >- {t("from_omnivore")}- <input- type="file"- name="photo"- id="import-omnivore-file"- accept=".zip"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.omnivore)- }- />- </label>- </li>- </ul>- </div>+ <ImportDropdown />+</div></div>)}diff --git a/pages/settings/account.tsx b/pages/settings/account.tsxindex 06042161..16463458 100644--- a/pages/settings/account.tsx+++ b/pages/settings/account.tsx@@ -7,7 +7,6 @@ import { resizeImage } from "@/lib/client/resizeImage";import ProfilePhoto from "@/components/ProfilePhoto";import SubmitButton from "@/components/SubmitButton";import React from "react";-import { MigrationFormat, MigrationRequest } from "@/types/global";import Link from "next/link";import Checkbox from "@/components/Checkbox";import { dropdownTriggerer } from "@/lib/client/utils";@@ -18,7 +17,7 @@ import { useTranslation } from "next-i18next";import getServerSideProps from "@/lib/client/getServerSideProps";import { useUpdateUser, useUser } from "@/hooks/store/user";import { z } from "zod";-import importBookmarks from "@/lib/client/importBookmarks"+import ImportDropdown from "@/components/ImportDropdown";const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER;@@ -315,85 +314,7 @@ export default function Account() {<div className="flex gap-3 flex-col"><div><p className="mb-2">{t("import_data")}</p>- <div className="dropdown dropdown-bottom">- <Button- tabIndex={0}- role="button"- intent="secondary"- onMouseDown={dropdownTriggerer}- className="text-sm"- id="import-dropdown"- >- <i className="bi-cloud-upload text-xl duration-100"></i>- {t("import_links")}- </Button>-- <ul className="shadow menu dropdown-content z-[1] bg-base-200 border border-neutral-content rounded-box mt-1">- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-linkwarden-file"- title={t("from_linkwarden")}- className="whitespace-nowrap"- >- {t("from_linkwarden")}- <input- type="file"- name="photo"- id="import-linkwarden-file"- accept=".json"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.linkwarden)- }- />- </label>- </li>- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-html-file"- title={t("from_html")}- className="whitespace-nowrap"- >- {t("from_html")}- <input- type="file"- name="photo"- id="import-html-file"- accept=".html"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.htmlFile)- }- />- </label>- </li>- <li>- <label- tabIndex={0}- role="button"- htmlFor="import-wallabag-file"- title={t("from_wallabag")}- className="whitespace-nowrap"- >- {t("from_wallabag")}- <input- type="file"- name="photo"- id="import-wallabag-file"- accept=".json"- className="hidden"- onChange={(e) =>- importBookmarks(e, MigrationFormat.wallabag)- }- />- </label>- </li>- </ul>- </div>+ <ImportDropdown /></div><div>