⚡️⚡️⚡️ 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
Start tag archival options
Isaac0a4d62491d6b
diff --git a/components/ArchiveTags.tsx b/components/ArchiveTags.tsxnew file mode 100644index 00000000..cd433cb3--- /dev/null+++ b/components/ArchiveTags.tsx@@ -0,0 +1,50 @@+import React from 'react';+import { ArchivalTagOption } from './InputSelect/types';+import { useTranslation } from 'react-i18next';++interface ArchiveTagsProps {+ archivalTags?: ArchivalTagOption[];+ // onUpdateTag: (id: number, tag: ArchivalTagOptions) => void;+}++const ArchiveTags: React.FC<ArchiveTagsProps> = ({ archivalTags }) => {+ const { t } = useTranslation();+ const buttons = [+ { key: 'screenshot', icon: 'file-earmark-image', flag: 'archiveAsScreenshot' },+ { key: 'webpage', icon: 'filetype-html', flag: 'archiveAsMonolith' },+ { key: 'pdf', icon: 'file-earmark-pdf', flag: 'archiveAsPDF' },+ { key: 'readable', icon: 'file-earmark-text', flag: 'archiveAsReadable' },+ { key: 'archive_org_snapshot', icon: 'archive', flag: 'archiveAsWaybackMachine' }+ ] as const;++ return (+ <>+ {archivalTags?.map((tag, index) => (+ <div+ key={`${tag.label}-${index}`}+ className="w-full flex items-center justify-between bg-base-200 p-2 rounded first-of-type:mt-4"+ >+ <span className="text-lg text-white">{tag.label}</span>+ <div className="grid grid-cols-6 gap-2">+ {buttons.map(({ key, icon, flag }) => (+ <div key={key} className="tooltip tooltip-top" data-tip={t(key)}>+ <button+ className={`py-1 px-2 bg-base-300 rounded ${tag[flag] ? 'bg-primary bg-opacity-25' : ''}`}+ >+ <i className={`bi-${icon} text-lg leading-none`}></i>+ </button>+ </div>+ ))}+ <div className="tooltip tooltip-top" data-tip={t("delete")}>+ <button className="py-1 px-2">+ <i className="bi-x text-lg leading-none"></i>+ </button>+ </div>+ </div>+ </div>+ ))}+ </>+ );+};++export default ArchiveTags;\ No newline at end of filediff --git a/components/InputSelect/TagSelection.tsx b/components/InputSelect/TagSelection.tsxindex 209ee7b4..698b78e1 100644--- a/components/InputSelect/TagSelection.tsx+++ b/components/InputSelect/TagSelection.tsx@@ -1,7 +1,7 @@import { useEffect, useState } from "react";import CreatableSelect from "react-select/creatable";import { styles } from "./styles";-import { Options } from "./types";+import { ArchivalTagOption, Option } from "./types";import { useTags } from "@/hooks/store/tags";import { useTranslation } from "next-i18next";@@ -11,6 +11,7 @@ type Props = {value?: number;label: string;}[];+ type?: "normal" | "archival";autoFocus?: boolean;onBlur?: any;};@@ -18,20 +19,36 @@ type Props = {export default function TagSelection({onChange,defaultValue,+ type = "normal",autoFocus,onBlur,}: Props) {const { data: tags = [] } = useTags();const { t } = useTranslation();- const [options, setOptions] = useState<Options[]>([]);+ const [options, setOptions] = useState<ArchivalTagOption[] | Option[]>([]);useEffect(() => {- const formatedCollections = tags.map((e: any) => {- return { value: e.id, label: e.name };+ const formattedTags = tags.map((e: any) => {+ if (type === "archival") {+ return {+ value: e.id,+ label: e.name,+ archiveAsScreenshot: e.archiveAsScreenshot,+ archiveAsMonolith: e.archiveAsMonolith,+ archiveAsPDF: e.archiveAsPDF,+ archiveAsReadable: e.archiveAsReadable,+ archiveAsWaybackMachine: e.archiveAsWaybackMachine,+ };+ } else {+ return {+ value: e.id,+ label: e.name,+ };+ }});- setOptions(formatedCollections);+ setOptions(formattedTags);}, [tags]);return (@@ -43,6 +60,7 @@ export default function TagSelection({options={options}styles={styles}defaultValue={defaultValue}+ value={type === "archival" && []}placeholder={t("tag_selection_placeholder")}isMultiautoFocus={autoFocus}diff --git a/components/InputSelect/types.ts b/components/InputSelect/types.tsindex dc8cd1fc..b3177027 100644--- a/components/InputSelect/types.ts+++ b/components/InputSelect/types.ts@@ -1,4 +1,12 @@-export interface Options {+export interface Option {label: string;value?: string | number;}++export interface ArchivalTagOption extends Option {+ archiveAsScreenshot?: boolean;+ archiveAsMonolith?: boolean;+ archiveAsPDF?: boolean;+ archiveAsReadable?: boolean;+ archiveAsWaybackMachine?: boolean;+}\ No newline at end of filediff --git a/lib/api/controllers/tags/tagId/updateTagById.ts b/lib/api/controllers/tags/tagId/updateTagById.tsindex 7bff0541..f4bdea90 100644--- a/lib/api/controllers/tags/tagId/updateTagById.ts+++ b/lib/api/controllers/tags/tagId/updateTagById.ts@@ -13,14 +13,13 @@ 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,};}- const { name } = dataValidation.data;+ const { name, archiveAsScreenshot, archiveAsMonolith, archiveAsPDF, archiveAsReadable, archiveAsWaybackMachine } = dataValidation.data;const tagNameIsTaken = await prisma.tag.findFirst({where: {@@ -53,6 +52,11 @@ export default async function updateTagById(},data: {name: name,+ archiveAsScreenshot: archiveAsScreenshot,+ archiveAsMonolith: archiveAsMonolith,+ archiveAsPDF: archiveAsPDF,+ archiveAsReadable: archiveAsReadable,+ archiveAsWaybackMachine: archiveAsWaybackMachine,},});diff --git a/lib/shared/schemaValidation.ts b/lib/shared/schemaValidation.tsindex e608264e..2d6fbb1b 100644--- a/lib/shared/schemaValidation.ts+++ b/lib/shared/schemaValidation.ts@@ -213,6 +213,11 @@ export type UpdateCollectionSchemaType = z.infer<typeof UpdateCollectionSchema>;export const UpdateTagSchema = z.object({name: z.string().trim().max(50),+ archiveAsScreenshot: z.boolean().nullable(),+ archiveAsMonolith: z.boolean().nullable(),+ archiveAsPDF: z.boolean().nullable(),+ archiveAsReadable: z.boolean().nullable(),+ archiveAsWaybackMachine: z.boolean().nullable(),});export type UpdateTagSchemaType = z.infer<typeof UpdateTagSchema>;diff --git a/pages/api/v1/tags/index.ts b/pages/api/v1/tags/index.tsindex 58add22c..dd5382f7 100644--- a/pages/api/v1/tags/index.ts+++ b/pages/api/v1/tags/index.ts@@ -10,6 +10,7 @@ export default async function tags(req: NextApiRequest, res: NextApiResponse) {const tags = await getTags({userId: user.id,});+return res.status(tags?.status || 500).json({ response: tags?.response });}}diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsxindex 73a387e3..96bc0942 100644--- a/pages/settings/preference.tsx+++ b/pages/settings/preference.tsx@@ -1,21 +1,25 @@import SettingsLayout from "@/layouts/SettingsLayout";-import { useState, useEffect } from "react";+import { useState, useEffect, use } from "react";import SubmitButton from "@/components/SubmitButton";import { toast } from "react-hot-toast";import Checkbox from "@/components/Checkbox";import useLocalSettingsStore from "@/store/localSettings";import { useTranslation } from "next-i18next";import getServerSideProps from "@/lib/client/getServerSideProps";-import { AiTaggingMethod, LinksRouteTo } from "@prisma/client";+import { AiTaggingMethod, LinksRouteTo, Tag } from "@prisma/client";import { useUpdateUser, useUser } from "@/hooks/store/user";import TagSelection from "@/components/InputSelect/TagSelection";import { useConfig } from "@/hooks/store/config";+import { ArchivalTagOption } from "@/components/InputSelect/types";+import ArchiveTags from "@/components/ArchiveTags";+import { useTags } from "@/hooks/store/tags";export default function Preference() {const { t } = useTranslation();const { settings, updateSettings } = useLocalSettingsStore();const [submitLoader, setSubmitLoader] = useState(false);const { data: account } = useUser();+ const { data: tags } = useTags();const updateUser = useUpdateUser();const [user, setUser] = useState(account);@@ -46,6 +50,9 @@ export default function Preference() {);const [aiPredefinedTags, setAiPredefinedTags] = useState<string[]>();+ const [archivalTags, setArchivalTags] = useState<ArchivalTagOption[]>();++ console.log(archivalTags);const { data: config } = useConfig();useEffect(() => {@@ -98,6 +105,23 @@ export default function Preference() {}}, [account]);+ useEffect(() => {+ if (tags) {+ setArchivalTags(+ tags+ .filter((tag: Tag) => tag.archiveAsScreenshot || tag.archiveAsMonolith || tag.archiveAsPDF || tag.archiveAsReadable || tag.archiveAsWaybackMachine)+ .map((tag: Tag) => ({+ label: tag.name,+ archiveAsScreenshot: tag.archiveAsScreenshot,+ archiveAsMonolith: tag.archiveAsMonolith,+ archiveAsPDF: tag.archiveAsPDF,+ archiveAsReadable: tag.archiveAsReadable,+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine,+ }))+ );+ }+ }, [tags]);+const submit = async () => {setSubmitLoader(true);@@ -332,6 +356,13 @@ export default function Preference() {}/></div>+ <p>{t("tag_formats_to_archive")}</p>+ <div className="p-3">+ <TagSelection type="archival" onChange={(e: ArchivalTagOption[]) => setArchivalTags([...archivalTags || [], ...(e || [])])} />+ <div className="flex flex-col gap-2">+ <ArchiveTags archivalTags={archivalTags} />+ </div>+ </div></div><div>diff --git a/pages/tags/[id].tsx b/pages/tags/[id].tsxindex 689517f2..90898f11 100644--- a/pages/tags/[id].tsx+++ b/pages/tags/[id].tsx@@ -171,16 +171,15 @@ export default function Index() {</form>) : (<>- <p className="sm:text-3xl text-2xl capitalize">+ <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/prisma/migrations/20250202201004_add_archive_options_for_tags/migration.sql b/prisma/migrations/20250202201004_add_archive_options_for_tags/migration.sqlnew file mode 100644index 00000000..28adde47--- /dev/null+++ b/prisma/migrations/20250202201004_add_archive_options_for_tags/migration.sql@@ -0,0 +1,6 @@+-- AlterTable+ALTER TABLE "Tag" ADD COLUMN "archiveAsMonolith" BOOLEAN,+ADD COLUMN "archiveAsPDF" BOOLEAN,+ADD COLUMN "archiveAsReadable" BOOLEAN,+ADD COLUMN "archiveAsScreenshot" BOOLEAN,+ADD COLUMN "archiveAsWaybackMachine" BOOLEAN;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 551de66f..8ee26797 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -176,13 +176,18 @@ model Link {}model Tag {- id Int @id @default(autoincrement())- name String- links Link[]- owner User @relation(fields: [ownerId], references: [id])- ownerId Int- createdAt DateTime @default(now())- updatedAt DateTime @default(now()) @updatedAt+ id Int @id @default(autoincrement())+ name String+ links Link[]+ owner User @relation(fields: [ownerId], references: [id])+ ownerId Int+ archiveAsScreenshot Boolean?+ archiveAsMonolith Boolean?+ archiveAsPDF Boolean?+ archiveAsReadable Boolean?+ archiveAsWaybackMachine Boolean?+ createdAt DateTime @default(now())+ updatedAt DateTime @default(now()) @updatedAt@@unique([name, ownerId])@@index([ownerId])diff --git a/public/locales/en/common.json b/public/locales/en/common.jsonindex 79c5ee74..5fcbb4e6 100644--- a/public/locales/en/common.json+++ b/public/locales/en/common.json@@ -464,5 +464,6 @@"write_new_note": "Write a New Note","new_note": "New Note","add_a_title_placeholder": "Add a title...",- "write_notes_here_placeholder": "Write some notes here..."+ "write_notes_here_placeholder": "Write some notes here...",+ "tag_formats_to_archive": "Formats to save based on tags:"}\ No newline at end of file