import { ChangeEvent, useCallback, useState } from 'react'; import { Group } from '@mantine/core'; import { Reorder, useDragControls } from 'framer-motion'; import isEqual from 'lodash/isEqual'; import { useTranslation } from 'react-i18next'; import { MdDragIndicator } from 'react-icons/md'; import { Button, Checkbox, Switch } from '/@/renderer/components'; import { useSettingsStoreActions, useGeneralSettings } from '../../../../store/settings.store'; import { SettingsOptions } from '/@/renderer/features/settings/components/settings-option'; import i18n from '/@/i18n/i18n'; const translatedSidebarItemMap = { Albums: i18n.t('page.sidebar.albums', { postProcess: 'titleCase' }), Artists: i18n.t('page.sidebar.artists', { postProcess: 'titleCase' }), Folders: i18n.t('page.sidebar.folders', { postProcess: 'titleCase' }), Genres: i18n.t('page.sidebar.genres', { postProcess: 'titleCase' }), Home: i18n.t('page.sidebar.home', { postProcess: 'titleCase' }), 'Now Playing': i18n.t('page.sidebar.nowPlaying', { postProcess: 'titleCase' }), Playlists: i18n.t('page.sidebar.playlists', { postProcess: 'titleCase' }), Search: i18n.t('page.sidebar.search', { postProcess: 'titleCase' }), Settings: i18n.t('page.sidebar.settings', { postProcess: 'titleCase' }), Tracks: i18n.t('page.sidebar.tracks', { postProcess: 'titleCase' }), }; const DragHandle = ({ dragControls }: any) => { return ( dragControls.start(event)} /> ); }; interface SidebarItem { disabled: boolean; id: string; } interface DraggableSidebarItemProps { handleChangeDisabled: (id: string, e: boolean) => void; item: SidebarItem; } const DraggableSidebarItem = ({ item, handleChangeDisabled }: DraggableSidebarItemProps) => { const dragControls = useDragControls(); return ( handleChangeDisabled(item.id, e.target.checked)} /> {translatedSidebarItemMap[item.id as keyof typeof translatedSidebarItemMap]} ); }; export const SidebarSettings = () => { const { t } = useTranslation(); const settings = useGeneralSettings(); const { setSidebarItems, setSettings } = useSettingsStoreActions(); const [localSidebarItems, setLocalSidebarItems] = useState(settings.sidebarItems); const handleSave = () => { setSidebarItems(localSidebarItems); }; const handleChangeDisabled = useCallback((id: string, e: boolean) => { setLocalSidebarItems((items) => items.map((item) => { if (item.id === id) { return { ...item, disabled: !e, }; } return item; }), ); }, []); const handleSetSidebarPlaylistList = (e: ChangeEvent) => { setSettings({ general: { ...settings, sidebarPlaylistList: e.target.checked, }, }); }; const handleSetSidebarCollapsedNavigation = (e: ChangeEvent) => { setSettings({ general: { ...settings, sidebarCollapsedNavigation: e.target.checked, }, }); }; const isSaveButtonDisabled = isEqual(settings.sidebarItems, localSidebarItems); return ( <> } description={t('setting.sidebarPlaylistList', { context: 'description', postProcess: 'sentenceCase', })} title={t('setting.sidebarPlaylistList', { postProcess: 'sentenceCase' })} /> } description={t('setting.sidebarPlaylistList', { context: 'description', postProcess: 'sentenceCase', })} title={t('setting.sidebarCollapsedNavigation', { postProcess: 'sentenceCase' })} /> {t('common.save', { postProcess: 'titleCase' })} } description={t('setting.sidebarCollapsedNavigation', { context: 'description', postProcess: 'sentenceCase', })} title={t('setting.sidebarConfiguration', { postProcess: 'sentenceCase' })} /> {localSidebarItems.map((item) => ( ))} ); };