From 4823b1dc385ee5079a3bf70bfe181f419891f8b9 Mon Sep 17 00:00:00 2001 From: Jing Hua <59118459+ztjhz@users.noreply.github.com> Date: Sun, 2 Apr 2023 23:04:11 +0800 Subject: [PATCH] feat: folder colors (#191) --- src/assets/icons/ColorPaletteIcon.tsx | 17 +++++++ src/components/Menu/ChatFolder.tsx | 65 ++++++++++++++++++++++++++- src/constants/color.ts | 7 +++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/assets/icons/ColorPaletteIcon.tsx create mode 100644 src/constants/color.ts diff --git a/src/assets/icons/ColorPaletteIcon.tsx b/src/assets/icons/ColorPaletteIcon.tsx new file mode 100644 index 0000000..8481681 --- /dev/null +++ b/src/assets/icons/ColorPaletteIcon.tsx @@ -0,0 +1,17 @@ +import React from 'react'; + +const ColorPaletteIcon = (props: React.SVGProps) => { + return ( + + + + ); +}; + +export default ColorPaletteIcon; diff --git a/src/components/Menu/ChatFolder.tsx b/src/components/Menu/ChatFolder.tsx index 8cc894d..f140781 100644 --- a/src/components/Menu/ChatFolder.tsx +++ b/src/components/Menu/ChatFolder.tsx @@ -14,6 +14,10 @@ import EditIcon from '@icon/EditIcon'; import DeleteIcon from '@icon/DeleteIcon'; import CrossIcon from '@icon/CrossIcon'; import TickIcon from '@icon/TickIcon'; +import ColorPaletteIcon from '@icon/ColorPaletteIcon'; +import RefreshIcon from '@icon/RefreshIcon'; + +import { folderColorOptions } from '@constants/color'; const ChatFolder = ({ folderChats, @@ -24,16 +28,19 @@ const ChatFolder = ({ }) => { const folderName = useStore((state) => state.folders[folderId].name); const isExpanded = useStore((state) => state.folders[folderId].expanded); + const color = useStore((state) => state.folders[folderId].color); const setChats = useStore((state) => state.setChats); const setFolders = useStore((state) => state.setFolders); const inputRef = useRef(null); + const folderRef = useRef(null); const [_folderName, _setFolderName] = useState(folderName); const [isEdit, setIsEdit] = useState(false); const [isDelete, setIsDelete] = useState(false); const [isHover, setIsHover] = useState(false); + const [showPalette, setShowPalette] = useState(false); const editTitle = () => { const updatedFolders: FolderCollection = JSON.parse( @@ -62,6 +69,16 @@ const ChatFolder = ({ setIsDelete(false); }; + const updateColor = (_color?: string) => { + const updatedFolders: FolderCollection = JSON.parse( + JSON.stringify(useStore.getState().folders) + ); + if (_color) updatedFolders[folderId].color = _color; + else delete updatedFolders[folderId].color; + setFolders(updatedFolders); + setShowPalette(false); + }; + const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { e.preventDefault(); @@ -133,8 +150,20 @@ const ChatFolder = ({ onDragLeave={handleDragLeave} >
{ + if (color && folderRef.current) + folderRef.current.style.background = `${color}dd`; + }} + onMouseLeave={() => { + if (color && folderRef.current) + folderRef.current.style.background = color; + }} >
@@ -169,6 +198,40 @@ const ChatFolder = ({ ) : ( <> +
+ + {showPalette && ( +
+ <> + {folderColorOptions.map((c) => ( + + +
+ )} +
+