import { useOutletContext, useParams } from 'react-router-dom'; import Notifications from '../components/Notifications'; import PlaylistList from '../components/PlaylistList'; import { useEffect, useState } from 'react'; import { OutletContextType } from './Base'; import Pagination from '../components/Pagination'; import ScrollToTopOnNavigate from '../components/ScrollToTop'; import loadPlaylistList from '../api/loader/loadPlaylistList'; import { PlaylistsResponseType } from './Playlists'; import iconGridView from '/img/icon-gridview.svg'; import iconListView from '/img/icon-listview.svg'; import { useUserConfigStore } from '../stores/UserConfigStore'; import updateUserConfig, { UserConfigType } from '../api/actions/updateUserConfig'; const ChannelPlaylist = () => { const { channelId } = useParams(); const { userConfig, setUserConfig } = useUserConfigStore(); const { currentPage, setCurrentPage } = useOutletContext() as OutletContextType; const [refreshPlaylists, setRefreshPlaylists] = useState(false); const [playlistsResponse, setPlaylistsResponse] = useState(); const playlistList = playlistsResponse?.data; const pagination = playlistsResponse?.paginate; const view = userConfig.view_style_playlist; const showSubedOnly = userConfig.show_subed_only; const handleUserConfigUpdate = async (config: Partial) => { const updatedUserConfig = await updateUserConfig(config); setUserConfig(updatedUserConfig); }; useEffect(() => { (async () => { const playlists = await loadPlaylistList({ channel: channelId, subscribed: showSubedOnly, page: currentPage, }); setPlaylistsResponse(playlists); setRefreshPlaylists(false); })(); }, [channelId, refreshPlaylists, showSubedOnly, currentPage]); return ( <> TA | Channel: Playlists
Show subscribed only:
{ handleUserConfigUpdate({ show_subed_only: !showSubedOnly }); setRefreshPlaylists(true); }} type="checkbox" /> {!showSubedOnly && ( )} {showSubedOnly && ( )}
{ handleUserConfigUpdate({ view_style_playlist: 'grid' }); }} alt="grid view" /> { handleUserConfigUpdate({ view_style_playlist: 'list' }); }} alt="list view" />
{pagination && }
); }; export default ChannelPlaylist;