A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
clipper: add support for assigning multiple notebooks
Abdullah Atta878c901e064a
diff --git a/apps/web/src/utils/web-extension-server.ts b/apps/web/src/utils/web-extension-server.tsindex 960b64496..a6f5823a1 100644--- a/apps/web/src/utils/web-extension-server.ts+++ b/apps/web/src/utils/web-extension-server.ts@@ -94,9 +94,8 @@ export class WebExtensionServer implements Server {}).outerHTML;}- const note =- (clip.note?.id && db.notes?.note(clip.note?.id)) ||- db.notes?.note(await db.notes?.add({ title: clip.title }));+ const note = clip.note?.id ? db.notes?.note(clip.note?.id) : null;+let content = (await note?.content()) || "";content += clipContent;content += h("div", [@@ -105,20 +104,26 @@ export class WebExtensionServer implements Server {h("p", [`Date clipped: ${formatDate(Date.now())}`])]).innerHTML;- await db.notes?.add({+ const id = await db.notes?.add({id: note?.id,- content: { type: "tiptap", data: content }+ title: note ? note.title : clip.title,+ content: { type: "tiptap", data: content },+ tags: note ? note.tags : clip.tags});- if (clip.notebook && note) {- await db.notes?.addToNotebook(- { id: clip.notebook.id, topic: clip.notebook.topic.id },- note.id- );- }- if (clip.tags && note) {- for (const tag of clip.tags) {- await db.tags?.add(tag, note.id);+ if (clip.refs && id && !clip.note) {+ for (const ref of clip.refs) {+ switch (ref.type) {+ case "notebook":+ await db.notes?.addToNotebook({ id: ref.id }, id);+ break;+ case "topic":+ await db.notes?.addToNotebook(+ { id: ref.parentId, topic: ref.id },+ id+ );+ break;+ }}}await appstore.refresh();diff --git a/extensions/web-clipper/src/common/bridge.ts b/extensions/web-clipper/src/common/bridge.tsindex 1ff0c5537..abef17f98 100644--- a/extensions/web-clipper/src/common/bridge.ts+++ b/extensions/web-clipper/src/common/bridge.ts@@ -45,7 +45,18 @@ export interface Gateway {connect(): ClientMetadata;}-export type SelectedNotebook = ItemReference & { topic: ItemReference };+type SelectedTopicReference = ItemReference & {+ type: "topic";+ parentId: string;+};++type SelectedNotebookReference = ItemReference & {+ type: "notebook";+};++export type SelectedReference =+ | SelectedTopicReference+ | SelectedNotebookReference;export type Clip = {url: string;@@ -58,7 +69,7 @@ export type Clip = {pageTitle?: string;tags?: string[];note?: ItemReference;- notebook?: SelectedNotebook;+ refs?: SelectedReference[];};export interface Server {diff --git a/extensions/web-clipper/src/components/check-list-item/index.tsx b/extensions/web-clipper/src/components/check-list-item/index.tsxnew file mode 100644index 000000000..28b46375b--- /dev/null+++ b/extensions/web-clipper/src/components/check-list-item/index.tsx@@ -0,0 +1,62 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { Button, Text } from "@theme-ui/components";+import { Icon } from "../icons/icon";+import { Icons } from "../icons";++type CheckListItemProps = {+ title: string;+ isSelected: boolean;+ onSelected: () => void;+ indentLevel?: number;+};++export function CheckListItem(props: CheckListItemProps) {+ const { title, onSelected, isSelected, indentLevel = 0 } = props;+ return (+ <Button+ variant="list"+ onClick={onSelected}+ sx={{+ display: "flex",+ alignItems: "center",+ py: 1,+ px: 1,+ ml: indentLevel * 2+ }}+ >+ <Icon+ path={isSelected ? Icons.checkCircle : Icons.circle}+ color={isSelected ? "primary" : "text"}+ size={16}+ />+ <Text+ sx={{+ fontSize: "13px",+ ml: 1,+ fontWeight: 400,+ color: "text"+ }}+ >+ {title}+ </Text>+ </Button>+ );+}diff --git a/extensions/web-clipper/src/components/filtered-list/index.tsx b/extensions/web-clipper/src/components/filtered-list/index.tsxindex afbdd268f..3da83b893 100644--- a/extensions/web-clipper/src/components/filtered-list/index.tsx+++ b/extensions/web-clipper/src/components/filtered-list/index.tsx@@ -25,7 +25,7 @@ import { FlexScrollContainer } from "../scroll-container";type FilteredListT<T> = {placeholder: string;getAll: () => Array<T>;- filter: (items: T[], query: string) => T[];+ filter?: (items: T[], query: string) => T[];onCreateNewItem?: (title: string) => void;renderItem: (item: T, index: number) => JSX.Element;itemName: string;@@ -57,6 +57,7 @@ export function FilteredList<T>({const _filter = useCallback((query) => {+ if (!filter) return;setItems(() => {const items = getAll();if (!query) {@@ -83,27 +84,32 @@ export function FilteredList<T>({return (<>- <Input- sx={{- mt: 1,- mb: 1,- mr: 1,- fontSize: "body",- py: "7px",- color: "text"- }}- ref={inputRef}- autoFocus- placeholder={items.length <= 0 ? `Add a ${itemName}` : placeholder}- onChange={(e) => {- _filter(e.target.value);- }}- onKeyUp={async (e) => {- if (e.key === "Enter" && noItemsFound) {- _createNewItem(query);+ {(onCreateNewItem || filter) && (+ <Input+ sx={{+ m: 1,+ width: "auto",+ fontSize: "body",+ py: "7px",+ color: "text"+ }}+ ref={inputRef}+ autoFocus+ placeholder={+ items.length <= 0 && onCreateNewItem+ ? `Add a ${itemName}`+ : placeholder}- }}- />+ onChange={(e) => {+ _filter(e.target.value);+ }}+ onKeyUp={async (e) => {+ if (e.key === "Enter" && noItemsFound && onCreateNewItem) {+ _createNewItem(query);+ }+ }}+ />+ )}<FlexScrollContainer><Flexdiff --git a/extensions/web-clipper/src/components/icons/index.ts b/extensions/web-clipper/src/components/icons/index.tsindex 127673b0f..ee1f97e76 100644--- a/extensions/web-clipper/src/components/icons/index.ts+++ b/extensions/web-clipper/src/components/icons/index.ts@@ -38,7 +38,12 @@ import {mdiMagnify,mdiViewDayOutline,mdiViewDashboardOutline,- mdiArrowLeft+ mdiArrowLeft,+ mdiCheckCircleOutline,+ mdiCircleOutline,+ mdiBookOutline,+ mdiBookmarkOutline,+ mdiPound} from "@mdi/js";export const Icons = {@@ -67,6 +72,12 @@ export const Icons = {chevronUp: mdiChevronUp,chevronRight: mdiChevronRight,+ checkCircle: mdiCheckCircleOutline,+ circle: mdiCircleOutline,+ notebook: mdiBookOutline,+ topic: mdiBookmarkOutline,+ tag: mdiPound,+none: "",back: mdiArrowLeft};diff --git a/extensions/web-clipper/src/components/inline-tag/index.tsx b/extensions/web-clipper/src/components/inline-tag/index.tsxnew file mode 100644index 000000000..69c6f72bc--- /dev/null+++ b/extensions/web-clipper/src/components/inline-tag/index.tsx@@ -0,0 +1,55 @@+/*+This file is part of the Notesnook project (https://notesnook.com/)++Copyright (C) 2023 Streetwriters (Private) Limited++This program is free software: you can redistribute it and/or modify+it under the terms of the GNU General Public License as published by+the Free Software Foundation, either version 3 of the License, or+(at your option) any later version.++This program is distributed in the hope that it will be useful,+but WITHOUT ANY WARRANTY; without even the implied warranty of+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+GNU General Public License for more details.++You should have received a copy of the GNU General Public License+along with this program. If not, see <http://www.gnu.org/licenses/>.+*/++import { Flex, Text } from "@theme-ui/components";+import { Icon } from "../icons/icon";+import { SchemeColors } from "@notesnook/theme/dist/theme/colorscheme";++export function InlineTag(props: {+ title: string;+ icon: string;+ iconColor?: keyof SchemeColors;+ onClick: () => void;+}) {+ const { title, icon, onClick, iconColor = "icon" } = props;++ return (+ <Flex+ onClick={onClick}+ sx={{+ alignItems: "center",+ justifyContent: "center",+ bg: "bgSecondary",+ border: "1px solid var(--border)",+ borderRadius: "small",+ p: "3px",+ pr: 1,+ cursor: "pointer",+ ":hover": {+ bg: "hover"+ }+ }}+ >+ <Icon path={icon} color={iconColor} size={16} />+ <Text variant="subBody" sx={{ color: "icon", ml: 1 }}>+ {title}+ </Text>+ </Flex>+ );+}diff --git a/extensions/web-clipper/src/components/note-picker/index.tsx b/extensions/web-clipper/src/components/note-picker/index.tsxindex 5ca4e4d8f..435eb1ed1 100644--- a/extensions/web-clipper/src/components/note-picker/index.tsx+++ b/extensions/web-clipper/src/components/note-picker/index.tsx@@ -24,6 +24,7 @@ import { Icon } from "../icons/icon";import { Icons } from "../icons";import { useAppStore } from "../../stores/app-store";import { Picker } from "../picker";+import { CheckListItem } from "../check-list-item";type NotePickerProps = {selectedNote?: ItemReference;@@ -95,7 +96,7 @@ export const NotePicker = (props: NotePickerProps) => {)}</Flex>- <Picker onClose={close} isOpen={modalVisible}>+ <Picker onClose={close} onDone={() => {}} isOpen={modalVisible}><FilteredListgetAll={() => notes}filter={(items, query) =>@@ -105,12 +106,13 @@ export const NotePicker = (props: NotePickerProps) => {placeholder={"Search for a note"}refreshItems={() => notes}renderItem={(note) => (- <Note- note={note}+ <CheckListItem+ title={note.title}onSelected={() => {onSelected(note);close();}}+ isSelected={selectedNote?.id === note.id}/>)}/>@@ -118,17 +120,3 @@ export const NotePicker = (props: NotePickerProps) => {</>);};--function Note({- note,- onSelected-}: {- note: ItemReference;- onSelected: () => void;-}) {- return (- <Button onClick={onSelected} variant="list" sx={{ py: "7px" }}>- <Text variant="body">{note.title}</Text>- </Button>- );-}diff --git a/extensions/web-clipper/src/components/notebook-picker/index.tsx b/extensions/web-clipper/src/components/notebook-picker/index.tsxindex 34c8f2460..3014bf4e3 100644--- a/extensions/web-clipper/src/components/notebook-picker/index.tsx+++ b/extensions/web-clipper/src/components/notebook-picker/index.tsx@@ -17,100 +17,120 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/import { useState } from "react";-import { Button, Flex, Text } from "@theme-ui/components";+import { Flex } from "@theme-ui/components";import { FilteredList } from "../filtered-list";import {NotebookReference,ItemReference,- SelectedNotebook+ SelectedReference} from "../../common/bridge";-import { Icon } from "../icons/icon";import { Icons } from "../icons";import { useAppStore } from "../../stores/app-store";import { Picker } from "../picker";+import { InlineTag } from "../inline-tag";+import { CheckListItem } from "../check-list-item";type NotebookPickerProps = {- selectedNotebook?: SelectedNotebook;- onSelected: (notebook?: SelectedNotebook) => void;+ selectedItems: SelectedReference[];+ onSelected: (items?: SelectedReference[]) => void;};export const NotebookPicker = (props: NotebookPickerProps) => {- const { selectedNotebook, onSelected } = props;+ const { onSelected } = props;const [modalVisible, setModalVisible] = useState(false);- const [expanded, setExpanded] = useState<string | null>(null);- const notebooks = useAppStore((s) => s.notebooks);+ const [selectedItems, setSelectedItems] = useState<SelectedReference[]>(+ props.selectedItems+ );const close = () => {- setExpanded(null);setModalVisible(false);};- const open = () => setModalVisible(true);+ const open = () => {+ setSelectedItems(props.selectedItems);+ setModalVisible(true);+ };return (<>- <Flex sx={{ alignItems: "center" }}>- <Button- variant="tool"+ <Flex+ sx={{+ border: "1px solid var(--border)",+ p: 1,+ gap: 1,+ borderRadius: "default",+ flexWrap: "wrap"+ }}+ >+ {props.selectedItems && props.selectedItems.length+ ? props.selectedItems.map((item) => (+ <InlineTag+ key={item.id}+ title={item.title}+ icon={item.type === "topic" ? Icons.topic : Icons.notebook}+ onClick={() =>+ setSelectedItems((items) => {+ const copy = items.slice();+ const index = copy.indexOf(item);+ if (index > -1) copy.splice(index, 1);+ onSelected(copy);+ return copy;+ })+ }+ />+ ))+ : null}+ <InlineTag+ title={selectedItems.length ? "Add more" : "Add to notebook"}+ icon={Icons.plus}+ iconColor="primary"onClick={open}- sx={{- display: "flex",- justifyContent: "space-between",- alignItems: "center",- flex: 1,- borderTopRightRadius: 0,- borderBottomRightRadius: 0,- height: 33- }}- title={- selectedNotebook- ? `${selectedNotebook.title} > ${selectedNotebook.topic.title}`- : `Select a notebook`- }- >- <Text variant="text">- {selectedNotebook- ? `${selectedNotebook.title} > ${selectedNotebook.topic.title}`- : `Select a notebook`}- </Text>- <Icon path={Icons.chevronDown} color="text" size={18} />- </Button>- {selectedNotebook && (- <Button- variant="tool"- onClick={() => onSelected(undefined)}- sx={{- display: "flex",- justifyContent: "space-between",- alignItems: "center",- flexShrink: 0,- borderTopLeftRadius: 0,- borderBottomLeftRadius: 0,- height: 33- }}- title={"Clear selection"}- >- <Icon path={Icons.close} color="text" size={16} />- </Button>- )}+ /></Flex>-- <Picker onClose={close} isOpen={modalVisible}>+ <Picker+ onClose={close}+ onDone={() => {+ onSelected(selectedItems);+ close();+ }}+ isOpen={modalVisible}+ ><FilteredList- getAll={() => notebooks}+ getAll={() => useAppStore.getState().notebooks}filter={(items, query) =>items.filter((item) => item.title.toLowerCase().indexOf(query) > -1)}itemName="notebook"placeholder={"Search for a notebook"}- refreshItems={() => notebooks}+ refreshItems={() => useAppStore.getState().notebooks}renderItem={(item) => (<Notebooknotebook={item}- isExpanded={expanded === item.id}- onExpand={(id) => setExpanded(id || null)}- onSelected={(notebook) => {- onSelected(notebook);- close();+ isTopicSelected={(topic) =>+ !!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"+ )+ }+ onSelected={(ref) => {+ setSelectedItems((items) => {+ const copy = items.slice();+ const index = copy.findIndex(+ (n) => n.id === ref.id && n.type === ref.type+ );+ if (index > -1) {+ copy.splice(index, 1);+ } else {+ copy.push(ref);+ }+ return copy;+ });}}/>)}@@ -122,12 +142,12 @@ export const NotebookPicker = (props: NotebookPickerProps) => {type NotebookProps = {notebook: NotebookReference;- isExpanded: boolean;- onExpand: (notebookId?: string) => void;- onSelected: (notebook: SelectedNotebook) => void;+ isSelected: boolean;+ onSelected: (notebook: SelectedReference) => void;+ isTopicSelected: (topic: ItemReference) => boolean;};function Notebook(props: NotebookProps) {- const { notebook, isExpanded, onExpand, onSelected } = props;+ const { notebook, isSelected, onSelected, isTopicSelected } = props;return (<Flex@@ -136,69 +156,39 @@ function Notebook(props: NotebookProps) {overflow: "hidden"}}>- <Button- variant="list"- onClick={() => {- if (isExpanded) return onExpand();- onExpand(notebook.id);+ <CheckListItem+ title={notebook.title}+ isSelected={isSelected}+ onSelected={() => {+ onSelected({+ id: notebook.id,+ title: notebook.title,+ type: "notebook"+ });}}- sx={{- display: "flex",- justifyContent: "space-between",- alignItems: "center",- backgroundColor: isExpanded ? "border" : "transparent",- py: "7px",- px: 1- }}- >- <Text- sx={{- fontSize: "13px",- fontWeight: 400,- color: "var(--paragraph)"- }}- >- {notebook.title}- </Text>- <Icon- path={isExpanded ? Icons.chevronUp : Icons.chevronDown}- color="text"- size={18}- />- </Button>+ />- {isExpanded ? (- <FilteredList- getAll={() => notebook.topics}- filter={(items, query) =>- items.filter((item) => item.title.toLowerCase().indexOf(query) > -1)- }- itemName="topic"- placeholder={"Search for a topic"}- refreshItems={() => notebook.topics}- renderItem={(topic) => (- <Topic- topic={topic}- onSelected={() => {- onSelected({ id: notebook.id, title: notebook.title, topic });- }}- />- )}- />- ) : null}+ <FilteredList+ getAll={() => notebook.topics}+ itemName="topic"+ placeholder={"Search for a topic"}+ refreshItems={() => notebook.topics}+ renderItem={(topic) => (+ <CheckListItem+ title={topic.title}+ isSelected={isTopicSelected(topic)}+ indentLevel={1}+ onSelected={() => {+ onSelected({+ id: topic.id,+ title: topic.title,+ type: "topic",+ parentId: notebook.id+ });+ }}+ />+ )}+ /></Flex>);}--type TopicProps = {- topic: ItemReference;- onSelected: () => void;-};-function Topic(props: TopicProps) {- const { topic, onSelected } = props;- return (- <Button variant="list" onClick={onSelected} sx={{ pl: 3, py: "7px" }}>- <Text variant="text">{topic.title}</Text>- </Button>- );-}diff --git a/extensions/web-clipper/src/components/picker/index.tsx b/extensions/web-clipper/src/components/picker/index.tsxindex a635f2fcb..62bd414b2 100644--- a/extensions/web-clipper/src/components/picker/index.tsx+++ b/extensions/web-clipper/src/components/picker/index.tsx@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.*/import { PropsWithChildren } from "react";import Modal from "react-modal";-import { Flex } from "@theme-ui/components";+import { Button, Flex } from "@theme-ui/components";import { ThemeProvider } from "../theme-provider";Modal.setAppElement("#root");@@ -30,26 +30,27 @@ const customStyles = {bottom: "auto",marginRight: "-50%",transform: "translate(-50%, -50%)",- boxShadow: "0px 1px 10px var(--info)",+ boxShadow: "0px 1px 10px #00000055",border: "none",borderRadius: 5,backgroundColor: "var(--background)",- padding: "10px",height: "80vh",width: "85vw",display: "flex",flexDirection: "column",- overflow: "hidden"+ overflow: "hidden",+ padding: 0} as const};type PickerProps = {isOpen: boolean;onClose: () => void;+ onDone: () => void;};export const Picker = (props: PropsWithChildren<PickerProps>) => {- const { children, isOpen, onClose } = props;+ const { children, isOpen, onClose, onDone } = props;return (<Modal@@ -66,10 +67,25 @@ export const Picker = (props: PropsWithChildren<PickerProps>) => {<Flexsx={{flexDirection: "column",- overflow: "hidden"+ overflow: "hidden",+ height: "100%"}}>- {children}+ <Flex+ sx={{+ flexDirection: "column",+ overflow: "hidden",+ flex: 1,+ padding: 2+ }}+ >+ {children}+ </Flex>+ <Flex sx={{ bg: "bgSecondary", p: 1, justifyContent: "end" }}>+ <Button variant="dialog" onClick={onDone}>+ Done+ </Button>+ </Flex></Flex></ThemeProvider></Modal>diff --git a/extensions/web-clipper/src/components/tag-picker/index.tsx b/extensions/web-clipper/src/components/tag-picker/index.tsxindex e8216c38c..94f0b177c 100644--- a/extensions/web-clipper/src/components/tag-picker/index.tsx+++ b/extensions/web-clipper/src/components/tag-picker/index.tsx@@ -17,29 +17,34 @@ You should have received a copy of the GNU General Public Licensealong with this program. If not, see <http://www.gnu.org/licenses/>.*/import { useState } from "react";-import { Button, Flex, Text } from "@theme-ui/components";+import { Flex } from "@theme-ui/components";import { FilteredList } from "../filtered-list";-import { ItemReference } from "../../common/bridge";-import { Icon } from "../icons/icon";import { Icons } from "../icons";import { useAppStore } from "../../stores/app-store";import { Picker } from "../picker";+import { InlineTag } from "../inline-tag";+import { CheckListItem } from "../check-list-item";type TagPickerProps = {selectedTags: string[];- onSelected: (tag: string) => void;- onDeselected: (tag: string) => void;+ onSelected: (tags: string[]) => void;};export const TagPicker = (props: TagPickerProps) => {- const { selectedTags, onSelected, onDeselected } = props;+ const { onSelected } = props;const [modalVisible, setModalVisible] = useState(false);- const tags = useAppStore((s) => s.tags);+ const [selectedTags, setSelectedTags] = useState<string[]>(+ props.selectedTags || []+ );const close = () => {setModalVisible(false);};- const open = () => setModalVisible(true);++ const open = () => {+ setSelectedTags(props.selectedTags || []);+ setModalVisible(true);+ };return (<>@@ -47,59 +52,66 @@ export const TagPicker = (props: TagPickerProps) => {sx={{border: "2px solid var(--border)",p: 1,- pb: 0,borderRadius: "default",- flexWrap: "wrap"+ flexWrap: "wrap",+ gap: 1}}>- {selectedTags.length- ? selectedTags.map((tag) => (+ {props.selectedTags.length+ ? props.selectedTags.map((tag) => (<InlineTagkey={tag}- tag={tag}- onDeselected={() => {- onDeselected(tag);+ icon={Icons.tag}+ title={tag}+ onClick={() => {+ setSelectedTags((items) => {+ const copy = items.slice();+ const index = copy.indexOf(tag);+ if (index > -1) copy.splice(index, 1);+ onSelected(copy);+ return copy;+ });}}/>)): null}- <Flex+ <InlineTag+ icon={Icons.plus}+ title={"Assign a tag"}+ iconColor="primary"onClick={open}- sx={{- bg: "bgSecondary",- border: "1px solid var(--border)",- borderRadius: "small",- mr: 1,- px: 1,- mb: 1,- cursor: "pointer",- ":hover": {- bg: "hover"- }- }}- title="Click to assign more tags"- >- <Icon path={Icons.plus} size={12} color="fontTertiary" />- <Text variant="subBody" sx={{ ml: "2px", color: "icon" }}>- Assign a tag- </Text>- </Flex>+ /></Flex>- <Picker onClose={close} isOpen={modalVisible}>+ <Picker+ onClose={close}+ onDone={() => {+ onSelected(selectedTags);+ close();+ }}+ isOpen={modalVisible}+ ><FilteredList- getAll={() => tags}+ getAll={() => useAppStore.getState().tags}filter={(items, query) =>items.filter((item) => item.title.toLowerCase().indexOf(query) > -1)}itemName="tag"placeholder={"Search for a tag"}- onCreateNewItem={(tag) => onSelected(tag)}- refreshItems={() => tags}+ refreshItems={() => useAppStore.getState().tags}renderItem={(tag) => (- <Tag- tag={tag}+ <CheckListItem+ title={`#${tag.title}`}onSelected={() => {- onSelected(tag.title);+ 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;+ });}}isSelected={selectedTags.indexOf(tag.title) > -1}/>@@ -109,64 +121,3 @@ export const TagPicker = (props: TagPickerProps) => {</>);};--type TagProps = {- tag: ItemReference;- isSelected: boolean;- onSelected: () => void;-};-function Tag(props: TagProps) {- const { tag, onSelected, isSelected } = props;-- return (- <Button- variant="list"- onClick={onSelected}- sx={{- display: "flex",- justifyContent: "space-between",- alignItems: "center",- py: "7px",- px: 1- }}- >- <Text- sx={{- fontSize: "13px",- fontWeight: 400,- color: "var(--paragraph)"- }}- >- #{tag.title}- </Text>- {isSelected ? <Icon path={Icons.check} color="text" size={14} /> : null}- </Button>- );-}--function InlineTag(props: { tag: string; onDeselected: () => void }) {- const { tag, onDeselected } = props;-- return (- <Flex- onClick={onDeselected}- sx={{- bg: "bgSecondary",- border: "1px solid var(--border)",- borderRadius: "small",- mr: 1,- px: 1,- mb: 1,- cursor: "pointer",- ":hover": {- bg: "hover"- }- }}- title="Click to remove"- >- <Text variant="subBody" sx={{ color: "icon" }}>- #{tag}- </Text>- </Flex>- );-}diff --git a/extensions/web-clipper/src/views/main.tsx b/extensions/web-clipper/src/views/main.tsxindex 560872b1e..9920d0ddb 100644--- a/extensions/web-clipper/src/views/main.tsx+++ b/extensions/web-clipper/src/views/main.tsx@@ -26,7 +26,7 @@ import { NotebookPicker } from "../components/notebook-picker";import { TagPicker } from "../components/tag-picker";import {ItemReference,- SelectedNotebook,+ SelectedReference,ClipArea,ClipMode,ClipData@@ -104,8 +104,7 @@ export function Main() {);const [isClipping, setIsClipping] = useState(false);const [note, setNote] = usePersistentState<ItemReference>("note");- const [notebook, setNotebook] =- usePersistentState<SelectedNotebook>("notebook");+ const [refs, setRefs] = usePersistentState<SelectedReference[]>("refs", []);const [tags, setTags] = usePersistentState<string[]>("tags", []);const [clipData, setClipData] = useState<ClipData>();const pageTitle = useRef<string>();@@ -307,7 +306,7 @@ export function Main() {Organization</Text>- {notebook || tags?.length ? null : (+ {refs?.length || tags?.length ? null : (<NotePickerselectedNote={note}onSelected={(note) => setNote(note)}@@ -315,34 +314,19 @@ export function Main() {)}{note ? null : (<>- {notebook || tags?.length ? null : (+ {refs?.length || tags?.length ? null : (<Text variant="subBody" sx={{ my: 1, textAlign: "center" }}>— or —</Text>)}<NotebookPicker- selectedNotebook={notebook}- onSelected={(notebook) => setNotebook(notebook)}+ selectedItems={refs || []}+ onSelected={(items) => setRefs(items)}/><Box sx={{ mt: 1 }} /><TagPickerselectedTags={tags || []}- onDeselected={(tag) => {- setTags((tags) => {- const copy = tags?.slice() || [];- copy.splice(copy.indexOf(tag), 1);- return copy;- });- }}- onSelected={(tag) => {- setTags((tags) => {- const copy = tags?.slice() || [];- if (copy.indexOf(tag) > -1) {- copy.splice(copy.indexOf(tag), 1);- } else copy.push(tag);- return copy;- });- }}+ onSelected={(tags) => setTags(tags)}/></>)}@@ -364,12 +348,21 @@ export function Main() {mode: clipMode,tags,note,- notebook,+ refs,pageTitle: pageTitle.current,...clipData});setClipData(undefined);++ await browser.notifications?.create({+ title: "Clip saved!",+ message: "Open the Notesnook app to view the result.",+ type: "basic",+ iconUrl: browser.runtime.getURL("256x256.png"),+ isClickable: false+ });+window.close();}}>