Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

complete toggling options

Isaac9177ad6a727c
diff --git a/components/InputSelect/ArchivalTagSelection.tsx b/components/InputSelect/ArchivalTagSelection.tsx
index 248d915c..8833f27b 100644
--- a/components/InputSelect/ArchivalTagSelection.tsx
+++ b/components/InputSelect/ArchivalTagSelection.tsx
@@ -20,19 +20,20 @@ export default function ArchivalTagSelection({
const [options, setOptions] = useState<ArchivalTagOption[]>([]);
useEffect(() => {
- const formattedTags = tags.map((e: Tag) => {
+ const formattedTags = tags.map((tag: Tag) => {
return {
- value: e.id,
- label: e.name,
- archiveAsScreenshot: e.archiveAsScreenshot,
- archiveAsMonolith: e.archiveAsMonolith,
- archiveAsPDF: e.archiveAsPDF,
- archiveAsReadable: e.archiveAsReadable,
- archiveAsWaybackMachine: e.archiveAsWaybackMachine,
+ value: tag.id,
+ label: tag.name,
+ archiveAsScreenshot: tag.archiveAsScreenshot || false,
+ archiveAsMonolith: tag.archiveAsMonolith || false,
+ archiveAsPDF: tag.archiveAsPDF || false,
+ archiveAsReadable: tag.archiveAsReadable || false,
+ archiveAsWaybackMachine: tag.archiveAsWaybackMachine || false,
+ aiTag: tag.aiTag || false
};
});
- const filteredTags = formattedTags.filter((tag: ArchivalTagOption) => {
+ const filteredTags = formattedTags.filter((tag) => {
return !selectedTags.find((selectedTag) => selectedTag.value === tag.value);
});
diff --git a/components/InputSelect/types.ts b/components/InputSelect/types.ts
index b25caddb..7ce74389 100644
--- a/components/InputSelect/types.ts
+++ b/components/InputSelect/types.ts
@@ -4,10 +4,12 @@ export interface Option {
}
export interface ArchivalTagOption extends Option {
- archiveAsScreenshot?: boolean;
- archiveAsMonolith?: boolean;
- archiveAsPDF?: boolean;
- archiveAsReadable?: boolean;
- archiveAsWaybackMachine?: boolean;
- aiTag?: boolean;
-}
\ No newline at end of file
+ archiveAsScreenshot: boolean | null;
+ archiveAsMonolith: boolean | null;
+ archiveAsPDF: boolean | null
+ archiveAsReadable: boolean | null;
+ archiveAsWaybackMachine: boolean | null;
+ aiTag: boolean | null;
+}
+
+export type ArchivalOptionKeys = keyof Omit<ArchivalTagOption, "label" | "value">;
diff --git a/hooks/store/tags.tsx b/hooks/store/tags.tsx
index a2c0b7df..93840d2c 100644
--- a/hooks/store/tags.tsx
+++ b/hooks/store/tags.tsx
@@ -1,8 +1,9 @@
-import { useQuery, useMutation, useQueryClient } 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";
-const useTags = () => {
+const useTags = (): UseQueryResult<Tag[], Error> => {
const { status } = useSession();
return useQuery({
diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsx
index 59fa2573..861c31f5 100644
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@ -10,7 +10,7 @@ import { AiTaggingMethod, LinksRouteTo, Tag } from "@prisma/client";
import { useUpdateUser, useUser } from "@/hooks/store/user";
import ArchivalTagSelection from "@/components/InputSelect/ArchivalTagSelection";
import { useConfig } from "@/hooks/store/config";
-import { ArchivalTagOption } from "@/components/InputSelect/types";
+import { ArchivalOptionKeys, ArchivalTagOption } from "@/components/InputSelect/types";
import { useTags } from "@/hooks/store/tags";
import { cn } from "@/lib/client/utils";
import TagSelection from "@/components/InputSelect/TagSelection";
@@ -108,14 +108,16 @@ export default function Preference() {
if (tags) {
setArchivalTags(
tags
- .filter((tag: Tag) => tag.archiveAsScreenshot || tag.archiveAsMonolith || tag.archiveAsPDF || tag.archiveAsReadable || tag.archiveAsWaybackMachine)
+ .filter((tag: Tag) => tag.archiveAsScreenshot || tag.archiveAsMonolith || tag.archiveAsPDF || tag.archiveAsReadable || tag.archiveAsWaybackMachine || tag.aiTag)
.map((tag: Tag) => ({
label: tag.name,
+ value: tag.id,
archiveAsScreenshot: tag.archiveAsScreenshot,
archiveAsMonolith: tag.archiveAsMonolith,
archiveAsPDF: tag.archiveAsPDF,
archiveAsReadable: tag.archiveAsReadable,
archiveAsWaybackMachine: tag.archiveAsWaybackMachine,
+ aiTag: tag.aiTag,
}))
);
}
@@ -144,8 +146,8 @@ export default function Preference() {
};
const handleArchivalTagChange = (e: ArchivalTagOption[]) => {
- const newTags = e || [];
- const existingTags = archivalTags || [];
+ const newTags = e;
+ const existingTags = archivalTags;
// Filter out any new tags that already exist in archivalTags based on label
const uniqueNewTags = newTags.filter(newTag =>
@@ -155,12 +157,27 @@ export default function Preference() {
setArchivalTags([...existingTags, ...uniqueNewTags]);
};
+ const handleArchiveOptionChange = (tag: ArchivalTagOption, option: ArchivalOptionKeys) => {
+ const updatedTags = archivalTags?.map(t =>
+ t.label === tag.label ? { ...t, [option]: !t[option] } : t
+ );
+
+ setArchivalTags(updatedTags);
+ };
+
const handleDeleteTag = (tagToDelete: ArchivalTagOption) => {
const updatedTags = archivalTags?.filter(tag => tag.label !== tagToDelete.label);
setArchivalTags(updatedTags);
}
- console.log(archivalTags);
+ 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 (
<SettingsLayout>
@@ -383,16 +400,12 @@ export default function Preference() {
<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 }) => (
+ {ARCHIVAL_OPTIONS.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] })}>
+ <button
+ onClick={() => handleArchiveOptionChange(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>