⚡️⚡️⚡️ 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
format & lint
Isaac80962c5df620
diff --git a/components/ConfirmationModal.tsx b/components/ConfirmationModal.tsxindex e4f692a6..a2ee36d4 100644--- a/components/ConfirmationModal.tsx+++ b/components/ConfirmationModal.tsx@@ -7,117 +7,136 @@ import Button from "./ui/Button";import { useTranslation } from "react-i18next";type Props = {- toggleModal: Function;- children: ReactNode;- title: string;- onConfirmed: Function;- className?: string;- dismissible?: boolean;+ toggleModal: Function;+ children: ReactNode;+ title: string;+ onConfirmed: Function;+ className?: string;+ dismissible?: boolean;};export default function ConfirmationModal({- toggleModal,- className,- title,- onConfirmed,- children,- dismissible = true,+ toggleModal,+ className,+ title,+ onConfirmed,+ children,+ dismissible = true,}: Props) {- const { t } = useTranslation();- const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);- const { width } = useWindowDimensions();+ const { t } = useTranslation();+ const [drawerIsOpen, setDrawerIsOpen] = React.useState(true);+ const { width } = useWindowDimensions();- useEffect(() => {- if (width >= 640) {- document.body.style.overflow = "hidden";- document.body.style.position = "relative";- return () => {- document.body.style.overflow = "auto";- document.body.style.position = "";- };- }- }, []);+ useEffect(() => {+ if (width >= 640) {+ document.body.style.overflow = "hidden";+ document.body.style.position = "relative";+ return () => {+ document.body.style.overflow = "auto";+ document.body.style.position = "";+ };+ }+ }, []);- if (width < 640) {- return (- <Drawer.Root- open={drawerIsOpen}- onClose={() => dismissible && setDrawerIsOpen(false)}- onAnimationEnd={(isOpen) => !isOpen && toggleModal()}- dismissible={dismissible}- >- <Drawer.Portal>- <Drawer.Overlay className="fixed inset-0 bg-black/40" />- <Drawer.Content className="flex flex-col rounded-t-2xl h-[90%] mt-24 fixed bottom-0 left-0 right-0 z-30 outline-none">- <div- className="p-4 bg-base-100 rounded-t-2xl flex-1 border-neutral-content border-t overflow-y-auto"- data-testid="mobile-modal-container"- >- <div- className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-neutral mb-5"- data-testid="mobile-modal-slider"- />- <p className="text-xl font-thin">{title}</p>- <div className="divider mb-3 mt-1"></div>- {children}- <div className="w-full flex items-center justify-end gap-2 mt-3">- <Button intent="ghost" className="hover:bg-base-200" onClick={() => toggleModal()}>- {t("cancel")}- </Button>- <Button intent="destructive" onClick={async () => {- await onConfirmed();- toggleModal();- }}>- {t("confirm")}- </Button>- </div>- </div>- </Drawer.Content>- </Drawer.Portal>- </Drawer.Root>- );- } else {- return (- <div- className="overflow-y-auto pt-2 sm:py-2 fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-40"- data-testid="modal-outer"- >- <ClickAwayHandler- onClickOutside={() => dismissible && toggleModal()}- className={clsx("w-full mt-auto sm:m-auto sm:w-11/12 sm:max-w-2xl", className)}- >- <div- className={"slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl bg-base-100 overflow-y-auto sm:overflow-y-visible p-5"}- data-testid="modal-container"- >- {dismissible && (- <div- onClick={toggleModal as MouseEventHandler<HTMLDivElement>}- className="absolute top-4 right-3 btn btn-sm outline-none btn-circle btn-ghost z-10"- >- <i- className="bi-x text-neutral text-2xl"- data-testid="close-modal-button"- ></i>- </div>- )}- <p className="text-xl font-thin">{title}</p>- <div className="divider mb-3 mt-1"></div>- {children}- <div className="w-full flex items-center justify-end gap-2 mt-3">- <Button intent="ghost" className="hover:bg-base-200" onClick={() => toggleModal()}>- {t("cancel")}- </Button>- <Button intent="destructive" onClick={async () => {- await onConfirmed();- toggleModal();- }}>- {t("confirm")}- </Button>- </div>- </div>- </ClickAwayHandler>- </div>- );- }+ if (width < 640) {+ return (+ <Drawer.Root+ open={drawerIsOpen}+ onClose={() => dismissible && setDrawerIsOpen(false)}+ onAnimationEnd={(isOpen) => !isOpen && toggleModal()}+ dismissible={dismissible}+ >+ <Drawer.Portal>+ <Drawer.Overlay className="fixed inset-0 bg-black/40" />+ <Drawer.Content className="flex flex-col rounded-t-2xl h-[90%] mt-24 fixed bottom-0 left-0 right-0 z-30 outline-none">+ <div+ className="p-4 bg-base-100 rounded-t-2xl flex-1 border-neutral-content border-t overflow-y-auto"+ data-testid="mobile-modal-container"+ >+ <div+ className="mx-auto w-12 h-1.5 flex-shrink-0 rounded-full bg-neutral mb-5"+ data-testid="mobile-modal-slider"+ />+ <p className="text-xl font-thin">{title}</p>+ <div className="divider mb-3 mt-1"></div>+ {children}+ <div className="w-full flex items-center justify-end gap-2 mt-3">+ <Button+ intent="ghost"+ className="hover:bg-base-200"+ onClick={() => toggleModal()}+ >+ {t("cancel")}+ </Button>+ <Button+ intent="destructive"+ onClick={async () => {+ await onConfirmed();+ toggleModal();+ }}+ >+ {t("confirm")}+ </Button>+ </div>+ </div>+ </Drawer.Content>+ </Drawer.Portal>+ </Drawer.Root>+ );+ } else {+ return (+ <div+ className="overflow-y-auto pt-2 sm:py-2 fixed top-0 bottom-0 right-0 left-0 bg-black bg-opacity-10 backdrop-blur-sm flex justify-center items-center fade-in z-40"+ data-testid="modal-outer"+ >+ <ClickAwayHandler+ onClickOutside={() => dismissible && toggleModal()}+ className={clsx(+ "w-full mt-auto sm:m-auto sm:w-11/12 sm:max-w-2xl",+ className+ )}+ >+ <div+ className={+ "slide-up mt-auto sm:m-auto relative border-neutral-content rounded-t-2xl sm:rounded-2xl border-t sm:border shadow-2xl bg-base-100 overflow-y-auto sm:overflow-y-visible p-5"+ }+ data-testid="modal-container"+ >+ {dismissible && (+ <div+ onClick={toggleModal as MouseEventHandler<HTMLDivElement>}+ className="absolute top-4 right-3 btn btn-sm outline-none btn-circle btn-ghost z-10"+ >+ <i+ className="bi-x text-neutral text-2xl"+ data-testid="close-modal-button"+ ></i>+ </div>+ )}+ <p className="text-xl font-thin">{title}</p>+ <div className="divider mb-3 mt-1"></div>+ {children}+ <div className="w-full flex items-center justify-end gap-2 mt-3">+ <Button+ intent="ghost"+ className="hover:bg-base-200"+ onClick={() => toggleModal()}+ >+ {t("cancel")}+ </Button>+ <Button+ intent="destructive"+ onClick={async () => {+ await onConfirmed();+ toggleModal();+ }}+ >+ {t("confirm")}+ </Button>+ </div>+ </div>+ </ClickAwayHandler>+ </div>+ );+ }}diff --git a/components/InputSelect/ArchivalTagSelection.tsx b/components/InputSelect/ArchivalTagSelection.tsxindex e1b4137a..75b991de 100644--- a/components/InputSelect/ArchivalTagSelection.tsx+++ b/components/InputSelect/ArchivalTagSelection.tsx@@ -4,27 +4,24 @@ import { useTranslation } from "next-i18next";import { ArchivalTagOption } from "./types";type Props = {- options: ArchivalTagOption[] | []- onChange: (e: any) => void;+ options: ArchivalTagOption[] | [];+ onChange: (e: any) => void;};-export default function ArchivalTagSelection({- options,- onChange-}: Props) {- const { t } = useTranslation();+export default function ArchivalTagSelection({ options, onChange }: Props) {+ const { t } = useTranslation();- return (- <CreatableSelect- isClearable={false}- className="react-select-container"- classNamePrefix="react-select"- onChange={onChange}- options={options}- styles={styles}- value={[]}- placeholder={t("tag_selection_placeholder")}- isMulti- />- );+ return (+ <CreatableSelect+ isClearable={false}+ className="react-select-container"+ classNamePrefix="react-select"+ onChange={onChange}+ options={options}+ styles={styles}+ value={[]}+ placeholder={t("tag_selection_placeholder")}+ isMulti+ />+ );}diff --git a/components/InputSelect/CollectionSelection.tsx b/components/InputSelect/CollectionSelection.tsxindex 072382c3..1a3e3ac2 100644--- a/components/InputSelect/CollectionSelection.tsx+++ b/components/InputSelect/CollectionSelection.tsx@@ -11,11 +11,11 @@ type Props = {onChange: any;showDefaultValue?: boolean;defaultValue?:- | {- label: string;- value?: number;- }- | undefined;+ | {+ label: string;+ value?: number;+ }+ | undefined;creatable?: boolean;autoFocus?: boolean;onBlur?: any;@@ -118,7 +118,7 @@ export default function CollectionSelection({components={{Option: customOption,}}- // menuPosition="fixed"+ // menuPosition="fixed"/>);} else {@@ -136,7 +136,7 @@ export default function CollectionSelection({components={{Option: customOption,}}- // menuPosition="fixed"+ // menuPosition="fixed"/>);}diff --git a/components/InputSelect/TagSelection.tsx b/components/InputSelect/TagSelection.tsxindex 184299e7..8ce0edb0 100644--- a/components/InputSelect/TagSelection.tsx+++ b/components/InputSelect/TagSelection.tsx@@ -49,4 +49,4 @@ export default function TagSelection({onBlur={onBlur}/>);-}\ No newline at end of file+}diff --git a/components/InputSelect/types.ts b/components/InputSelect/types.tsindex 3313f8d4..d9b2c547 100644--- a/components/InputSelect/types.ts+++ b/components/InputSelect/types.ts@@ -14,4 +14,7 @@ export interface ArchivalTagOption extends Option {newTag: boolean | null;}-export type ArchivalOptionKeys = keyof Omit<ArchivalTagOption, "label" | "value" | "__isNew__">;+export type ArchivalOptionKeys = keyof Omit<+ ArchivalTagOption,+ "label" | "value" | "__isNew__"+>;diff --git a/components/SettingsSidebar.tsx b/components/SettingsSidebar.tsxindex 653f8d81..0f24b52b 100644--- a/components/SettingsSidebar.tsx+++ b/components/SettingsSidebar.tsx@@ -22,16 +22,18 @@ export default function SettingsSidebar({ className }: { className?: string }) {return (<div- className={`bg-base-100 h-full w-64 overflow-y-auto border-solid border border-base-100 border-r-neutral-content p-5 z-20 flex flex-col gap-5 justify-between ${className || ""- }`}+ className={`bg-base-100 h-full w-64 overflow-y-auto border-solid border border-base-100 border-r-neutral-content p-5 z-20 flex flex-col gap-5 justify-between ${+ className || ""+ }`}><div className="flex flex-col gap-1"><Link href="/settings/account"><div- className={`${active === "/settings/account"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/account"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-person text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("account")}</p>@@ -40,10 +42,11 @@ export default function SettingsSidebar({ className }: { className?: string }) {<Link href="/settings/preference"><div- className={`${active === "/settings/preference"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/preference"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-sliders text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("preference")}</p>@@ -52,10 +55,11 @@ export default function SettingsSidebar({ className }: { className?: string }) {<Link href="/settings/rss-subscriptions"><div- className={`${active === "/settings/rss-subscriptions"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/rss-subscriptions"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-rss text-primary text-2xl"></i><p className="truncate w-full pr-7">RSS Subscriptions</p>@@ -64,10 +68,11 @@ export default function SettingsSidebar({ className }: { className?: string }) {<Link href="/settings/access-tokens"><div- className={`${active === "/settings/access-tokens"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/access-tokens"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-key text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("access_tokens")}</p>@@ -76,10 +81,11 @@ export default function SettingsSidebar({ className }: { className?: string }) {<Link href="/settings/password"><div- className={`${active === "/settings/password"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/password"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-lock text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("password")}</p>@@ -89,10 +95,11 @@ export default function SettingsSidebar({ className }: { className?: string }) {{isAdmin && (<Link href="/settings/worker"><div- className={`${active === "/settings/worker"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/worker"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-gear-wide-connected text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("worker")}</p>@@ -103,10 +110,11 @@ export default function SettingsSidebar({ className }: { className?: string }) {{process.env.NEXT_PUBLIC_STRIPE && !user.parentSubscriptionId && (<Link href="/settings/billing"><div- className={`${active === "/settings/billing"- ? "bg-primary/20"- : "hover:bg-neutral/20"- } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}+ className={`${+ active === "/settings/billing"+ ? "bg-primary/20"+ : "hover:bg-neutral/20"+ } duration-100 py-5 px-2 cursor-pointer flex items-center gap-2 w-full rounded-md h-8`}><i className="bi-credit-card text-primary text-2xl"></i><p className="truncate w-full pr-7">{t("billing")}</p>diff --git a/hooks/store/tags.tsx b/hooks/store/tags.tsxindex 5602c9ab..424c7963 100644--- a/hooks/store/tags.tsx+++ b/hooks/store/tags.tsx@@ -1,4 +1,9 @@-import { useQuery, useMutation, useQueryClient, UseQueryResult } from "@tanstack/react-query";+import {+ useQuery,+ useMutation,+ useQueryClient,+ UseQueryResult,+} from "@tanstack/react-query";import { TagIncludingLinkCount } from "@/types/global";import { useSession } from "next-auth/react";import { Tag } from "@prisma/client";@@ -67,19 +72,24 @@ const useUpdateArchivalTags = () => {return data.response;},onSuccess: (data: TagIncludingLinkCount[]) => {- queryClient.setQueryData(["tags"], (oldData: TagIncludingLinkCount[] = []) => {- const updatedTags = oldData.map((tag) => {- const updatedTag = data.find((t) => t.id === tag.id);- return updatedTag ? { ...tag, ...updatedTag } : tag;- });-- const newTags = data.filter((t) => !oldData.some((tag) => tag.id === t.id));-- return [...updatedTags, ...newTags];- });+ queryClient.setQueryData(+ ["tags"],+ (oldData: TagIncludingLinkCount[] = []) => {+ const updatedTags = oldData.map((tag) => {+ const updatedTag = data.find((t) => t.id === tag.id);+ return updatedTag ? { ...tag, ...updatedTag } : tag;+ });++ const newTags = data.filter(+ (t) => !oldData.some((tag) => tag.id === t.id)+ );++ return [...updatedTags, ...newTags];+ }+ );},});-}+};const useRemoveTag = () => {const queryClient = useQueryClient();diff --git a/hooks/useArchivalTags.ts b/hooks/useArchivalTags.tsindex 40ba67a1..ade2ace4 100644--- a/hooks/useArchivalTags.ts+++ b/hooks/useArchivalTags.ts@@ -1,115 +1,156 @@-import { Tag } from '@prisma/client';-import { ArchivalOptionKeys, ArchivalTagOption } from '../components/InputSelect/types';-import { useState, useEffect } from 'react';-import { useTranslation } from 'react-i18next';+import { Tag } from "@prisma/client";+import {+ ArchivalOptionKeys,+ ArchivalTagOption,+} from "../components/InputSelect/types";+import { useState, useEffect } from "react";+import { useTranslation } from "react-i18next";export const isArchivalTag = (tag: ArchivalTagOption | Tag) =>- typeof tag.archiveAsScreenshot === "boolean" ||- typeof tag.archiveAsMonolith === "boolean" ||- typeof tag.archiveAsPDF === "boolean" ||- typeof tag.archiveAsReadable === "boolean" ||- typeof tag.archiveAsWaybackMachine === "boolean" ||- typeof tag.aiTag === "boolean";+ typeof tag.archiveAsScreenshot === "boolean" ||+ typeof tag.archiveAsMonolith === "boolean" ||+ typeof tag.archiveAsPDF === "boolean" ||+ typeof tag.archiveAsReadable === "boolean" ||+ typeof tag.archiveAsWaybackMachine === "boolean" ||+ typeof tag.aiTag === "boolean";const useArchivalTags = (initialTags: Tag[]) => {- const [archivalTags, setArchivalTags] = useState<ArchivalTagOption[]>([]);- const [options, setOptions] = useState<ArchivalTagOption[]>([]);- const { t } = useTranslation();+ const [archivalTags, setArchivalTags] = useState<ArchivalTagOption[]>([]);+ const [options, setOptions] = useState<ArchivalTagOption[]>([]);+ const { t } = useTranslation();- useEffect(() => {- if (!initialTags) return;+ useEffect(() => {+ if (!initialTags) return;- const transformTag = (tag: Tag): ArchivalTagOption => ({- label: tag.name,- value: tag.id,- archiveAsScreenshot: tag.archiveAsScreenshot || false,- archiveAsMonolith: tag.archiveAsMonolith || false,- archiveAsPDF: tag.archiveAsPDF || false,- archiveAsReadable: tag.archiveAsReadable || false,- archiveAsWaybackMachine: tag.archiveAsWaybackMachine || false,- aiTag: tag.aiTag || false,- newTag: false,- });+ const transformTag = (tag: Tag): ArchivalTagOption => ({+ label: tag.name,+ value: tag.id,+ archiveAsScreenshot: tag.archiveAsScreenshot || false,+ archiveAsMonolith: tag.archiveAsMonolith || false,+ archiveAsPDF: tag.archiveAsPDF || false,+ archiveAsReadable: tag.archiveAsReadable || false,+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine || false,+ aiTag: tag.aiTag || false,+ newTag: false,+ });- const archival = initialTags.filter(isArchivalTag).map(transformTag);- const nonArchival = initialTags.filter(tag => !isArchivalTag(tag)).map(transformTag);+ const archival = initialTags.filter(isArchivalTag).map(transformTag);+ const nonArchival = initialTags+ .filter((tag) => !isArchivalTag(tag))+ .map(transformTag);- setArchivalTags(archival);- setOptions(nonArchival);- }, [initialTags]);+ setArchivalTags(archival);+ setOptions(nonArchival);+ }, [initialTags]);- const addTags = (newTags: ArchivalTagOption[]) => {- const uniqueNewTags = newTags- .filter(newTag => !archivalTags.some(existing => existing.label === newTag.label))- .map(({ __isNew__, ...tag }) => ({- ...tag,- value: __isNew__ ? undefined : tag.value,- archiveAsScreenshot: __isNew__ ? false : tag.archiveAsScreenshot,- archiveAsMonolith: __isNew__ ? false : tag.archiveAsMonolith,- archiveAsPDF: __isNew__ ? false : tag.archiveAsPDF,- archiveAsReadable: __isNew__ ? false : tag.archiveAsReadable,- archiveAsWaybackMachine: __isNew__ ? false : tag.archiveAsWaybackMachine,- aiTag: __isNew__ ? false : tag.aiTag,- newTag: __isNew__ ? true : false,- }));+ const addTags = (newTags: ArchivalTagOption[]) => {+ const uniqueNewTags = newTags+ .filter(+ (newTag) =>+ !archivalTags.some((existing) => existing.label === newTag.label)+ )+ .map(({ __isNew__, ...tag }) => ({+ ...tag,+ value: __isNew__ ? undefined : tag.value,+ archiveAsScreenshot: __isNew__ ? false : tag.archiveAsScreenshot,+ archiveAsMonolith: __isNew__ ? false : tag.archiveAsMonolith,+ archiveAsPDF: __isNew__ ? false : tag.archiveAsPDF,+ archiveAsReadable: __isNew__ ? false : tag.archiveAsReadable,+ archiveAsWaybackMachine: __isNew__+ ? false+ : tag.archiveAsWaybackMachine,+ aiTag: __isNew__ ? false : tag.aiTag,+ newTag: __isNew__ ? true : false,+ }));- setArchivalTags(prev => [...prev, ...uniqueNewTags]);- setOptions(prev => prev.filter(option => !newTags.some(({ label }) => label === option.label)));- };+ setArchivalTags((prev) => [...prev, ...uniqueNewTags]);+ setOptions((prev) =>+ prev.filter(+ (option) => !newTags.some(({ label }) => label === option.label)+ )+ );+ };- const toggleOption = (tag: ArchivalTagOption, option: keyof ArchivalTagOption) => {- setArchivalTags(prev => prev.map(t =>- t.label === tag.label ? { ...t, [option]: !t[option] } : t- ));- };+ const toggleOption = (+ tag: ArchivalTagOption,+ option: keyof ArchivalTagOption+ ) => {+ setArchivalTags((prev) =>+ prev.map((t) =>+ t.label === tag.label ? { ...t, [option]: !t[option] } : t+ )+ );+ };- const removeTag = (tagToDelete: ArchivalTagOption) => {- setArchivalTags(prev => prev.map(t =>- t.label === tagToDelete.label ?- {- ...t,- archiveAsScreenshot: null,- archiveAsMonolith: null,- archiveAsPDF: null,- archiveAsReadable: null,- archiveAsWaybackMachine: null,- aiTag: null- }- : t- ));+ const removeTag = (tagToDelete: ArchivalTagOption) => {+ setArchivalTags((prev) =>+ prev.map((t) =>+ t.label === tagToDelete.label+ ? {+ ...t,+ archiveAsScreenshot: null,+ archiveAsMonolith: null,+ archiveAsPDF: null,+ archiveAsReadable: null,+ archiveAsWaybackMachine: null,+ aiTag: null,+ }+ : t+ )+ );- if (!tagToDelete.__isNew__) {- const resetTag: ArchivalTagOption = {- ...tagToDelete,- archiveAsScreenshot: false,- archiveAsMonolith: false,- archiveAsPDF: false,- archiveAsReadable: false,- archiveAsWaybackMachine: false,- aiTag: false,- };+ if (!tagToDelete.__isNew__) {+ const resetTag: ArchivalTagOption = {+ ...tagToDelete,+ archiveAsScreenshot: false,+ archiveAsMonolith: false,+ archiveAsPDF: false,+ archiveAsReadable: false,+ archiveAsWaybackMachine: false,+ aiTag: false,+ };- setOptions(prev => [...prev, resetTag]);- }- };+ setOptions((prev) => [...prev, resetTag]);+ }+ };- const ARCHIVAL_OPTIONS: { type: ArchivalOptionKeys; icon: string; label: string }[] = [- { type: "aiTag", icon: "bi-tag", label: t("ai_tagging") },- { type: "archiveAsScreenshot", icon: "bi-file-earmark-image", label: t("screenshot") },- { type: "archiveAsMonolith", icon: "bi-filetype-html", label: t("webpage") },- { type: "archiveAsPDF", icon: "bi-file-earmark-pdf", label: t("pdf") },- { type: "archiveAsReadable", icon: "bi-file-earmark-text", label: t("readable") },- { type: "archiveAsWaybackMachine", icon: "bi-archive", label: t("archive_org_snapshot") },- ];+ const ARCHIVAL_OPTIONS: {+ type: ArchivalOptionKeys;+ icon: string;+ label: string;+ }[] = [+ { type: "aiTag", icon: "bi-tag", label: t("ai_tagging") },+ {+ type: "archiveAsScreenshot",+ icon: "bi-file-earmark-image",+ label: t("screenshot"),+ },+ {+ type: "archiveAsMonolith",+ icon: "bi-filetype-html",+ label: t("webpage"),+ },+ { type: "archiveAsPDF", icon: "bi-file-earmark-pdf", label: t("pdf") },+ {+ type: "archiveAsReadable",+ icon: "bi-file-earmark-text",+ label: t("readable"),+ },+ {+ type: "archiveAsWaybackMachine",+ icon: "bi-archive",+ label: t("archive_org_snapshot"),+ },+ ];- return {- ARCHIVAL_OPTIONS,- archivalTags,- options,- addTags,- toggleOption,- removeTag- };+ return {+ ARCHIVAL_OPTIONS,+ archivalTags,+ options,+ addTags,+ toggleOption,+ removeTag,+ };};-export { useArchivalTags };\ No newline at end of file+export { useArchivalTags };diff --git a/lib/api/archiveHandler.ts b/lib/api/archiveHandler.tsindex e49a1274..b9666c29 100644--- a/lib/api/archiveHandler.ts+++ b/lib/api/archiveHandler.ts@@ -26,7 +26,9 @@ export interface ArchivalSettings {aiTag: boolean;}-export default async function archiveHandler(link: LinkWithCollectionOwnerAndTags) {+export default async function archiveHandler(+ link: LinkWithCollectionOwnerAndTags+) {const user = link.collection?.owner;if (process.env.DISABLE_PRESERVATION === "true") {@@ -82,23 +84,28 @@ export default async function archiveHandler(link: LinkWithCollectionOwnerAndTagconst archivalTags = link.tags.filter(isArchivalTag);- const archivalSettings: ArchivalSettings = archivalTags.length > 0- ? {- archiveAsScreenshot: archivalTags.some(tag => tag.archiveAsScreenshot),- archiveAsMonolith: archivalTags.some(tag => tag.archiveAsMonolith),- archiveAsPDF: archivalTags.some(tag => tag.archiveAsPDF),- archiveAsReadable: archivalTags.some(tag => tag.archiveAsReadable),- archiveAsWaybackMachine: archivalTags.some(tag => tag.archiveAsWaybackMachine),- aiTag: archivalTags.some(tag => tag.aiTag),- }- : {- archiveAsScreenshot: user.archiveAsScreenshot,- archiveAsMonolith: user.archiveAsMonolith,- archiveAsPDF: user.archiveAsPDF,- archiveAsReadable: user.archiveAsReadable,- archiveAsWaybackMachine: user.archiveAsWaybackMachine,- aiTag: user.aiTaggingMethod !== AiTaggingMethod.DISABLED,- };+ const archivalSettings: ArchivalSettings =+ archivalTags.length > 0+ ? {+ archiveAsScreenshot: archivalTags.some(+ (tag) => tag.archiveAsScreenshot+ ),+ archiveAsMonolith: archivalTags.some((tag) => tag.archiveAsMonolith),+ archiveAsPDF: archivalTags.some((tag) => tag.archiveAsPDF),+ archiveAsReadable: archivalTags.some((tag) => tag.archiveAsReadable),+ archiveAsWaybackMachine: archivalTags.some(+ (tag) => tag.archiveAsWaybackMachine+ ),+ aiTag: archivalTags.some((tag) => tag.aiTag),+ }+ : {+ archiveAsScreenshot: user.archiveAsScreenshot,+ archiveAsMonolith: user.archiveAsMonolith,+ archiveAsPDF: user.archiveAsPDF,+ archiveAsReadable: user.archiveAsReadable,+ archiveAsWaybackMachine: user.archiveAsWaybackMachine,+ aiTag: user.aiTaggingMethod !== AiTaggingMethod.DISABLED,+ };try {await Promise.race([@@ -109,7 +116,8 @@ export default async function archiveHandler(link: LinkWithCollectionOwnerAndTag);// send to archive.org- if (archivalSettings.archiveAsWaybackMachine && link.url) sendToWayback(link.url);+ if (archivalSettings.archiveAsWaybackMachine && link.url)+ sendToWayback(link.url);if (linkType === "image" && !link.image) {await imageHandler(link, imageExtension); // archive image (jpeg/png)@@ -135,7 +143,8 @@ export default async function archiveHandler(link: LinkWithCollectionOwnerAndTagif (!link.preview) await handleArchivePreview(link, page);// Readability- if (archivalSettings.archiveAsReadable && !link.readable) await handleReadability(content, link);+ if (archivalSettings.archiveAsReadable && !link.readable)+ await handleReadability(content, link);// Auto-taggingif (@@ -180,7 +189,8 @@ export default async function archiveHandler(link: LinkWithCollectionOwnerAndTagmonolith: !finalLink.monolith ? "unavailable" : undefined,pdf: !finalLink.pdf ? "unavailable" : undefined,preview: !finalLink.preview ? "unavailable" : undefined,- aiTagged: archivalSettings.aiTag && !finalLink.aiTagged || undefined+ aiTagged:+ (archivalSettings.aiTag && !finalLink.aiTagged) || undefined,},});else {diff --git a/lib/api/controllers/tags/tagId/updateTagById.ts b/lib/api/controllers/tags/tagId/updateTagById.tsindex fc13706b..7bff0541 100644--- a/lib/api/controllers/tags/tagId/updateTagById.ts+++ b/lib/api/controllers/tags/tagId/updateTagById.ts@@ -13,8 +13,9 @@ export default async function updateTagById(if (!dataValidation.success) {return {- response: `Error: ${dataValidation.error.issues[0].message- } [${dataValidation.error.issues[0].path.join(", ")}]`,+ response: `Error: ${+ dataValidation.error.issues[0].message+ } [${dataValidation.error.issues[0].path.join(", ")}]`,status: 400,};}diff --git a/lib/api/controllers/users/userId/updateUserById.ts b/lib/api/controllers/users/userId/updateUserById.tsindex e5166707..3c0bba69 100644--- a/lib/api/controllers/users/userId/updateUserById.ts+++ b/lib/api/controllers/users/userId/updateUserById.ts@@ -19,8 +19,9 @@ export default async function updateUserById(if (!dataValidation.success) {return {- response: `Error: ${dataValidation.error.issues[0].message- } [${dataValidation.error.issues[0].path.join(", ")}]`,+ response: `Error: ${+ dataValidation.error.issues[0].message+ } [${dataValidation.error.issues[0].path.join(", ")}]`,status: 400,};}@@ -32,18 +33,18 @@ export default async function updateUserById(id: { not: userId },OR: emailEnabled? [- {- username: data.username.toLowerCase(),- },- {- email: data.email?.toLowerCase(),- },- ]+ {+ username: data.username.toLowerCase(),+ },+ {+ email: data.email?.toLowerCase(),+ },+ ]: [- {- username: data.username.toLowerCase(),- },- ],+ {+ username: data.username.toLowerCase(),+ },+ ],},});diff --git a/lib/api/manageLinkFiles.ts b/lib/api/manageLinkFiles.tsindex e68f5478..800dc283 100644--- a/lib/api/manageLinkFiles.ts+++ b/lib/api/manageLinkFiles.ts@@ -30,7 +30,10 @@ const removeFiles = async (linkId: number, collectionId: number) => {});};-const removePreservationFiles = async (linkId: number, collectionId: number) => {+const removePreservationFiles = async (+ linkId: number,+ collectionId: number+) => {await removeFile({filePath: `archives/${collectionId}/${linkId}.pdf`,diff --git a/lib/api/preservationScheme/handleScreenshotAndPdf.ts b/lib/api/preservationScheme/handleScreenshotAndPdf.tsindex 78b68307..409b2ec6 100644--- a/lib/api/preservationScheme/handleScreenshotAndPdf.ts+++ b/lib/api/preservationScheme/handleScreenshotAndPdf.ts@@ -19,7 +19,10 @@ const handleScreenshotAndPdf = async (if (linkExists) {const processingPromises = [];- if (archivalSettings.archiveAsScreenshot && !link.image?.startsWith("archive")) {+ if (+ archivalSettings.archiveAsScreenshot &&+ !link.image?.startsWith("archive")+ ) {processingPromises.push(page.screenshot({ fullPage: true, type: "jpeg" })diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.tsindex f4bc13b2..68110792 100644--- a/lib/shared/schemaValidation.ts+++ b/lib/shared/schemaValidation.ts@@ -41,12 +41,12 @@ export const PostUserSchema = () => {username: emailEnabled? z.string().optional(): z- .string()- .trim()- .toLowerCase()- .min(3)- .max(50)- .regex(/^[a-z0-9_-]{3,50}$/),+ .string()+ .trim()+ .toLowerCase()+ .min(3)+ .max(50)+ .regex(/^[a-z0-9_-]{3,50}$/),invite: z.boolean().optional(),});};@@ -236,7 +236,7 @@ export const PostArchivalTagSchema = z.object({archiveAsPDF: z.boolean().nullable(),archiveAsReadable: z.boolean().nullable(),archiveAsWaybackMachine: z.boolean().nullable(),- aiTag: z.boolean().nullable()+ aiTag: z.boolean().nullable(),})),});@@ -245,4 +245,7 @@ export const LinkArchiveActionSchema = z.object({action: z.enum(["allAndRePreserve", "allAndIgnore", "allBroken"]),});-export type LinkArchiveActionSchemaType = "allAndRePreserve" | "allAndIgnore" | "allBroken";+export type LinkArchiveActionSchemaType =+ | "allAndRePreserve"+ | "allAndIgnore"+ | "allBroken";diff --git a/pages/api/v1/links/archive/index.ts b/pages/api/v1/links/archive/index.tsindex 16782110..7c285faf 100644--- a/pages/api/v1/links/archive/index.ts+++ b/pages/api/v1/links/archive/index.ts@@ -7,127 +7,155 @@ import { isArchivalTag } from "@/hooks/useArchivalTags";import { ArchivalSettings } from "@/lib/api/archiveHandler";export default async function links(req: NextApiRequest, res: NextApiResponse) {- const user = await verifyUser({ req, res });- if (!user) return;+ const user = await verifyUser({ req, res });+ if (!user) return;- const isServerAdmin = user.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);+ const isServerAdmin = user.id === Number(process.env.NEXT_PUBLIC_ADMIN || 1);- if (!isServerAdmin) {- return res.status(401).json({ response: "Permission denied." });- }+ if (!isServerAdmin) {+ return res.status(401).json({ response: "Permission denied." });+ }- if (req.method === "DELETE") {- const dataValidation = LinkArchiveActionSchema.safeParse(req.body);- if (!dataValidation.success) {- return res.status(400).json({- response: `Error: ${dataValidation.error.issues[0].message- } [${dataValidation.error.issues[0].path.join(", ")}]`,- });- }+ if (req.method === "DELETE") {+ const dataValidation = LinkArchiveActionSchema.safeParse(req.body);+ if (!dataValidation.success) {+ return res.status(400).json({+ response: `Error: ${+ dataValidation.error.issues[0].message+ } [${dataValidation.error.issues[0].path.join(", ")}]`,+ });+ }- const { action } = dataValidation.data;- let count = 0;+ const { action } = dataValidation.data;+ let count = 0;- if (action === "allAndIgnore") {- const allLinks = await prisma.link.findMany();+ if (action === "allAndIgnore") {+ const allLinks = await prisma.link.findMany();- for (const link of allLinks) {- await removePreservationFiles(link.id, link.collectionId);- await prisma.link.update({- where: { id: link.id },- data: {- image: "unavailable",- pdf: "unavailable",- readable: "unavailable",- monolith: "unavailable",- preview: "unavailable",- },- });- }+ for (const link of allLinks) {+ await removePreservationFiles(link.id, link.collectionId);+ await prisma.link.update({+ where: { id: link.id },+ data: {+ image: "unavailable",+ pdf: "unavailable",+ readable: "unavailable",+ monolith: "unavailable",+ preview: "unavailable",+ },+ });+ }- return res.status(200).json({ response: "Success." });- } else if (action === "allAndRePreserve") {- const allLinks = await prisma.link.findMany();+ return res.status(200).json({ response: "Success." });+ } else if (action === "allAndRePreserve") {+ const allLinks = await prisma.link.findMany();- for (const link of allLinks) {- await removePreservationFiles(link.id, link.collectionId);- await prisma.link.update({- where: { id: link.id },- data: {- image: null,- pdf: null,- readable: null,- monolith: null,- preview: null,- },- });- count++;- }+ for (const link of allLinks) {+ await removePreservationFiles(link.id, link.collectionId);+ await prisma.link.update({+ where: { id: link.id },+ data: {+ image: null,+ pdf: null,+ readable: null,+ monolith: null,+ preview: null,+ },+ });+ count++;+ }- return res.status(200).json({ count });- } else if (action === "allBroken") {- const brokenArchives = await prisma.link.findMany({- where: {- OR: [- { image: "unavailable" },- { pdf: "unavailable" },- { readable: "unavailable" },- { monolith: "unavailable" },- { preview: "unavailable" },- ],- },- include: {- createdBy: {- select: {- archiveAsScreenshot: true,- archiveAsMonolith: true,- archiveAsPDF: true,- archiveAsReadable: true,- archiveAsWaybackMachine: true,- },- },- tags: true,- },- });+ return res.status(200).json({ count });+ } else if (action === "allBroken") {+ const brokenArchives = await prisma.link.findMany({+ where: {+ OR: [+ { image: "unavailable" },+ { pdf: "unavailable" },+ { readable: "unavailable" },+ { monolith: "unavailable" },+ { preview: "unavailable" },+ ],+ },+ include: {+ createdBy: {+ select: {+ archiveAsScreenshot: true,+ archiveAsMonolith: true,+ archiveAsPDF: true,+ archiveAsReadable: true,+ archiveAsWaybackMachine: true,+ },+ },+ tags: true,+ },+ });- for (const link of brokenArchives) {- const archivalTags = link.tags.filter(isArchivalTag);+ for (const link of brokenArchives) {+ const archivalTags = link.tags.filter(isArchivalTag);- const shouldArchive: Omit<ArchivalSettings, "aiTag" | "archiveAsWaybackMachine"> = archivalTags.length > 0- ? {- archiveAsScreenshot: archivalTags.some(tag => tag.archiveAsScreenshot),- archiveAsMonolith: archivalTags.some(tag => tag.archiveAsMonolith),- archiveAsPDF: archivalTags.some(tag => tag.archiveAsPDF),- archiveAsReadable: archivalTags.some(tag => tag.archiveAsReadable),- }- : {- archiveAsScreenshot: link.createdBy?.archiveAsScreenshot || false,- archiveAsMonolith: link.createdBy?.archiveAsMonolith || false,- archiveAsPDF: link.createdBy?.archiveAsPDF || false,- archiveAsReadable: link.createdBy?.archiveAsReadable || false,- };+ const shouldArchive: Omit<+ ArchivalSettings,+ "aiTag" | "archiveAsWaybackMachine"+ > =+ archivalTags.length > 0+ ? {+ archiveAsScreenshot: archivalTags.some(+ (tag) => tag.archiveAsScreenshot+ ),+ archiveAsMonolith: archivalTags.some(+ (tag) => tag.archiveAsMonolith+ ),+ archiveAsPDF: archivalTags.some((tag) => tag.archiveAsPDF),+ archiveAsReadable: archivalTags.some(+ (tag) => tag.archiveAsReadable+ ),+ }+ : {+ archiveAsScreenshot:+ link.createdBy?.archiveAsScreenshot || false,+ archiveAsMonolith: link.createdBy?.archiveAsMonolith || false,+ archiveAsPDF: link.createdBy?.archiveAsPDF || false,+ archiveAsReadable: link.createdBy?.archiveAsReadable || false,+ };- const needsReprocessing =- (link.image === "unavailable" && shouldArchive.archiveAsScreenshot) ||- (link.monolith === "unavailable" && shouldArchive.archiveAsMonolith) ||- (link.pdf === "unavailable" && shouldArchive.archiveAsPDF) ||- (link.readable === "unavailable" && shouldArchive.archiveAsReadable);+ const needsReprocessing =+ (link.image === "unavailable" && shouldArchive.archiveAsScreenshot) ||+ (link.monolith === "unavailable" &&+ shouldArchive.archiveAsMonolith) ||+ (link.pdf === "unavailable" && shouldArchive.archiveAsPDF) ||+ (link.readable === "unavailable" && shouldArchive.archiveAsReadable);- if (needsReprocessing) {- await prisma.link.update({- where: { id: link.id },- data: {- image: shouldArchive.archiveAsScreenshot && link.image === "unavailable" ? null : link.image,- pdf: shouldArchive.archiveAsPDF && link.pdf === "unavailable" ? null : link.pdf,- readable: shouldArchive.archiveAsReadable && link.readable === "unavailable" ? null : link.readable,- monolith: shouldArchive.archiveAsMonolith && link.monolith === "unavailable" ? null : link.monolith,- },- });- count++;- }- }+ if (needsReprocessing) {+ await prisma.link.update({+ where: { id: link.id },+ data: {+ image:+ shouldArchive.archiveAsScreenshot &&+ link.image === "unavailable"+ ? null+ : link.image,+ pdf:+ shouldArchive.archiveAsPDF && link.pdf === "unavailable"+ ? null+ : link.pdf,+ readable:+ shouldArchive.archiveAsReadable &&+ link.readable === "unavailable"+ ? null+ : link.readable,+ monolith:+ shouldArchive.archiveAsMonolith &&+ link.monolith === "unavailable"+ ? null+ : link.monolith,+ },+ });+ count++;+ }+ }- return res.status(200).json({ count });- }- }+ return res.status(200).json({ count });+ }+ }}diff --git a/pages/api/v1/tags/archival/index.ts b/pages/api/v1/tags/archival/index.tsindex ac24d672..e46ddfd4 100644--- a/pages/api/v1/tags/archival/index.ts+++ b/pages/api/v1/tags/archival/index.ts@@ -4,87 +4,91 @@ import { PostArchivalTagSchema } from "@/lib/shared/schemaValidation";import { Tag } from "@prisma/client";import { NextApiRequest, NextApiResponse } from "next";-export default async function archivalTags(req: NextApiRequest, res: NextApiResponse) {- const user = await verifyUser({ req, res });- if (!user) return;+export default async function archivalTags(+ req: NextApiRequest,+ res: NextApiResponse+) {+ const user = await verifyUser({ req, res });+ if (!user) return;- if (req.method === "POST") {- const dataValidation = PostArchivalTagSchema.safeParse(req.body);+ if (req.method === "POST") {+ const dataValidation = PostArchivalTagSchema.safeParse(req.body);- if (!dataValidation.success) {- return res.status(400).json({- response: `Error: ${dataValidation.error.issues[0].message- } [${dataValidation.error.issues[0].path.join(", ")}]`,- });- }+ if (!dataValidation.success) {+ return res.status(400).json({+ response: `Error: ${+ dataValidation.error.issues[0].message+ } [${dataValidation.error.issues[0].path.join(", ")}]`,+ });+ }- const { tags } = dataValidation.data;- const updatedTags: Tag[] = []+ const { tags } = dataValidation.data;+ const updatedTags: Tag[] = [];- for (const tag of tags) {- if (tag.newTag) {- const tagNameIsTaken = await prisma.tag.findFirst({- where: {- ownerId: user.id,- name: tag.label,- },- });+ for (const tag of tags) {+ if (tag.newTag) {+ const tagNameIsTaken = await prisma.tag.findFirst({+ where: {+ ownerId: user.id,+ name: tag.label,+ },+ });- // If the tag name is already taken by the user, skip creating a new tag- if (tagNameIsTaken) return+ // If the tag name is already taken by the user, skip creating a new tag+ if (tagNameIsTaken) return;- const newTag = await prisma.tag.create({- data: {- name: tag.label,- ownerId: user.id,- archiveAsScreenshot: tag.archiveAsScreenshot,- archiveAsMonolith: tag.archiveAsMonolith,- archiveAsPDF: tag.archiveAsPDF,- archiveAsReadable: tag.archiveAsReadable,- archiveAsWaybackMachine: tag.archiveAsWaybackMachine,- aiTag: tag.aiTag,- },- include: {- _count: true,- }- });- updatedTags.push(newTag);- } else {- const targetTag = await prisma.tag.findUnique({- where: {- name_ownerId: {- name: tag.label,- ownerId: user.id,- },- },- });+ const newTag = await prisma.tag.create({+ data: {+ name: tag.label,+ ownerId: user.id,+ archiveAsScreenshot: tag.archiveAsScreenshot,+ archiveAsMonolith: tag.archiveAsMonolith,+ archiveAsPDF: tag.archiveAsPDF,+ archiveAsReadable: tag.archiveAsReadable,+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine,+ aiTag: tag.aiTag,+ },+ include: {+ _count: true,+ },+ });+ updatedTags.push(newTag);+ } else {+ const targetTag = await prisma.tag.findUnique({+ where: {+ name_ownerId: {+ name: tag.label,+ ownerId: user.id,+ },+ },+ });- // If the tag is not found or the ownerId does not match, skip updating- if (targetTag && targetTag.ownerId !== user.id) return+ // If the tag is not found or the ownerId does not match, skip updating+ if (targetTag && targetTag.ownerId !== user.id) return;- const updatedTag = await prisma.tag.update({- where: {- name_ownerId: {- name: tag.label,- ownerId: user.id,- },- },- data: {- archiveAsScreenshot: tag.archiveAsScreenshot,- archiveAsMonolith: tag.archiveAsMonolith,- archiveAsPDF: tag.archiveAsPDF,- archiveAsReadable: tag.archiveAsReadable,- archiveAsWaybackMachine: tag.archiveAsWaybackMachine,- aiTag: tag.aiTag,- },- include: {- _count: true,- }- });- updatedTags.push(updatedTag);- }- }+ const updatedTag = await prisma.tag.update({+ where: {+ name_ownerId: {+ name: tag.label,+ ownerId: user.id,+ },+ },+ data: {+ archiveAsScreenshot: tag.archiveAsScreenshot,+ archiveAsMonolith: tag.archiveAsMonolith,+ archiveAsPDF: tag.archiveAsPDF,+ archiveAsReadable: tag.archiveAsReadable,+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine,+ aiTag: tag.aiTag,+ },+ include: {+ _count: true,+ },+ });+ updatedTags.push(updatedTag);+ }+ }- return res.status(200).json({ response: updatedTags });- }+ return res.status(200).json({ response: updatedTags });+ }}diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsxindex 268a86ec..2f23f680 100644--- a/pages/settings/preference.tsx+++ b/pages/settings/preference.tsx@@ -22,7 +22,14 @@ export default function Preference() {const { data: account } = useUser();const { data: tags } = useTags();const updateArchivalTags = useUpdateArchivalTags();- const { ARCHIVAL_OPTIONS, archivalTags, options, addTags, toggleOption, removeTag } = useArchivalTags(tags ? tags : []);+ const {+ ARCHIVAL_OPTIONS,+ archivalTags,+ options,+ addTags,+ toggleOption,+ removeTag,+ } = useArchivalTags(tags ? tags : []);const updateUser = useUpdateUser();const [user, setUser] = useState(account);@@ -114,22 +121,20 @@ export default function Preference() {useEffect(() => {const relevantKeys = [- 'archiveAsScreenshot',- 'archiveAsMonolith',- 'archiveAsPDF',- 'archiveAsReadable',- 'archiveAsWaybackMachine',- 'linksRouteTo',- 'preventDuplicateLinks',- 'aiTaggingMethod',- 'aiPredefinedTags',- 'dashboardRecentLinks',- 'dashboardPinnedLinks'+ "archiveAsScreenshot",+ "archiveAsMonolith",+ "archiveAsPDF",+ "archiveAsReadable",+ "archiveAsWaybackMachine",+ "linksRouteTo",+ "preventDuplicateLinks",+ "aiTaggingMethod",+ "aiPredefinedTags",+ "dashboardRecentLinks",+ "dashboardPinnedLinks",];- const hasChanges = relevantKeys.some(key =>- account[key] !== user[key]- );+ const hasChanges = relevantKeys.some((key) => account[key] !== user[key]);setHasAccountChanges(hasChanges);}, [account, user]);@@ -137,8 +142,8 @@ export default function Preference() {useEffect(() => {if (!tags || !archivalTags) return;- const hasChanges = archivalTags.some(newTag => {- const originalTag = tags.find(t => t.name === newTag.label);+ const hasChanges = archivalTags.some((newTag) => {+ const originalTag = tags.find((t) => t.name === newTag.label);if (!originalTag) return true;@@ -147,7 +152,8 @@ export default function Preference() {newTag.archiveAsMonolith !== originalTag.archiveAsMonolith ||newTag.archiveAsPDF !== originalTag.archiveAsPDF ||newTag.archiveAsReadable !== originalTag.archiveAsReadable ||- newTag.archiveAsWaybackMachine !== originalTag.archiveAsWaybackMachine ||+ newTag.archiveAsWaybackMachine !==+ originalTag.archiveAsWaybackMachine ||newTag.aiTag !== originalTag.aiTag);});@@ -164,7 +170,8 @@ export default function Preference() {const promises = [];if (hasAccountChanges) promises.push(updateUser.mutateAsync({ ...user }));- if (hasTagChanges) promises.push(updateArchivalTags.mutateAsync(archivalTags));+ if (hasTagChanges)+ promises.push(updateArchivalTags.mutateAsync(archivalTags));if (promises.length > 0) {await Promise.all(promises);@@ -205,10 +212,11 @@ export default function Preference() {].map(({ theme, icon, bgColor, textColor, activeColor }) => (<divkey={theme}- className={`w-full text-center outline-solid outline-neutral-content outline h-20 duration-100 rounded-xl flex items-center justify-center cursor-pointer select-none ${bgColor} ${localStorage.getItem("theme") === theme- ? `outline-primary ${activeColor}`- : textColor- }`}+ className={`w-full text-center outline-solid outline-neutral-content outline h-20 duration-100 rounded-xl flex items-center justify-center cursor-pointer select-none ${bgColor} ${+ localStorage.getItem("theme") === theme+ ? `outline-primary ${activeColor}`+ : textColor+ }`}onClick={() => updateSettings({ theme })}><i className={`${icon} text-3xl`}></i>@@ -428,37 +436,58 @@ export default function Preference() {</div><div className="w-full flex items-center justify-between"><p>{t("archival_tag_settings")}</p>- <div className="tooltip tooltip-top" data-tip={t("archival_tag_info")}>+ <div+ className="tooltip tooltip-top"+ data-tip={t("archival_tag_info")}+ ><i className="bi-info-lg text-lg leading-none"></i></div></div><div className="p-3"><ArchivalTagSelection onChange={addTags} options={options} /><div className="flex flex-col gap-2">- {archivalTags && archivalTags.filter(isArchivalTag).map((tag) => (- <div key={tag.label} className="w-full flex items-center justify-between bg-base-200 p-2 rounded first-of-type:mt-4">- <span className="text-xl sm:text-lg text-white truncate max-w-[10rem]">{tag.label}</span>- <div className="flex items-center gap-1">- <div className="grid grid-cols-3 sm:grid-cols-6 gap-1">- {ARCHIVAL_OPTIONS.map(({ type, icon, label }) => (- <div key={type} className="tooltip tooltip-top" data-tip={label}>- <button- onClick={() => toggleOption(tag, type)}- className={cn("py-1 px-2 bg-base-300 rounded", { "bg-primary bg-opacity-25": tag[type] })}+ {archivalTags &&+ archivalTags.filter(isArchivalTag).map((tag) => (+ <div+ key={tag.label}+ className="w-full flex items-center justify-between bg-base-200 p-2 rounded first-of-type:mt-4"+ >+ <span className="text-xl sm:text-lg text-white truncate max-w-[10rem]">+ {tag.label}+ </span>+ <div className="flex items-center gap-1">+ <div className="grid grid-cols-3 sm:grid-cols-6 gap-1">+ {ARCHIVAL_OPTIONS.map(({ type, icon, label }) => (+ <div+ key={type}+ className="tooltip tooltip-top"+ data-tip={label}>- <i className={`${icon} text-lg leading-none`}></i>- </button>- </div>- ))}- </div>- <div className="tooltip tooltip-top" data-tip={t("delete")}>- <button className="py-1 px-2" onClick={() => removeTag(tag)}>- <i className="bi-x text-lg leading-none"></i>- </button>+ <button+ onClick={() => toggleOption(tag, type)}+ className={cn("py-1 px-2 bg-base-300 rounded", {+ "bg-primary bg-opacity-25": tag[type],+ })}+ >+ <i className={`${icon} text-lg leading-none`}></i>+ </button>+ </div>+ ))}+ </div>+ <div+ className="tooltip tooltip-top"+ data-tip={t("delete")}+ >+ <button+ className="py-1 px-2"+ onClick={() => removeTag(tag)}+ >+ <i className="bi-x text-lg leading-none"></i>+ </button>+ </div></div></div>- </div>- ))}+ ))}</div></div></div>@@ -592,4 +621,4 @@ export default function Preference() {);}-export { getServerSideProps };\ No newline at end of file+export { getServerSideProps };diff --git a/pages/settings/worker.tsx b/pages/settings/worker.tsxindex 3cf43244..62997325 100644--- a/pages/settings/worker.tsx+++ b/pages/settings/worker.tsx@@ -8,128 +8,138 @@ import { LinkArchiveActionSchemaType } from "@/lib/shared/schemaValidation";import toast from "react-hot-toast";const useArchiveAction = () => {- const queryClient = useQueryClient();+ const queryClient = useQueryClient();- return useMutation({- mutationFn: async (action: LinkArchiveActionSchemaType) => {- const response = await fetch("/api/v1/links/archive", {- body: JSON.stringify({ action: action }),- method: "DELETE",- headers: {- "Content-Type": "application/json",- },- });+ return useMutation({+ mutationFn: async (action: LinkArchiveActionSchemaType) => {+ const response = await fetch("/api/v1/links/archive", {+ body: JSON.stringify({ action: action }),+ method: "DELETE",+ headers: {+ "Content-Type": "application/json",+ },+ });- const data = await response.json();- if (!response.ok) throw new Error(data.response);+ const data = await response.json();+ if (!response.ok) throw new Error(data.response);- return data;- },- onSuccess: () => {- queryClient.invalidateQueries({ queryKey: ["links"] });- },- });-}+ return data;+ },+ onSuccess: () => {+ queryClient.invalidateQueries({ queryKey: ["links"] });+ },+ });+};export default function Worker() {- const { t } = useTranslation();- const archiveAction = useArchiveAction();- const [showModal, setShowModal] = useState(false);- const [submitLoader, setSubmitLoader] = useState(false);- const [action, setAction] = useState<LinkArchiveActionSchemaType | undefined>();+ const { t } = useTranslation();+ const archiveAction = useArchiveAction();+ const [showModal, setShowModal] = useState(false);+ const [submitLoader, setSubmitLoader] = useState(false);+ const [action, setAction] = useState<+ LinkArchiveActionSchemaType | undefined+ >();- useEffect(() => {- if (showModal === false) {- setAction(undefined);- }- }, [showModal]);+ useEffect(() => {+ if (showModal === false) {+ setAction(undefined);+ }+ }, [showModal]);- const submit = async (action: LinkArchiveActionSchemaType) => {- if (!action || submitLoader) return;- setSubmitLoader(true);+ const submit = async (action: LinkArchiveActionSchemaType) => {+ if (!action || submitLoader) return;+ setSubmitLoader(true);- const load = toast.loading(t("deleting"));+ const load = toast.loading(t("deleting"));- await archiveAction.mutateAsync(action, {- onSettled: (data, error) => {- setSubmitLoader(false);- toast.dismiss(load);+ await archiveAction.mutateAsync(action, {+ onSettled: (data, error) => {+ setSubmitLoader(false);+ toast.dismiss(load);- if (error) {- toast.error(error.message);- } else {- if (action === "allAndIgnore") {- toast.success(t("deleted"));- } else {- if (data.count === 0) {- toast.success(t("no_broken_preservations"));- } else if (data.count === 1) {- toast.success(t("successfully_represerved_link"));- } else {- toast.success(t("successfully_represerved_links", { count: data.count }));- }- }- }- },- });- };+ if (error) {+ toast.error(error.message);+ } else {+ if (action === "allAndIgnore") {+ toast.success(t("deleted"));+ } else {+ if (data.count === 0) {+ toast.success(t("no_broken_preservations"));+ } else if (data.count === 1) {+ toast.success(t("successfully_represerved_link"));+ } else {+ toast.success(+ t("successfully_represerved_links", { count: data.count })+ );+ }+ }+ }+ },+ });+ };- return (- <SettingsLayout>- <p className="capitalize text-3xl font-thin inline">- {t("worker")}- </p>+ return (+ <SettingsLayout>+ <p className="capitalize text-3xl font-thin inline">{t("worker")}</p>- <div className="divider my-3"></div>+ <div className="divider my-3"></div>- <div className="w-full flex flex-col gap-6 justify-between">- <div className="flex flex-col sm:flex-row sm:items-center gap-3">- <span>{t("regenerate_broken_preservations")}</span>- <button- onClick={() => submit("allBroken")}- className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}- >- {t("confirm")}- </button>- </div>- <div className="flex flex-col sm:flex-row sm:items-center gap-3">- <span>{t("delete_all_preservations")}</span>- <button- className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}- onClick={() => {- setAction("allAndIgnore");- setShowModal(true);- }}- >- {t("confirm")}- </button>- </div>- <div className="flex flex-col sm:flex-row sm:items-center gap-3">- <span>{t("delete_all_preservations_and_regenerate")}</span>- <button- className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}- onClick={() => {- setAction("allAndRePreserve");- setShowModal(true);- }}- >- {t("confirm")}- </button>- </div>- </div>- {showModal && action && (- <ConfirmationModal title={action === "allAndIgnore" ? t("delete_all_preservations") : t("delete_all_preservations_and_regenerate")} onConfirmed={() => submit(action)} toggleModal={setShowModal}>- <p>{t("delete_all_preservation_warning")}</p>- <div role="alert" className="alert alert-warning mt-3">- <i className="bi-exclamation-triangle text-xl" />- <span>- <b>{t("warning")}:</b> {t("irreversible_action_warning")}- </span>- </div>- </ConfirmationModal>- )}- </SettingsLayout>- );+ <div className="w-full flex flex-col gap-6 justify-between">+ <div className="flex flex-col sm:flex-row sm:items-center gap-3">+ <span>{t("regenerate_broken_preservations")}</span>+ <button+ onClick={() => submit("allBroken")}+ className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}+ >+ {t("confirm")}+ </button>+ </div>+ <div className="flex flex-col sm:flex-row sm:items-center gap-3">+ <span>{t("delete_all_preservations")}</span>+ <button+ className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}+ onClick={() => {+ setAction("allAndIgnore");+ setShowModal(true);+ }}+ >+ {t("confirm")}+ </button>+ </div>+ <div className="flex flex-col sm:flex-row sm:items-center gap-3">+ <span>{t("delete_all_preservations_and_regenerate")}</span>+ <button+ className={`btn btn-sm ml-auto btn-accent dark:border-violet-400 text-white tracking-wider w-fit flex items-center gap-2`}+ onClick={() => {+ setAction("allAndRePreserve");+ setShowModal(true);+ }}+ >+ {t("confirm")}+ </button>+ </div>+ </div>+ {showModal && action && (+ <ConfirmationModal+ title={+ action === "allAndIgnore"+ ? t("delete_all_preservations")+ : t("delete_all_preservations_and_regenerate")+ }+ onConfirmed={() => submit(action)}+ toggleModal={setShowModal}+ >+ <p>{t("delete_all_preservation_warning")}</p>+ <div role="alert" className="alert alert-warning mt-3">+ <i className="bi-exclamation-triangle text-xl" />+ <span>+ <b>{t("warning")}:</b> {t("irreversible_action_warning")}+ </span>+ </div>+ </ConfirmationModal>+ )}+ </SettingsLayout>+ );}export { getServerSideProps };diff --git a/pages/tags/[id].tsx b/pages/tags/[id].tsxindex 90898f11..2501473b 100644--- a/pages/tags/[id].tsx+++ b/pages/tags/[id].tsx@@ -171,15 +171,14 @@ export default function Index() {</form>) : (<>- <p className="sm:text-3xl text-2xl">- {activeTag?.name}- </p>+ <p className="sm:text-3xl text-2xl">{activeTag?.name}</p><div className="relative"><div- className={`dropdown dropdown-bottom font-normal ${activeTag?.name.length && activeTag?.name.length > 8+ className={`dropdown dropdown-bottom font-normal ${+ activeTag?.name.length && activeTag?.name.length > 8? "dropdown-end": ""- }`}+ }`}><divtabIndex={0}diff --git a/types/global.ts b/types/global.tsindex 63b776bb..f3c07e2f 100644--- a/types/global.ts+++ b/types/global.ts@@ -70,7 +70,7 @@ export type LinkWithCollectionOwnerAndTags = LinksIncludingTags & {collection: Collection & {owner: User;};-}+};export enum ViewMode {Card = "card",