import { ActionIcon, Box, Button, Group, Highlight, Popover, Stack, Text, TextInput, } from '@mantine/core'; import { useDebouncedValue, useDisclosure } from '@mantine/hooks'; import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks'; import { useState } from 'react'; import { FiChevronRight, FiHelpCircle, FiPlus } from 'react-icons/fi'; import { actionIconClasses, buttonClasses, textClasses, textInputClasses } from 'styles'; import type { ThemePlaylist } from 'types'; import ThemePlaylistCard from './ThemePlaylistCard'; import ThemePlaylistModal from './ThemePlaylistModal'; function ThemePlaylists() { const { data: allThemes } = useQueryAPI({ endpoint: 'api/themes', }); const { data: themePlaylists } = useQueryAPI({ endpoint: 'api/themePlaylists', }); const { mutateAsync } = useMutationAPI(); const [opened, { open, close }] = useDisclosure(false); const [selectedPlaylist, setSelectedPlaylist] = useState({}); const { currentThemePlaylist, setCurrentThemePlaylist, theme, isMobile } = useCommonHooks(); const [searchValue, setSearchValue] = useState(''); const [debouncedSearch] = useDebouncedValue(searchValue, 500); const handleOpen = (playlist: any) => { setSelectedPlaylist(playlist); open(); }; const handleClose = () => { close(); }; const handleSavePlaylist = () => { mutateAsync({ method: selectedPlaylist.id === undefined ? 'POST' : 'PATCH', endpoint: 'api/themePlaylists', body: selectedPlaylist, }); close(); }; return ( <> Theme Playlists {'Theme playlists can be created here and applied to the homepage.'} { 'Playlists are lists of themes. They can be enabled either here or in the settings button on the homepage. When a playlist is enabled, it will shuffle the included themes on the homepage. If a theme is part of a playlist, it will appear while the playlist is active, regardless of random/shuffle.' } { setSearchValue(event.target.value); }} /> Defaults {themePlaylists ?.filter((playlist: ThemePlaylist) => playlist.default === 1) ?.filter((a: ThemePlaylist) => a.name.toLowerCase().includes(debouncedSearch.toLowerCase()), ) .map((cardPlaylist: ThemePlaylist) => { return ( {cardPlaylist.name === currentThemePlaylist && ( )} ); })} User Made {themePlaylists ?.filter((playlist: ThemePlaylist) => playlist.default === 0) ?.filter((a: ThemePlaylist) => a.name.toLowerCase().includes(debouncedSearch.toLowerCase()), ) .sort((a: any, b: any) => (a.name > b.name ? 1 : -1)) .map((cardPlaylist: ThemePlaylist) => { return ( {cardPlaylist.name === currentThemePlaylist && ( )} ); })} ); } export default ThemePlaylists;