⚡️⚡️⚡️ 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
feat(web): add upload button to preservation nav bar
Kha Nguyen581e27e8c694
diff --git a/apps/web/components/Preservation/PreservationNavbar.tsx b/apps/web/components/Preservation/PreservationNavbar.tsxindex 1f1e5705..365dd6a8 100644--- a/apps/web/components/Preservation/PreservationNavbar.tsx+++ b/apps/web/components/Preservation/PreservationNavbar.tsx@@ -24,6 +24,7 @@ import clsx from "clsx";import ToggleDarkMode from "../ToggleDarkMode";import TextStyleDropdown from "../TextStyleDropdown";import HighlightDrawer from "../HighlightDrawer";+import toast from "react-hot-toast";type Props = {link: LinkIncludingShortenedCollectionAndTags;@@ -56,6 +57,31 @@ const PreservationNavbar = ({ link, format, showNavbar, className }: Props) => {const { t } = useTranslation();const router = useRouter();+ const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {+ const file = e.target.files?.[0];+ if (!file) return;+ const formBody = new FormData();+ formBody.append("file", file);++ try {+ const res = await fetch(`/api/v1/archives/${link?.id}?format=${format}`, {+ method: "POST",+ body: formBody,+ });++ if (res.ok) {+ router.reload();+ } else {+ const data = await res.json().catch(() => ({}));+ console.error("Failed to replace file:", data);+ toast.error("Failed to replace file");+ }+ } catch (error) {+ console.error("Failed to replace file:", error);+ toast.error("Failed to replace file");+ }+ };+const handleDownload = () => {const path = `/api/v1/archives/${link?.id}?format=${format}`;fetch(path)@@ -97,9 +123,31 @@ const PreservationNavbar = ({ link, format, showNavbar, className }: Props) => {{format === ArchivedFormat.readability ? (<TextStyleDropdown />) : (- <Button variant="ghost" size="icon" onClick={handleDownload}>- <i className="bi-cloud-arrow-down text-xl text-neutral" />- </Button>+ <div>+ <Button variant="ghost" size="icon" onClick={handleDownload}>+ <i className="bi-cloud-arrow-down text-xl text-neutral" />+ </Button>+ <Button asChild variant="ghost" size="icon">+ <label className="cursor-pointer">+ <i className="bi-cloud-arrow-up text-xl text-neutral" />+ <input+ type="file"+ accept={+ format === ArchivedFormat.monolith+ ? "text/html,.html"+ : format === ArchivedFormat.pdf+ ? "application/pdf,.pdf"+ : format === ArchivedFormat.png ||+ format === ArchivedFormat.jpeg+ ? "image/png,image/jpeg,.png,.jpg,.jpeg"+ : undefined+ }+ className="hidden"+ onChange={handleFileUpload}+ />+ </label>+ </Button>+ </div>)}{format === ArchivedFormat.readability && (<Button