⚡️⚡️⚡️ 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
add ai tagging & fix select
Isaacd360f612e2e0
diff --git a/components/ArchiveTags.tsx b/components/ArchiveTags.tsxdeleted file mode 100644index cd433cb3..00000000--- a/components/ArchiveTags.tsx+++ /dev/null@@ -1,50 +0,0 @@-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/ArchivalTagSelection.tsx b/components/InputSelect/ArchivalTagSelection.tsxnew file mode 100644index 00000000..248d915c--- /dev/null+++ b/components/InputSelect/ArchivalTagSelection.tsx@@ -0,0 +1,55 @@+import { useEffect, useState } from "react";+import CreatableSelect from "react-select/creatable";+import { styles } from "./styles";+import { ArchivalTagOption } from "./types";+import { useTags } from "@/hooks/store/tags";+import { useTranslation } from "next-i18next";+import { Tag } from "@prisma/client";++type Props = {+ onChange: (e: any) => void;+ selectedTags: ArchivalTagOption[] | [];+};++export default function ArchivalTagSelection({+ onChange,+ selectedTags+}: Props) {+ const { data: tags = [] } = useTags();+ const { t } = useTranslation();+ const [options, setOptions] = useState<ArchivalTagOption[]>([]);++ useEffect(() => {+ const formattedTags = tags.map((e: Tag) => {+ return {+ value: e.id,+ label: e.name,+ archiveAsScreenshot: e.archiveAsScreenshot,+ archiveAsMonolith: e.archiveAsMonolith,+ archiveAsPDF: e.archiveAsPDF,+ archiveAsReadable: e.archiveAsReadable,+ archiveAsWaybackMachine: e.archiveAsWaybackMachine,+ };+ });++ const filteredTags = formattedTags.filter((tag: ArchivalTagOption) => {+ return !selectedTags.find((selectedTag) => selectedTag.value === tag.value);+ });++ setOptions(filteredTags);+ }, [tags, selectedTags]);++ 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 6b83f275..cf79157c 100644--- a/components/InputSelect/CollectionSelection.tsx+++ b/components/InputSelect/CollectionSelection.tsx@@ -1,7 +1,7 @@import { useRouter } from "next/router";import { useEffect, useState } from "react";import { styles } from "./styles";-import { Options } from "./types";+import { Option } from "./types";import CreatableSelect from "react-select/creatable";import Select from "react-select";import { useCollections } from "@/hooks/store/collections";@@ -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;@@ -35,7 +35,7 @@ export default function CollectionSelection({const router = useRouter();- const [options, setOptions] = useState<Options[]>([]);+ const [options, setOptions] = useState<Option[]>([]);const collectionId = Number(router.query.id);@@ -117,7 +117,7 @@ export default function CollectionSelection({components={{Option: customOption,}}- // menuPosition="fixed"+ // menuPosition="fixed"/>);} else {@@ -135,7 +135,7 @@ export default function CollectionSelection({components={{Option: customOption,}}- // menuPosition="fixed"+ // menuPosition="fixed"/>);}diff --git a/components/InputSelect/TagSelection.tsx b/components/InputSelect/TagSelection.tsxindex 698b78e1..184299e7 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 { ArchivalTagOption, Option } from "./types";+import { Option } from "./types";import { useTags } from "@/hooks/store/tags";import { useTranslation } from "next-i18next";@@ -11,7 +11,6 @@ type Props = {value?: number;label: string;}[];- type?: "normal" | "archival";autoFocus?: boolean;onBlur?: any;};@@ -19,36 +18,20 @@ type Props = {export default function TagSelection({onChange,defaultValue,- type = "normal",autoFocus,onBlur,}: Props) {const { data: tags = [] } = useTags();const { t } = useTranslation();- const [options, setOptions] = useState<ArchivalTagOption[] | Option[]>([]);+ const [options, setOptions] = useState<Option[]>([]);useEffect(() => {- 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,- };- }+ const formatedCollections = tags.map((e: any) => {+ return { value: e.id, label: e.name };});- setOptions(formattedTags);+ setOptions(formatedCollections);}, [tags]);return (@@ -60,11 +43,10 @@ export default function TagSelection({options={options}styles={styles}defaultValue={defaultValue}- value={type === "archival" && []}placeholder={t("tag_selection_placeholder")}isMultiautoFocus={autoFocus}onBlur={onBlur}/>);-}+}\ No newline at end of filediff --git a/components/InputSelect/types.ts b/components/InputSelect/types.tsindex b3177027..b25caddb 100644--- a/components/InputSelect/types.ts+++ b/components/InputSelect/types.ts@@ -9,4 +9,5 @@ export interface ArchivalTagOption extends Option {archiveAsPDF?: boolean;archiveAsReadable?: boolean;archiveAsWaybackMachine?: boolean;+ aiTag?: boolean;}\ No newline at end of filediff --git a/pages/api/v1/tags/archival/index.ts b/pages/api/v1/tags/archival/index.tsnew file mode 100644index 00000000..04090d9b--- /dev/null+++ b/pages/api/v1/tags/archival/index.ts@@ -0,0 +1,19 @@+import verifyUser from "@/lib/api/verifyUser";+import { NextApiRequest, NextApiResponse } from "next";++export default async function archivalTags(req: NextApiRequest, res: NextApiResponse) {+ const user = await verifyUser({ req, res });+ if (!user) return;++ // The body should be like this+ // {+ // tags: [{ id: 1, archiveAsScreenshot: true }, { id: 2, archiveAsMonolith: true }]+ //}++ // Update or create+ // Will sometimes sent ID, sometimes not++ if (req.method === "POST") {++ }+}diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsxindex 96bc0942..59fa2573 100644--- a/pages/settings/preference.tsx+++ b/pages/settings/preference.tsx@@ -1,5 +1,5 @@import SettingsLayout from "@/layouts/SettingsLayout";-import { useState, useEffect, use } from "react";+import { useState, useEffect } from "react";import SubmitButton from "@/components/SubmitButton";import { toast } from "react-hot-toast";import Checkbox from "@/components/Checkbox";@@ -8,11 +8,12 @@ import { useTranslation } from "next-i18next";import getServerSideProps from "@/lib/client/getServerSideProps";import { AiTaggingMethod, LinksRouteTo, Tag } from "@prisma/client";import { useUpdateUser, useUser } from "@/hooks/store/user";-import TagSelection from "@/components/InputSelect/TagSelection";+import ArchivalTagSelection from "@/components/InputSelect/ArchivalTagSelection";import { useConfig } from "@/hooks/store/config";import { ArchivalTagOption } from "@/components/InputSelect/types";-import ArchiveTags from "@/components/ArchiveTags";import { useTags } from "@/hooks/store/tags";+import { cn } from "@/lib/client/utils";+import TagSelection from "@/components/InputSelect/TagSelection";export default function Preference() {const { t } = useTranslation();@@ -49,10 +50,8 @@ export default function Preference() {account.aiTaggingMethod);const [aiPredefinedTags, setAiPredefinedTags] = useState<string[]>();+ const [archivalTags, setArchivalTags] = useState<ArchivalTagOption[]>([]);- const [archivalTags, setArchivalTags] = useState<ArchivalTagOption[]>();-- console.log(archivalTags);const { data: config } = useConfig();useEffect(() => {@@ -144,6 +143,25 @@ export default function Preference() {);};+ const handleArchivalTagChange = (e: ArchivalTagOption[]) => {+ const newTags = e || [];+ const existingTags = archivalTags || [];++ // Filter out any new tags that already exist in archivalTags based on label+ const uniqueNewTags = newTags.filter(newTag =>+ !existingTags.some(existingTag => existingTag.label === newTag.label)+ );++ setArchivalTags([...existingTags, ...uniqueNewTags]);+ };++ const handleDeleteTag = (tagToDelete: ArchivalTagOption) => {+ const updatedTags = archivalTags?.filter(tag => tag.label !== tagToDelete.label);+ setArchivalTags(updatedTags);+ }++ console.log(archivalTags);+return (<SettingsLayout><p className="capitalize text-3xl font-thin inline">{t("preference")}</p>@@ -356,11 +374,38 @@ export default function Preference() {}/></div>- <p>{t("tag_formats_to_archive")}</p>+ <p>{t("tag_settings")}</p><div className="p-3">- <TagSelection type="archival" onChange={(e: ArchivalTagOption[]) => setArchivalTags([...archivalTags || [], ...(e || [])])} />+ <ArchivalTagSelection onChange={handleArchivalTagChange} selectedTags={archivalTags} /><div className="flex flex-col gap-2">- <ArchiveTags archivalTags={archivalTags} />+ {archivalTags && archivalTags.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">+ {[+ { 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") },+ ].map(({ type, icon, label }) => (+ <div key={type} className="tooltip tooltip-top" data-tip={label}>+ <button className={cn("py-1 px-2 bg-base-300 rounded", { "bg-primary bg-opacity-25": tag[type as keyof ArchivalTagOption] })}>+ <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={() => handleDeleteTag(tag)}>+ <i className="bi-x text-lg leading-none"></i>+ </button>+ </div>+ </div>+ </div>+ ))}</div></div></div>diff --git a/prisma/migrations/20250203002023_add_ai_tagging_option_for_tags/migration.sql b/prisma/migrations/20250203002023_add_ai_tagging_option_for_tags/migration.sqlnew file mode 100644index 00000000..40716d64--- /dev/null+++ b/prisma/migrations/20250203002023_add_ai_tagging_option_for_tags/migration.sql@@ -0,0 +1,2 @@+-- AlterTable+ALTER TABLE "Tag" ADD COLUMN "aiTag" BOOLEAN;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 8ee26797..7982a0a3 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -186,6 +186,7 @@ model Tag {archiveAsPDF Boolean?archiveAsReadable Boolean?archiveAsWaybackMachine Boolean?+ aiTag Boolean?createdAt DateTime @default(now())updatedAt DateTime @default(now()) @updatedAtdiff --git a/public/locales/en/common.json b/public/locales/en/common.jsonindex 5fcbb4e6..7bdad995 100644--- a/public/locales/en/common.json+++ b/public/locales/en/common.json@@ -465,5 +465,6 @@"new_note": "New Note","add_a_title_placeholder": "Add a title...","write_notes_here_placeholder": "Write some notes here...",- "tag_formats_to_archive": "Formats to save based on tags:"+ "tag_settings": "Tag archival and processing settings:",+ "ai_tagging": "AI Tagging"}\ No newline at end of file