import { Box, Button, Group, Stack, Text } from '@mantine/core'; import { useDisclosure } from '@mantine/hooks'; import { modals } from '@mantine/modals'; import { useCommonHooks, useMutationAPI, useQueryAPI } from 'hooks'; import { useState } from 'react'; import { FiChevronRight, FiPlus } from 'react-icons/fi'; import { buttonClasses, textClasses } from 'styles'; 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: createPlaylist } = useMutationAPI(); const { mutateAsync: deletePlaylist } = useMutationAPI(); const [opened, { open, close }] = useDisclosure(false); const [selectedPlaylist, setSelectedPlaylist] = useState({}); const { currentThemePlaylist, setCurrentThemePlaylist, theme } = useCommonHooks(); const handleOpen = (playlist: any) => { setSelectedPlaylist(playlist); open(); }; const handleClose = () => { close(); }; const handleSavePlaylist = () => { createPlaylist({ method: selectedPlaylist.id === undefined ? 'POST' : 'PATCH', endpoint: 'api/themePlaylists', body: selectedPlaylist, }); close(); }; const openDeleteConfirmModal = (playlist: any) => modals.openConfirmModal({ title: 'Are you sure you want to delete this theme playlist?', labels: { confirm: 'Delete', cancel: 'Cancel' }, confirmProps: { color: 'red' }, onConfirm: () => deletePlaylist({ method: 'DELETE', endpoint: 'api/themePlaylists', body: playlist, }), }); const handleDeletePlaylist = (playlist: any) => { openDeleteConfirmModal(playlist); close(); }; return ( <> Theme Playlists Defaults {themePlaylists ?.filter((playlist: any) => playlist.default === 1) .map((cardPlaylist: any) => { return ( {cardPlaylist.name === currentThemePlaylist && ( )} ); })} User Made {themePlaylists ?.filter((playlist: any) => playlist.default === 0) .map((cardPlaylist: any) => { return ( {cardPlaylist.name === currentThemePlaylist && ( )} ); })} ); } export default ThemePlaylists;