diff --git a/apps/web/src/utils/web-extension-server.ts b/apps/web/src/utils/web-extension-server.ts
index 6680f079f..d8380773e 100644
--- a/apps/web/src/utils/web-extension-server.ts
+++ b/apps/web/src/utils/web-extension-server.ts
@@ -118,19 +118,16 @@ export class WebExtensionServer implements Server {
content: { type: "tiptap", data: content }
});
- if (id && clip.tags) {
- for (const id of clip.tags) {
- if (!(await db.tags.exists(id))) continue;
- await db.relations.add({ id: id, type: "tag" }, { id, type: "note" });
- }
- }
-
if (clip.refs && id && !clip.note) {
for (const ref of clip.refs) {
switch (ref.type) {
case "notebook":
+ if (!(await db.notebooks.exists(ref.id))) continue;
await db.notes.addToNotebook(ref.id, id);
break;
+ case "tag":
+ if (!(await db.tags.exists(ref.id))) continue;
+ await db.relations.add(ref, { id, type: "note" });
}
}
}
diff --git a/extensions/web-clipper/src/common/bridge.ts b/extensions/web-clipper/src/common/bridge.ts
index 0f5327e5b..3e081fb62 100644
--- a/extensions/web-clipper/src/common/bridge.ts
+++ b/extensions/web-clipper/src/common/bridge.ts
@@ -44,17 +44,15 @@ export interface Gateway {
connect(): ClientMetadata;
}
-type SelectedTopicReference = ItemReference & {
- type: "topic";
- parentId: string;
-};
-
type SelectedNotebookReference = ItemReference & {
type: "notebook";
};
+type SelectedTagReference = ItemReference & {
+ type: "tag";
+};
export type SelectedReference =
- | SelectedTopicReference
+ | SelectedTagReference
| SelectedNotebookReference;
export type Clip = {
@@ -66,7 +64,6 @@ export type Clip = {
width?: number;
height?: number;
pageTitle?: string;
- tags?: string[];
note?: ItemReference;
refs?: SelectedReference[];
};
diff --git a/extensions/web-clipper/src/components/notebook-picker/index.tsx b/extensions/web-clipper/src/components/notebook-picker/index.tsx
index b52de2003..727a95061 100644
--- a/extensions/web-clipper/src/components/notebook-picker/index.tsx
+++ b/extensions/web-clipper/src/components/notebook-picker/index.tsx
@@ -19,11 +19,7 @@ along with this program. If not, see .
import { useState } from "react";
import { Flex } from "@theme-ui/components";
import { FilteredList } from "../filtered-list";
-import {
- NotebookReference,
- ItemReference,
- SelectedReference
-} from "../../common/bridge";
+import { NotebookReference, SelectedReference } from "../../common/bridge";
import { Icons } from "../icons";
import { useAppStore } from "../../stores/app-store";
import { Picker } from "../picker";
@@ -66,7 +62,7 @@ export const NotebookPicker = (props: NotebookPickerProps) => {
setSelectedItems((items) => {
const copy = items.slice();
@@ -105,14 +101,6 @@ export const NotebookPicker = (props: NotebookPickerProps) => {
renderItem={(item) => (
- !!selectedItems.find(
- (n) =>
- n.id === topic.id &&
- n.type === "topic" &&
- n.parentId === item.id
- )
- }
isSelected={
!!selectedItems.find(
(n) => n.id === item.id && n.type === "notebook"
@@ -144,10 +132,9 @@ type NotebookProps = {
notebook: NotebookReference;
isSelected: boolean;
onSelected: (notebook: SelectedReference) => void;
- isTopicSelected: (topic: ItemReference) => boolean;
};
function Notebook(props: NotebookProps) {
- const { notebook, isSelected, onSelected, isTopicSelected } = props;
+ const { notebook, isSelected, onSelected } = props;
return (
void;
+ selectedTags: SelectedReference[];
+ onSelected: (tags: SelectedReference[]) => void;
};
export const TagPicker = (props: TagPickerProps) => {
- const { onSelected } = props;
+ const { selectedTags, onSelected } = props;
const [modalVisible, setModalVisible] = useState(false);
- const [selectedTags, setSelectedTags] = useState(
- props.selectedTags || []
- );
const close = () => {
setModalVisible(false);
};
const open = () => {
- setSelectedTags(props.selectedTags || []);
setModalVisible(true);
};
@@ -57,20 +54,20 @@ export const TagPicker = (props: TagPickerProps) => {
gap: 1
}}
>
- {props.selectedTags.length
- ? props.selectedTags.map((tag) => (
+ {selectedTags.length
+ ? selectedTags.map((tag) => (
{
- setSelectedTags((items) => {
- const copy = items.slice();
- const index = copy.indexOf(tag);
- if (index > -1) copy.splice(index, 1);
- onSelected(copy);
- return copy;
- });
+ const copy = selectedTags.slice();
+ const index = copy.findIndex(
+ (c) => c.type === "tag" && c.id === tag.id
+ );
+ if (index <= -1) return;
+ copy.splice(index, 1);
+ onSelected(copy);
}}
/>
))
@@ -102,18 +99,19 @@ export const TagPicker = (props: TagPickerProps) => {
{
- setSelectedTags((items) => {
- const copy = items.slice();
- const index = copy.indexOf(tag.title);
- if (index > -1) {
- copy.splice(index, 1);
- } else {
- copy.push(tag.title);
- }
- return copy;
- });
+ const copy = selectedTags.slice();
+ const index = copy.findIndex(
+ (c) => c.type === "tag" && c.id === tag.id
+ );
+ if (index <= -1) copy.push({ ...tag, type: "tag" });
+ else copy.splice(index, 1);
+ onSelected(copy);
}}
- isSelected={selectedTags.indexOf(tag.title) > -1}
+ isSelected={
+ selectedTags.findIndex(
+ (s) => s.type === "tag" && s.id === tag.id
+ ) > -1
+ }
/>
)}
/>
diff --git a/extensions/web-clipper/src/views/main.tsx b/extensions/web-clipper/src/views/main.tsx
index a7ad01e4b..c69b53be2 100644
--- a/extensions/web-clipper/src/views/main.tsx
+++ b/extensions/web-clipper/src/views/main.tsx
@@ -110,7 +110,6 @@ export function Main() {
const [isClipping, setIsClipping] = useState(false);
const [note, setNote] = usePersistentState("note");
const [refs, setRefs] = usePersistentState("refs", []);
- const [tags, setTags] = usePersistentState("tags", []);
const [clipData, setClipData] = useState();
const pageTitle = useRef();
@@ -374,7 +373,7 @@ export function Main() {
Organization
- {refs?.length || tags?.length ? null : (
+ {refs?.length ? null : (
setNote(note)}
@@ -382,19 +381,19 @@ export function Main() {
)}
{note ? null : (
<>
- {refs?.length || tags?.length ? null : (
+ {refs?.length ? null : (
— or —
)}
r.type === "notebook") || []}
onSelected={(items) => setRefs(items)}
/>
setTags(tags)}
+ selectedTags={refs?.filter((r) => r.type === "tag") || []}
+ onSelected={(tags) => setRefs(tags)}
/>
>
)}
@@ -415,7 +414,6 @@ export function Main() {
title,
area: clipArea,
mode: clipMode,
- tags,
note,
refs,
pageTitle: pageTitle.current,