diff --git a/src/components/friends/views/friends-list/FriendsCategoryManagerView.tsx b/src/components/friends/views/friends-list/FriendsCategoryManagerView.tsx new file mode 100644 index 0000000..1dd77dd --- /dev/null +++ b/src/components/friends/views/friends-list/FriendsCategoryManagerView.tsx @@ -0,0 +1,96 @@ +import { FC, MouseEvent, useState } from 'react'; +import { FriendCategoryData } from '@nitrots/nitro-renderer'; +import { LocalizeText } from '../../../../api'; +import { Button, Column, Flex, NitroCardContentView, NitroCardHeaderView, NitroCardView } from '../../../../common'; +import { useFriendsActions } from '../../../../hooks'; + +interface FriendsCategoryManagerViewProps +{ + categories: FriendCategoryData[]; + onCloseClick: (event: MouseEvent) => void; +} + +export const FriendsCategoryManagerView: FC = props => +{ + const { categories = [], onCloseClick = null } = props; + const { addCategory, renameCategory, removeCategory } = useFriendsActions(); + const [ newName, setNewName ] = useState(''); + const [ editingId, setEditingId ] = useState(0); + const [ editingName, setEditingName ] = useState(''); + + const submitAdd = () => + { + const trimmed = newName.trim(); + if(!trimmed.length) return; + addCategory(trimmed); + setNewName(''); + }; + + const submitRename = () => + { + const trimmed = editingName.trim(); + if(editingId && trimmed.length) renameCategory(editingId, trimmed); + setEditingId(0); + setEditingName(''); + }; + + return ( + + + + + setNewName(event.target.value) } + onKeyDown={ event => (event.key === 'Enter') && submitAdd() } /> + + + + { categories.map(category => ( + + { (editingId === category.id) ? + <> + setEditingName(event.target.value) } + onKeyDown={ event => (event.key === 'Enter') && submitRename() } /> + + + : + <> + { category.name } + { setEditingId(category.id); setEditingName(category.name); } }> + { '✎' } + + removeCategory(category.id) }> + { '✕' } + + } + + )) } + { !categories.length && + + { LocalizeText('friendlist.search.nofriendsfound') } + } + + + + ); +};