-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
148 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
106 changes: 106 additions & 0 deletions
106
app/(pages)/edit/_components/edit-description/_components/tags-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
'use client'; | ||
|
||
import * as React from 'react'; | ||
import { 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'; | ||
|
||
|
||
|
||
import { Button } from '@/components/ui/button'; | ||
import { Input } from '@/components/ui/input'; | ||
import { useModalContext } from '@/services/providers/modal-provider'; | ||
import { useSettingsContext } from '@/services/providers/settings-provider'; | ||
|
||
|
||
interface Props { | ||
setValue: UseFormSetValue<any>; | ||
} | ||
|
||
const Component = ({ setValue }: Props) => { | ||
const { closeModal } = useModalContext(); | ||
const [newTag, setNewTag] = React.useState(''); | ||
const { setState: setSettingsState, editTags } = useSettingsContext(); | ||
|
||
const handleAddTag = () => { | ||
setSettingsState!((prev) => ({ | ||
...prev, | ||
editTags: [...(prev?.editTags || []), newTag], | ||
})); | ||
setNewTag(''); | ||
}; | ||
|
||
const handleSetTag = (tag: string) => { | ||
setValue('description', tag); | ||
closeModal(); | ||
}; | ||
|
||
const handleRemoveTag = (tag: string) => { | ||
setSettingsState!((prev) => ({ | ||
...prev, | ||
editTags: prev?.editTags?.filter((t) => t !== tag) || [], | ||
})); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div className="flex flex-col gap-4"> | ||
<div className="flex gap-2"> | ||
<Input | ||
value={newTag} | ||
onChange={(e) => setNewTag(e.target.value)} | ||
className="flex-1 w-full" | ||
/> | ||
<Button | ||
disabled={!newTag || newTag.trim().length === 0} | ||
variant="secondary" | ||
size="icon" | ||
onClick={handleAddTag} | ||
> | ||
<MaterialSymbolsAddRounded /> | ||
</Button> | ||
</div> | ||
</div> | ||
|
||
<hr className="h-[1px] w-auto -mx-6 bg-border" /> | ||
|
||
<div className="flex-1 overflow-y-scroll w-auto h-full -mx-6"> | ||
{editTags?.map((tag, index) => ( | ||
<div | ||
key={tag + index} | ||
className="flex gap-2 items-center justify-between px-6 py-2" | ||
> | ||
<p className="text-sm line-clamp-2">{tag}</p> | ||
<div className="flex gap-2 items-center"> | ||
<Button | ||
size="icon-md" | ||
variant="outline" | ||
onClick={() => handleRemoveTag(tag)} | ||
> | ||
<MaterialSymbolsDeleteForeverRounded className="text-lg" /> | ||
</Button> | ||
<Button | ||
size="icon-md" | ||
variant="outline" | ||
onClick={() => handleSetTag(tag)} | ||
> | ||
<MaterialSymbolsCheckSmallRounded className="text-lg" /> | ||
</Button> | ||
</div> | ||
</div> | ||
))} | ||
|
||
{editTags?.length === 0 && ( | ||
<div className="px-6"> | ||
<p className="text-sm text-muted-foreground text-center"> | ||
Не знайдено збережених тегів редагування | ||
</p> | ||
</div> | ||
)} | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default Component; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import EditDescription from './edit-description'; | ||
|
||
export default EditDescription; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters