feature/share-libs
tsx 65 lines 1.73 KB
Raw
1 "use client";
2
3 import {
4 AudioFile,
5 Status,
6 } from "@/models/audio-file";
7 import { useRouter } from "next/navigation";
8 import { useState } from "react";
9 import ButtonGenerateBackingTracks from "./button-split";
10 import MainVotesView, { } from "./votes-view-main";
11 import LetsPlayView from "./lets-play";
12 import { useLogger } from "@/lib/logger";
13 import { SongProviderVote } from "@/models/song-votes-detail-response";
14
15 export default function VotesView({
16 songProviderId,
17 votes,
18 audioFile,
19 }: {
20 songProviderId: number;
21 votes: SongProviderVote[];
22 audioFile: AudioFile | null;
23 }) {
24
25 const log = useLogger("Votes view");
26 const [goToPlayer, setGoToPlayer] = useState(false);
27 const router = useRouter();
28 const [votesAggregate, setVotesAggregate] = useState(0);
29
30 const isDoneSplitting = audioFile && audioFile.status === Status.DONE;
31
32 if (goToPlayer) {
33 log.debug("Go to player");
34 router.push(`/play?audioFileId=${audioFile?.id}`);
35 return <></>;
36 }
37
38 const onVotesAggregateUpdate = (votesAggregate: number) => {
39 setVotesAggregate(votesAggregate);
40 }
41
42 const mainView = isDoneSplitting ? (
43 <LetsPlayView onClick={() => setGoToPlayer(true)} />
44 ) : (
45 <MainVotesView songProviderId={songProviderId} votes={votes} onVotesAggregateUpdate={onVotesAggregateUpdate} />
46 );
47 const mainButton = (
48 <ButtonGenerateBackingTracks
49 songProviderId={songProviderId}
50 audioFile={audioFile}
51 aggregateVotes={votesAggregate}
52 />
53 );
54 // Votes treshold is passed, show the generate button.
55 return (
56 <div className="grid-rows-2">
57 <div className="flex justify-center">
58 {mainButton}
59 </div>
60 <div className="flex justify-center min-h-8">
61 {mainView}
62 </div>
63 </div>
64 );
65 }