Skip to content

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

use existing TagSelection

Isaac794f8f07fa8f
diff --git a/components/InputSelect/ArchivalTagSelection.tsx b/components/InputSelect/ArchivalTagSelection.tsx
deleted file mode 100644
index 75b991de..00000000
--- a/components/InputSelect/ArchivalTagSelection.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import CreatableSelect from "react-select/creatable";
-import { styles } from "./styles";
-import { useTranslation } from "next-i18next";
-import { ArchivalTagOption } from "./types";
-
-type Props = {
- options: ArchivalTagOption[] | [];
- onChange: (e: any) => void;
-};
-
-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
- />
- );
-}
diff --git a/components/InputSelect/TagSelection.tsx b/components/InputSelect/TagSelection.tsx
index 8ce0edb0..15af6877 100644
--- a/components/InputSelect/TagSelection.tsx
+++ b/components/InputSelect/TagSelection.tsx
@@ -1,12 +1,14 @@
import { useEffect, useState } from "react";
import CreatableSelect from "react-select/creatable";
import { styles } from "./styles";
-import { Option } from "./types";
+import { ArchivalTagOption, Option } from "./types";
import { useTags } from "@/hooks/store/tags";
import { useTranslation } from "next-i18next";
type Props = {
- onChange: any;
+ onChange: (e: any) => void;
+ options?: Option[] | ArchivalTagOption[];
+ isArchivalTagSelection?: boolean;
defaultValue?: {
value?: number;
label: string;
@@ -17,36 +19,57 @@ type Props = {
export default function TagSelection({
onChange,
+ options,
+ isArchivalTagSelection,
defaultValue,
autoFocus,
onBlur,
}: Props) {
- const { data: tags = [] } = useTags();
const { t } = useTranslation();
- const [options, setOptions] = useState<Option[]>([]);
+ if (isArchivalTagSelection && options) {
+ return (
+ <CreatableSelect
+ isClearable={false}
+ className="react-select-container"
+ classNamePrefix="react-select"
+ onChange={onChange}
+ options={options}
+ styles={styles}
+ value={[]}
+ defaultValue={defaultValue}
+ placeholder={t("tag_selection_placeholder")}
+ isMulti
+ autoFocus={autoFocus}
+ onBlur={onBlur}
+ />
+ );
+ } else {
+ const { data: tags = [] } = useTags();
+ const [options, setOptions] = useState<Option[]>([]);
- useEffect(() => {
- const formatedCollections = tags.map((e: any) => {
- return { value: e.id, label: e.name };
- });
+ useEffect(() => {
+ const formatedCollections = tags.map((e: any) => {
+ return { value: e.id, label: e.name };
+ });
- setOptions(formatedCollections);
- }, [tags]);
+ setOptions(formatedCollections);
+ }, [tags]);
- return (
- <CreatableSelect
- isClearable={false}
- className="react-select-container"
- classNamePrefix="react-select"
- onChange={onChange}
- options={options}
- styles={styles}
- defaultValue={defaultValue}
- placeholder={t("tag_selection_placeholder")}
- isMulti
- autoFocus={autoFocus}
- onBlur={onBlur}
- />
- );
+ return (
+ <CreatableSelect
+ isClearable={false}
+ className="react-select-container"
+ classNamePrefix="react-select"
+ onChange={onChange}
+ options={options}
+ styles={styles}
+ defaultValue={defaultValue}
+ placeholder={t("tag_selection_placeholder")}
+ isMulti
+ autoFocus={autoFocus}
+ onBlur={onBlur}
+ />
+ );
+ }
}
diff --git a/pages/settings/preference.tsx b/pages/settings/preference.tsx
index 2f23f680..7e245d5c 100644
--- a/pages/settings/preference.tsx
+++ b/pages/settings/preference.tsx
@@ -8,7 +8,6 @@ import { useTranslation } from "next-i18next";
import getServerSideProps from "@/lib/client/getServerSideProps";
import { AiTaggingMethod, LinksRouteTo } from "@prisma/client";
import { useUpdateUser, useUser } from "@/hooks/store/user";
-import ArchivalTagSelection from "@/components/InputSelect/ArchivalTagSelection";
import { useConfig } from "@/hooks/store/config";
import { useTags, useUpdateArchivalTags } from "@/hooks/store/tags";
import { cn } from "@/lib/client/utils";
@@ -153,7 +152,7 @@ export default function Preference() {
newTag.archiveAsPDF !== originalTag.archiveAsPDF ||
newTag.archiveAsReadable !== originalTag.archiveAsReadable ||
newTag.archiveAsWaybackMachine !==
- originalTag.archiveAsWaybackMachine ||
+ originalTag.archiveAsWaybackMachine ||
newTag.aiTag !== originalTag.aiTag
);
});
@@ -212,11 +211,10 @@ export default function Preference() {
].map(({ theme, icon, bgColor, textColor, activeColor }) => (
<div
key={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>
@@ -357,9 +355,8 @@ export default function Preference() {
</div>
</div>
<div
- className={`mb-3 ${
- aiTaggingMethod === AiTaggingMethod.DISABLED ? "opacity-50" : ""
- }`}
+ className={`mb-3 ${aiTaggingMethod === AiTaggingMethod.DISABLED ? "opacity-50" : ""
+ }`}
>
<Checkbox
label={t("generate_tags_for_existing_links")}
@@ -444,7 +441,7 @@ export default function Preference() {
</div>
</div>
<div className="p-3">
- <ArchivalTagSelection onChange={addTags} options={options} />
+ <TagSelection isArchivalTagSelection onChange={addTags} options={options} />
<div className="flex flex-col gap-2">
{archivalTags &&
archivalTags.filter(isArchivalTag).map((tag) => (