import { GetServerSideProps } from "next"; import NextImage from "next/image"; import { getSession, useSession } from "next-auth/react"; import { useState } from "react"; import { dehydrate, QueryClient, useQuery } from "react-query"; import { CustomHead } from "../components/CustomHead"; import { Layout } from "../components/Layout"; import { getTAUrl } from "../lib/constants"; import { getPlaylists } from "../lib/getPlaylists"; import IconAdd from "../images/icon-add.svg"; import IconListView from "../images/icon-listview.svg"; import IconGridView from "../images/icon-gridview.svg"; type ViewStyle = "grid" | "list"; const TA_BASE_URL = getTAUrl(); export const getServerSideProps: GetServerSideProps = async (context) => { const queryClient = new QueryClient(); const session = await getSession(context); if (!session) { return { redirect: { destination: "/auth/login", permanent: false, }, }; } await queryClient.prefetchQuery(["playlists", session.ta_token.token], () => getPlaylists(session.ta_token.token) ); return { props: { dehydratedState: dehydrate(queryClient), session, }, }; }; const Playlist = () => { const { data: session } = useSession(); const { data: { data: playlists }, error, isLoading, } = useQuery( ["playlists", session.ta_token.token], () => getPlaylists(session.ta_token.token), { enabled: !!session.ta_token.token, } ); const [viewStyle, setViewStyle] = useState("grid"); const handleSetViewstyle = (selectedViewStyle: ViewStyle) => { setViewStyle(selectedViewStyle); }; return (

Playlists

{/* {% csrf_token %} {{ subscribe_form }} */}
{/*
*/}
Show subscribed only:
{/* {% if not show_subed_only %} */} {/* {% else %} */} {/* {% endif %} */}
handleSetViewstyle("grid")} alt="grid view" /> handleSetViewstyle("list")} alt="list view" />
{/* {% if results %} {% for playlist in results %} */} {!isLoading && !playlists ? (

No playlists found...

) : ( playlists?.map((playlist) => { return (

{playlist.playlist_channel}

{playlist.playlist_name}

Last refreshed: {playlist.playlist_last_refresh}

{/* {% if playlist.source.playlist_subscribed %} */} {/* {% else %} */} {/* {% endif %} */}
); }) )}
); }; export default Playlist;