2025-01-06 21:08:51 +07:00
|
|
|
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';
|
2025-03-20 20:30:08 +01:00
|
|
|
import loadPlaylistList, { PlaylistsResponseType } from '../api/loader/loadPlaylistList';
|
2025-01-06 21:08:51 +07:00
|
|
|
import iconGridView from '/img/icon-gridview.svg';
|
|
|
|
import iconListView from '/img/icon-listview.svg';
|
|
|
|
import { useUserConfigStore } from '../stores/UserConfigStore';
|
2025-02-13 21:43:01 +07:00
|
|
|
import updateUserConfig, { UserConfigType } from '../api/actions/updateUserConfig';
|
2025-03-20 20:30:08 +01:00
|
|
|
import { ApiResponseType } from '../functions/APIClient';
|
2025-06-05 05:19:16 +02:00
|
|
|
import { ViewStylesType, ViewStylesEnum } from '../configuration/constants/ViewStyle';
|
2025-01-06 21:08:51 +07:00
|
|
|
|
|
|
|
const ChannelPlaylist = () => {
|
|
|
|
const { channelId } = useParams();
|
2025-02-13 21:43:01 +07:00
|
|
|
const { userConfig, setUserConfig } = useUserConfigStore();
|
2025-01-06 21:08:51 +07:00
|
|
|
const { currentPage, setCurrentPage } = useOutletContext() as OutletContextType;
|
|
|
|
|
|
|
|
const [refreshPlaylists, setRefreshPlaylists] = useState(false);
|
|
|
|
|
2025-03-20 20:30:08 +01:00
|
|
|
const [playlistsResponse, setPlaylistsResponse] =
|
|
|
|
useState<ApiResponseType<PlaylistsResponseType>>();
|
2025-01-06 21:08:51 +07:00
|
|
|
|
2025-03-20 20:30:08 +01:00
|
|
|
const { data: playlistsResponseData } = playlistsResponse ?? {};
|
|
|
|
|
|
|
|
const playlistList = playlistsResponseData?.data;
|
|
|
|
const pagination = playlistsResponseData?.paginate;
|
2025-01-06 21:08:51 +07:00
|
|
|
|
2025-06-05 05:19:16 +02:00
|
|
|
const viewStyle = userConfig.view_style_playlist;
|
2025-02-13 21:43:01 +07:00
|
|
|
const showSubedOnly = userConfig.show_subed_only;
|
|
|
|
|
|
|
|
const handleUserConfigUpdate = async (config: Partial<UserConfigType>) => {
|
|
|
|
const updatedUserConfig = await updateUserConfig(config);
|
2025-03-20 20:30:08 +01:00
|
|
|
const { data: updatedUserConfigData } = updatedUserConfig;
|
|
|
|
|
|
|
|
if (updatedUserConfigData) {
|
|
|
|
setUserConfig(updatedUserConfigData);
|
|
|
|
}
|
2025-02-13 21:43:01 +07:00
|
|
|
};
|
2025-01-06 21:08:51 +07:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
const playlists = await loadPlaylistList({
|
|
|
|
channel: channelId,
|
|
|
|
subscribed: showSubedOnly,
|
2025-03-15 14:24:17 +01:00
|
|
|
page: currentPage,
|
2025-01-06 21:08:51 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
setPlaylistsResponse(playlists);
|
|
|
|
setRefreshPlaylists(false);
|
|
|
|
})();
|
|
|
|
}, [channelId, refreshPlaylists, showSubedOnly, currentPage]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<title>TA | Channel: Playlists</title>
|
|
|
|
<ScrollToTopOnNavigate />
|
|
|
|
<div className="boxed-content">
|
|
|
|
<Notifications pageName="channel" includeReindex={true} />
|
|
|
|
|
|
|
|
<div className="view-controls">
|
|
|
|
<div className="toggle">
|
|
|
|
<span>Show subscribed only:</span>
|
|
|
|
<div className="toggleBox">
|
|
|
|
<input
|
|
|
|
checked={showSubedOnly}
|
|
|
|
onChange={() => {
|
2025-02-13 21:43:01 +07:00
|
|
|
handleUserConfigUpdate({ show_subed_only: !showSubedOnly });
|
2025-01-06 21:08:51 +07:00
|
|
|
setRefreshPlaylists(true);
|
|
|
|
}}
|
|
|
|
type="checkbox"
|
|
|
|
/>
|
|
|
|
{!showSubedOnly && (
|
|
|
|
<label htmlFor="" className="ofbtn">
|
|
|
|
Off
|
|
|
|
</label>
|
|
|
|
)}
|
|
|
|
{showSubedOnly && (
|
|
|
|
<label htmlFor="" className="onbtn">
|
|
|
|
On
|
|
|
|
</label>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="view-icons">
|
|
|
|
<img
|
|
|
|
src={iconGridView}
|
|
|
|
onClick={() => {
|
2025-06-05 05:19:16 +02:00
|
|
|
handleUserConfigUpdate({
|
|
|
|
view_style_playlist: ViewStylesEnum.Grid as ViewStylesType,
|
|
|
|
});
|
2025-01-06 21:08:51 +07:00
|
|
|
}}
|
|
|
|
alt="grid view"
|
|
|
|
/>
|
|
|
|
<img
|
|
|
|
src={iconListView}
|
|
|
|
onClick={() => {
|
2025-06-05 05:19:16 +02:00
|
|
|
handleUserConfigUpdate({
|
|
|
|
view_style_playlist: ViewStylesEnum.List as ViewStylesType,
|
|
|
|
});
|
2025-01-06 21:08:51 +07:00
|
|
|
}}
|
|
|
|
alt="list view"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className={`boxed-content`}>
|
2025-06-05 05:19:16 +02:00
|
|
|
<div className={`playlist-list ${viewStyle}`}>
|
2025-01-06 21:08:51 +07:00
|
|
|
<PlaylistList playlistList={playlistList} setRefresh={setRefreshPlaylists} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className="boxed-content">
|
|
|
|
{pagination && <Pagination pagination={pagination} setPage={setCurrentPage} />}
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ChannelPlaylist;
|