From 2ce2b8410f5053f77d02b93dbb80aad5f33c728c Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Mon, 24 Apr 2023 16:33:51 +0530 Subject: [PATCH] feat(clipper): Added default tag setting to clipper --- .../src/Domain/Syncable/UserPrefs/PrefKey.ts | 2 + .../Components/ClipperView/ClipperView.tsx | 82 +++++++++++++++++-- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/packages/models/src/Domain/Syncable/UserPrefs/PrefKey.ts b/packages/models/src/Domain/Syncable/UserPrefs/PrefKey.ts index 307ba4eab..257286d66 100644 --- a/packages/models/src/Domain/Syncable/UserPrefs/PrefKey.ts +++ b/packages/models/src/Domain/Syncable/UserPrefs/PrefKey.ts @@ -42,6 +42,7 @@ export enum PrefKey { DarkMode = 'darkMode', DefaultEditorIdentifier = 'defaultEditorIdentifier', MomentsDefaultTagUuid = 'momentsDefaultTagUuid', + ClipperDefaultTagUuid = 'clipperDefaultTagUuid', SystemViewPreferences = 'systemViewPreferences', SuperNoteExportFormat = 'superNoteExportFormat', AuthenticatorNames = 'authenticatorNames', @@ -111,6 +112,7 @@ export type PrefValue = { [PrefKey.DarkMode]: boolean [PrefKey.DefaultEditorIdentifier]: EditorIdentifier [PrefKey.MomentsDefaultTagUuid]: string | undefined + [PrefKey.ClipperDefaultTagUuid]: string | undefined [PrefKey.SystemViewPreferences]: Partial> [PrefKey.SuperNoteExportFormat]: 'json' | 'md' | 'html' [PrefKey.AuthenticatorNames]: string diff --git a/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx b/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx index 5295b1925..f0a04edbb 100644 --- a/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx +++ b/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx @@ -15,11 +15,14 @@ import { confirmDialog } from '@standardnotes/ui-services' import { ApplicationEvent, ContentType, + DecryptedItem, FeatureIdentifier, FeatureStatus, NoteContent, NoteType, + PrefKey, SNNote, + SNTag, } from '@standardnotes/snjs' import { addToast, ToastType } from '@standardnotes/toast' import { getSuperJSONFromClipPayload } from './getSuperJSONFromClipHTML' @@ -28,6 +31,11 @@ import { PremiumFeatureIconClass, PremiumFeatureIconName } from '../Icon/Premium import Button from '../Button/Button' import { openSubscriptionDashboard } from '@/Utils/ManageSubscription' import { useStateRef } from '@/Hooks/useStateRef' +import usePreference from '@/Hooks/usePreference' +import { createLinkFromItem } from '@/Utils/Items/Search/createLinkFromItem' +import ItemSelectionDropdown from '../ItemSelectionDropdown/ItemSelectionDropdown' +import LinkedItemBubble from '../LinkedItems/LinkedItemBubble' +import StyledTooltip from '../StyledTooltip/StyledTooltip' const Header = () => (
@@ -79,6 +87,30 @@ const ClipperView = ({ }) }, [application]) + const defaultTagId = usePreference(PrefKey.ClipperDefaultTagUuid) + const [defaultTag, setDefaultTag] = useState() + + useEffect(() => { + if (!defaultTagId) { + setDefaultTag(undefined) + return + } + + const tag = application.items.findItem(defaultTagId) as SNTag | undefined + setDefaultTag(tag) + }, [defaultTagId, application]) + + const selectTag = useCallback( + (tag: DecryptedItem) => { + void application.setPreference(PrefKey.ClipperDefaultTagUuid, tag.uuid) + }, + [application], + ) + + const unselectTag = useCallback(async () => { + void application.setPreference(PrefKey.ClipperDefaultTagUuid, undefined) + }, [application]) + const [menuPane, setMenuPane] = useState() const activateRegisterPane = useCallback(() => { @@ -167,18 +199,24 @@ const ClipperView = ({ references: [], }) - void application.items.insertItem(note).then((note) => { - setClippedNote(note as SNNote) - addToast({ - type: ToastType.Success, - message: 'Note clipped successfully', - }) - void application.sync.sync() + const insertedNote = await application.items.insertItem(note) + + if (defaultTag) { + await application.linkingController.linkItems(insertedNote, defaultTag) + } + + setClippedNote(insertedNote as SNNote) + + addToast({ + type: ToastType.Success, + message: 'Note clipped successfully', }) + + void application.sync.sync() } void createNoteFromClip() - }, [application.items, application.sync, clipPayload, isEntitledRef]) + }, [application.items, application.linkingController, application.sync, clipPayload, defaultTag, isEntitledRef]) const upgradePlan = useCallback(async () => { if (hasSubscription) { @@ -309,6 +347,34 @@ const ClipperView = ({ > Select elements to clip +
+
+
Default tag:
+ {defaultTag && ( + + + + )} +
+ {defaultTag && ( +
+ +
+ )} + +
You're signed in as:
{user.email}