mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-11-22 11:50:14 +00:00
chore: misc changes
Clean up some code inconsistencies Try to handle async stuff better
This commit is contained in:
parent
8b86c327c5
commit
b62b903ed5
@ -122,7 +122,7 @@ export const VideoList = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className={`video-list ${viewStyle}`}>
|
<div className={`video-list ${viewStyle}`}>
|
||||||
{data &&
|
{data &&
|
||||||
data.data?.map((video) => {
|
data?.data?.map((video) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={video.youtube_id}
|
key={video.youtube_id}
|
||||||
@ -134,11 +134,11 @@ export const VideoList = () => {
|
|||||||
>
|
>
|
||||||
<div className="video-thumb-wrap list">
|
<div className="video-thumb-wrap list">
|
||||||
<div className="video-thumb">
|
<div className="video-thumb">
|
||||||
<NextImage
|
<img
|
||||||
src={`${TA_BASE_URL}/cache/${video.vid_thumb_url}`}
|
src={`${TA_BASE_URL}/cache/${video.vid_thumb_url}`}
|
||||||
alt="video-thumb"
|
alt="video-thumb"
|
||||||
width={250}
|
// width={250}
|
||||||
height={145}
|
// height={145}
|
||||||
// blurDataURL={placeholder}
|
// blurDataURL={placeholder}
|
||||||
// placeholder="blur"
|
// placeholder="blur"
|
||||||
/>
|
/>
|
||||||
@ -171,7 +171,7 @@ export const VideoList = () => {
|
|||||||
className="video-desc-player"
|
className="video-desc-player"
|
||||||
id={`video-info-${video.youtube_id}`}
|
id={`video-info-${video.youtube_id}`}
|
||||||
>
|
>
|
||||||
{video.player.watched ? (
|
{video?.player?.watched ? (
|
||||||
<img
|
<img
|
||||||
src="/img/icon-seen.svg"
|
src="/img/icon-seen.svg"
|
||||||
alt="seen-icon"
|
alt="seen-icon"
|
||||||
|
@ -1,22 +1,24 @@
|
|||||||
import NextImage from "next/image";
|
import NextImage from "next/image";
|
||||||
import ReactPlayer from "react-player";
|
import ReactPlayer from "react-player";
|
||||||
import IconClose from "../images/icon-close.svg";
|
import IconClose from "../images/icon-close.svg";
|
||||||
|
import { TA_BASE_URL } from "../lib/constants";
|
||||||
import { formatNumbers } from "../lib/utils";
|
import { formatNumbers } from "../lib/utils";
|
||||||
|
|
||||||
export const VideoPlayer = ({ selectedVideoUrl, handleRemoveVideoPlayer }) => {
|
export const VideoPlayer = ({ selectedVideoUrl, handleRemoveVideoPlayer }) => {
|
||||||
if (!selectedVideoUrl) return;
|
if (!selectedVideoUrl) return;
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{selectedVideoUrl && (
|
||||||
<div className="player-wrapper">
|
<div className="player-wrapper">
|
||||||
<div className="video-player">
|
<div className="video-player">
|
||||||
<ReactPlayer
|
<ReactPlayer
|
||||||
controls={true}
|
controls={true}
|
||||||
width="100%"
|
width="100%"
|
||||||
height="100%"
|
height="100%"
|
||||||
light="false"
|
light={false}
|
||||||
playing // TODO: Not currently working
|
playing // TODO: Not currently working
|
||||||
playsinline
|
playsinline
|
||||||
url={`${process.env.NEXT_PUBLIC_TUBEARCHIVIST_URL}/media/${selectedVideoUrl.media_url}`}
|
url={`${TA_BASE_URL}/media/${selectedVideoUrl?.media_url}`}
|
||||||
/>
|
/>
|
||||||
<div className="player-title boxed-content">
|
<div className="player-title boxed-content">
|
||||||
<NextImage
|
<NextImage
|
||||||
@ -56,6 +58,7 @@ export const VideoPlayer = ({ selectedVideoUrl, handleRemoveVideoPlayer }) => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
import { Channel } from "../types/channel";
|
import { Channel } from "../types/channel";
|
||||||
|
import { TA_BASE_URL } from "./constants";
|
||||||
|
|
||||||
export const getChannels = async (token: string): Promise<Channel> => {
|
export const getChannels = async (token: string): Promise<Channel> => {
|
||||||
const response = await fetch(
|
const response = await fetch(`${TA_BASE_URL}/api/channel/`, {
|
||||||
`${process.env.NEXT_PUBLIC_TUBEARCHIVIST_URL}/api/channel/`,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Error getting channel information");
|
throw new Error("Error getting channel information");
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
import { Playlist } from "../types/playlist";
|
import { Playlist } from "../types/playlist";
|
||||||
|
import { TA_BASE_URL } from "./constants";
|
||||||
|
|
||||||
export const getPlaylists = async (token: string): Promise<Playlist> => {
|
export const getPlaylists = async (token: string): Promise<Playlist> => {
|
||||||
const response = await fetch(
|
const response = await fetch(`${TA_BASE_URL}/api/playlist/`, {
|
||||||
`${process.env.NEXT_PUBLIC_TUBEARCHIVIST_URL}/api/playlist/`,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Error getting channel information");
|
throw new Error("Error getting channel information");
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
import { Videos } from "../types/video";
|
import { Videos } from "../types/video";
|
||||||
|
import { TA_BASE_URL } from "./constants";
|
||||||
|
|
||||||
export const getVideos = async (token: string): Promise<Videos> => {
|
export const getVideos = async (token: string): Promise<Videos> => {
|
||||||
if (!token) {
|
if (!token) {
|
||||||
throw new Error("Missing API token in request to get videos");
|
throw new Error("Missing API token in request to get videos");
|
||||||
}
|
}
|
||||||
const response = await fetch(
|
const response = await fetch(`${TA_BASE_URL}/api/video/`, {
|
||||||
`${process.env.NEXT_PUBLIC_TUBEARCHIVIST_URL}/api/video/`,
|
|
||||||
{
|
|
||||||
headers: {
|
headers: {
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: `Token ${token}`,
|
Authorization: `Token ${token}`,
|
||||||
mode: "no-cors",
|
mode: "no-cors",
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error("Failed to fetch videos");
|
throw new Error("Failed to fetch videos");
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import NextAuth from "next-auth";
|
import NextAuth from "next-auth";
|
||||||
import CredentialsProvider from "next-auth/providers/credentials";
|
import CredentialsProvider from "next-auth/providers/credentials";
|
||||||
|
import { TA_BASE_URL } from "../../../lib/constants";
|
||||||
|
|
||||||
type TA_Token = {
|
type TA_Token = {
|
||||||
token: string;
|
token: string;
|
||||||
@ -29,17 +30,14 @@ export default NextAuth({
|
|||||||
password: credentials.password,
|
password: credentials.password,
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await fetch(
|
const res = await fetch(`${TA_BASE_URL}/api/login/`, {
|
||||||
`${process.env.NEXT_PUBLIC_TUBEARCHIVIST_URL}/api/login/`,
|
|
||||||
{
|
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept-Language": "en-US",
|
"Accept-Language": "en-US",
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const ta_token: TA_Token = await res.json();
|
const ta_token: TA_Token = await res.json();
|
||||||
// If no error and we have user data, return it
|
// If no error and we have user data, return it
|
||||||
|
@ -29,6 +29,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
dehydratedState: dehydrate(queryClient),
|
dehydratedState: dehydrate(queryClient),
|
||||||
|
session,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -114,7 +115,7 @@ const Channel: NextPage = () => {
|
|||||||
{!channels.data ? (
|
{!channels.data ? (
|
||||||
<h2>No channels found...</h2>
|
<h2>No channels found...</h2>
|
||||||
) : (
|
) : (
|
||||||
channels?.data.map((channel) => {
|
channels?.data?.map((channel) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={channel?.channel_id}
|
key={channel?.channel_id}
|
||||||
|
@ -38,13 +38,14 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
await queryClient.prefetchQuery("videos", () =>
|
await queryClient.prefetchQuery(["videos", session.ta_token.token], () =>
|
||||||
getVideos(session.ta_token.token)
|
getVideos(session.ta_token.token)
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
dehydratedState: dehydrate(queryClient),
|
dehydratedState: dehydrate(queryClient),
|
||||||
|
session,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,7 @@ export const getServerSideProps: GetServerSideProps = async (context) => {
|
|||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
dehydratedState: dehydrate(queryClient),
|
dehydratedState: dehydrate(queryClient),
|
||||||
|
session,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -41,7 +42,11 @@ const Playlist = () => {
|
|||||||
const { data: session } = useSession();
|
const { data: session } = useSession();
|
||||||
const {
|
const {
|
||||||
data: { data: playlists },
|
data: { data: playlists },
|
||||||
} = useQuery("playlists", () => getPlaylists(session.ta_token.token));
|
error,
|
||||||
|
isLoading,
|
||||||
|
} = useQuery("playlists", () => getPlaylists(session.ta_token.token), {
|
||||||
|
enabled: !!session.ta_token.token,
|
||||||
|
});
|
||||||
|
|
||||||
const [viewStyle, setViewStyle] = useState<ViewStyle>("grid");
|
const [viewStyle, setViewStyle] = useState<ViewStyle>("grid");
|
||||||
|
|
||||||
@ -119,7 +124,7 @@ const Playlist = () => {
|
|||||||
<div className={`playlist-list ${viewStyle}`}>
|
<div className={`playlist-list ${viewStyle}`}>
|
||||||
{/* {% if results %}
|
{/* {% if results %}
|
||||||
{% for playlist in results %} */}
|
{% for playlist in results %} */}
|
||||||
{!playlists ? (
|
{!isLoading && !playlists ? (
|
||||||
<h2>No playlists found...</h2>
|
<h2>No playlists found...</h2>
|
||||||
) : (
|
) : (
|
||||||
playlists?.map((playlist) => {
|
playlists?.map((playlist) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user