From d0b24b96452447b4eed49ceaf2ab412065351838 Mon Sep 17 00:00:00 2001 From: Andrii Blacksmith Date: Tue, 21 May 2024 00:32:41 +0300 Subject: [PATCH 1/3] feat(edit-tags): add tags to existing text/tags --- .../components/tags-modal.tsx | 15 ++++++++--- .../edit-description/edit-description.tsx | 25 ++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/app/(pages)/edit/components/edit-description/components/tags-modal.tsx b/app/(pages)/edit/components/edit-description/components/tags-modal.tsx index aef13cab..581a5403 100644 --- a/app/(pages)/edit/components/edit-description/components/tags-modal.tsx +++ b/app/(pages)/edit/components/edit-description/components/tags-modal.tsx @@ -2,7 +2,10 @@ import * as React from 'react'; import { FC } from 'react'; -import { UseFormSetValue } from 'react-hook-form/dist/types/form'; +import { + UseFormGetValues, + UseFormSetValue, +} from 'react-hook-form/dist/types/form'; import MaterialSymbolsAddRounded from '~icons/material-symbols/add-rounded'; import MaterialSymbolsCheckSmallRounded from '~icons/material-symbols/check-small-rounded'; import MaterialSymbolsDeleteForeverRounded from '~icons/material-symbols/delete-forever-rounded'; @@ -15,9 +18,10 @@ import { useSettingsContext } from '@/services/providers/settings-provider'; interface Props { setValue: UseFormSetValue; + getValues: UseFormGetValues; } -const TagsModal: FC = ({ setValue }) => { +const TagsModal: FC = ({ setValue, getValues }) => { const { closeModal } = useModalContext(); const [newTag, setNewTag] = React.useState(''); const { setState: setSettingsState, editTags } = useSettingsContext(); @@ -31,7 +35,12 @@ const TagsModal: FC = ({ setValue }) => { }; const handleSetTag = (tag: string) => { - setValue('description', tag); + setValue( + 'description', + getValues('description') === '' + ? tag + : `${getValues('description')}, ${tag.toLowerCase()}`, + ); closeModal(); }; diff --git a/app/(pages)/edit/components/edit-description/edit-description.tsx b/app/(pages)/edit/components/edit-description/edit-description.tsx index 6c10c501..4c9c9613 100644 --- a/app/(pages)/edit/components/edit-description/edit-description.tsx +++ b/app/(pages)/edit/components/edit-description/edit-description.tsx @@ -17,7 +17,7 @@ interface Props { } const EditDescription: FC = ({ mode }) => { - const { control, setValue } = useFormContext(); + const { control, setValue, getValues } = useFormContext(); const { openModal } = useModalContext(); const { editTags } = useSettingsContext(); @@ -35,7 +35,14 @@ const EditDescription: FC = ({ mode }) => { size="badge" variant="outline" key={tag} - onClick={() => setValue('description', tag)} + onClick={() => + setValue( + 'description', + getValues('description') === '' + ? tag + : `${getValues('description')}, ${tag.toLowerCase()}`, + ) + } > {tag .slice(0, 20) @@ -49,12 +56,24 @@ const EditDescription: FC = ({ mode }) => { onClick={() => openModal({ title: 'Теги редагування', - content: , + content: ( + + ), }) } > Усі теги + From 7bdcb6e41ff5d83d6e61f38879e27653426574b2 Mon Sep 17 00:00:00 2001 From: Andrii Blacksmith Date: Tue, 21 May 2024 00:42:21 +0300 Subject: [PATCH 2/3] add rule for `---` --- .../edit/components/edit-description/edit-description.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/(pages)/edit/components/edit-description/edit-description.tsx b/app/(pages)/edit/components/edit-description/edit-description.tsx index 4c9c9613..1910c5ee 100644 --- a/app/(pages)/edit/components/edit-description/edit-description.tsx +++ b/app/(pages)/edit/components/edit-description/edit-description.tsx @@ -40,7 +40,11 @@ const EditDescription: FC = ({ mode }) => { 'description', getValues('description') === '' ? tag - : `${getValues('description')}, ${tag.toLowerCase()}`, + : getValues('description') + + (tag.split(' ')[0] == '---' + ? ' ' + : ', ') + + tag.toLowerCase(), ) } > From 9930f97d883462e99d5bb1a9ef0029e7f86e596b Mon Sep 17 00:00:00 2001 From: Andrii Blacksmith Date: Tue, 21 May 2024 00:47:29 +0300 Subject: [PATCH 3/3] add rule to modal --- .../components/edit-description/components/tags-modal.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/(pages)/edit/components/edit-description/components/tags-modal.tsx b/app/(pages)/edit/components/edit-description/components/tags-modal.tsx index 581a5403..d66f1a6b 100644 --- a/app/(pages)/edit/components/edit-description/components/tags-modal.tsx +++ b/app/(pages)/edit/components/edit-description/components/tags-modal.tsx @@ -39,7 +39,9 @@ const TagsModal: FC = ({ setValue, getValues }) => { 'description', getValues('description') === '' ? tag - : `${getValues('description')}, ${tag.toLowerCase()}`, + : getValues('description') + + (tag.split(' ')[0] == '---' ? ' ' : ', ') + + tag.toLowerCase(), ); closeModal(); };