Skip to content

Commit

Permalink
Update to match schema without score
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbe-j committed Nov 11, 2023
1 parent a4fde8f commit c28ab13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
40 changes: 20 additions & 20 deletions dance-app/src/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,11 @@ interface VideoData {
id: string;
video: string;
created: string;
tier: string
score: number
collectionId: string;
}

interface Score {
id: string;
score: number;
tier: string;
expand: {
video: VideoData;
user: User;
expand?: {
user: User | undefined;
};
}

Expand All @@ -29,31 +24,36 @@ function Leaderboard() {
// eslint-disable-next-line react-hooks/exhaustive-deps
const pb = new PocketBase("https://junctionb.nyman.dev");
const [isLoading, setIsLoading] = useState(true);
const [scores, setScores] = useState<Score[]>([]);
const [videos, setVideos] = useState<VideoData[]>([]);

useEffect(() => {
const getVideos = async () => {
const newScores = await pb
.collection("scores")
.getFullList<Score>({ expand: "video, user" });
console.log(newScores);
setScores(newScores);
const newVideos = await pb
.collection("videos")
.getFullList<VideoData>({ expand: "user" });
console.log(newVideos)
setVideos(newVideos);
setIsLoading(false);
};
getVideos();
}, [pb]);
}, []);

if (isLoading) {
return <Loader />;
}

const scoredVideos = videos
.filter((video) => video.expand?.user)
.filter((video) => video.score !== 0)
.sort((a, b) => a.score - b.score)

return (
<div className="leaderboard-list">
<div className="spacer" />
{scores.map(({ score, tier, expand: { video: entry, user } }) => (
<div className="card" key={entry.id}>
{scoredVideos.map(({ id, collectionId, video, tier, score, expand }) => (
<div className="card" key={id}>
<video
src={`https://junctionb.nyman.dev/api/files/${entry.collectionId}/${entry.id}/${entry.video}`}
src={`https://junctionb.nyman.dev/api/files/${collectionId}/${id}/${video}`}
preload="metadata"
autoPlay
muted
Expand All @@ -62,7 +62,7 @@ function Leaderboard() {
<div className="text-container">
<h4>{tier}</h4>
<p>
{user.name}: {score}
{expand?.user?.name}: {score}
</p>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions dance-app/src/Submit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const Submit: FC<SubmitProps> = ({ tier, video }) => {
console.log(blob)
formData.append('video', blob, `${src}.${fileType}`)
formData.append('tier', tier.toString())
formData.append('try', '1')
formData.append('score', '-1')
await pb.collection('videos').create(formData)
setTimeout(() => setIsLoading((state) => !state), 1000)
}
Expand Down

0 comments on commit c28ab13

Please sign in to comment.