From 99b46b0439bfd3ef636a586842c8e5d10aa3d4eb Mon Sep 17 00:00:00 2001 From: Markus Nyman Date: Sun, 12 Nov 2023 00:52:22 +0200 Subject: [PATCH] home section to own component --- dance-app/src/App.tsx | 2 +- dance-app/src/components/Leaderboard.tsx | 68 ++++++------- dance-app/src/sections/home.tsx | 97 ++++++++++++++++++ dance-app/src/sections/landing.tsx | 121 +---------------------- 4 files changed, 134 insertions(+), 154 deletions(-) create mode 100644 dance-app/src/sections/home.tsx diff --git a/dance-app/src/App.tsx b/dance-app/src/App.tsx index 2a6843e..241f4ae 100644 --- a/dance-app/src/App.tsx +++ b/dance-app/src/App.tsx @@ -55,7 +55,7 @@ function App() { }} > - + diff --git a/dance-app/src/components/Leaderboard.tsx b/dance-app/src/components/Leaderboard.tsx index 0d8b3db..c9da852 100644 --- a/dance-app/src/components/Leaderboard.tsx +++ b/dance-app/src/components/Leaderboard.tsx @@ -1,8 +1,8 @@ import { useEffect, useState } from "react"; import Loader from "./Loader"; -import PocketBase from "pocketbase"; import "../Leaderboard.css"; -import {Card, CardContent, CardMedia, Stack, Typography} from "@mui/material"; +import { Card, CardContent, CardMedia, Stack, Typography } from "@mui/material"; +import pb from "../pocketBase"; interface VideoData { id: string; @@ -20,25 +20,17 @@ interface User { email: string; name: string; } -interface LeaderboardProps { - pb: PocketBase; -} -function Leaderboard({ pb }: LeaderboardProps) { +function Leaderboard() { const [isLoading, setIsLoading] = useState(true); const [videos, setVideos] = useState([]); useEffect(() => { - const getVideos = async () => { - const newVideos = await pb - .collection("videos") - .getFullList({ expand: "user" }); - console.log(newVideos); - setVideos(newVideos); - setIsLoading(false); - }; - getVideos(); - }, [pb]); + pb.collection("videos") + .getFullList({ expand: "user" }) + .then((newVideos) => setVideos(newVideos)) + .then(() => setIsLoading(false)); + }, []); if (isLoading) { return ; @@ -57,26 +49,30 @@ function Leaderboard({ pb }: LeaderboardProps) { Todays high scores - {scoredVideos.map(({ id, collectionId, video, tier, score, expand }) => ( - - - - Tier {tier} - - {expand?.user?.name} - {': '} - {score} - - - - ))} + {scoredVideos.map( + ({ id, collectionId, video, tier, score, expand }) => ( + + + + + Tier {tier} + + + {expand?.user?.name} + {": "} + {score} + + + + ), + )} ); diff --git a/dance-app/src/sections/home.tsx b/dance-app/src/sections/home.tsx new file mode 100644 index 0000000..f42afda --- /dev/null +++ b/dance-app/src/sections/home.tsx @@ -0,0 +1,97 @@ +import { Container, Typography, Button, Grid } from "@mui/material"; +import RecordingPage from "./recording"; +import { useEffect, useState } from "react"; +import pb from "../pocketBase"; + +export interface RefVideo { + id: string; + collectionId: string; + tier: string; + video: string; +} + +// eslint-disable-next-line react-refresh/only-export-components +export enum Tier { + Tier1 = 1, + Tier2 = 2, + Tier3 = 3, + Tier4 = 4, + Tier5 = 5, +} + +const HomeSection = () => { + const [selectedTier, setSelectedTier] = useState(null); + const handleButtonClick = (tier: Tier) => setSelectedTier(tier); + const [refVideos, setRefVideos] = useState([]); + + useEffect(() => { + pb.collection("source_videos") + .getFullList() + .then((videos) => setRefVideos(videos)); + }, []); + + return ( + <> + {selectedTier ? ( + video.tier === selectedTier.toString(), + )} + pb={pb} + goBack={setSelectedTier} + /> + ) : ( + + + + + Ur fat! + + + Explore our amazing features! + + + + + + + + + + + + + + )} + + ); +}; + +export default HomeSection; diff --git a/dance-app/src/sections/landing.tsx b/dance-app/src/sections/landing.tsx index a2ce473..3ae7147 100644 --- a/dance-app/src/sections/landing.tsx +++ b/dance-app/src/sections/landing.tsx @@ -1,124 +1,11 @@ -import { useContext, useEffect, useState } from "react"; -import { Container, Typography, Button, Grid } from "@mui/material"; -import PocketBase from "pocketbase"; -import RecordingPage from "./recording"; +import { useContext } from "react"; import { PageContext } from "../context/PageContext"; import Leaderboard from "../components/Leaderboard"; -import { AuthContext } from "../context/AuthContext"; +import HomeSection from "./home"; -interface LandingProps { - pb: PocketBase; -} - -export interface RefVideo { - id: string; - collectionId: string; - tier: string; - video: string; -} - -// eslint-disable-next-line react-refresh/only-export-components -export enum Tier { - Tier1 = 1, - Tier2 = 2, - Tier3 = 3, - Tier4 = 4, - Tier5 = 5, -} - -const LandingPage = ({ pb }: LandingProps) => { +const LandingPage = () => { const page = useContext(PageContext); - const [selectedTier, setSelectedTier] = useState(null); - const [refVideos, setRefVideos] = useState([]); - const { user } = useContext(AuthContext); - - useEffect(() => { - if (user?.token !== "") { - } - }, [user]); - - useEffect(() => { - const getRefVideos = async () => { - const videos = await pb - .collection("source_videos") - .getFullList(); - setRefVideos(videos); - }; - getRefVideos(); - }, []); - - const handleButtonClick = (tier: Tier) => { - setSelectedTier(tier); - }; - - return ( - <> - {page === "home" ? ( - <> - {selectedTier ? ( - video.tier === selectedTier.toString(), - )} - pb={pb} - goBack={setSelectedTier} - /> - ) : ( - - - - - Ur fat! - - - Explore our amazing features! - - - - - - - - - - - - - - )} - - ) : ( - - )} - - ); + return page === "home" ? : ; }; export default LandingPage;