From 47e0861d47a890e2d22b6719196ca09b93342711 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 23 May 2023 18:36:34 +0900 Subject: [PATCH] Make the scoreview use scorometer's information --- front/views/PlayView.tsx | 14 +++++--------- front/views/ScoreView.tsx | 24 ++++++++++++++++-------- scorometer/main.py | 1 + 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index 34d4231..6577e10 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -89,13 +89,11 @@ const PlayView = ({ songId, type, route }: RouteProps) => { webSocket.current?.send(JSON.stringify({ type: "end" })); - stopwatch.stop(); - webSocket.current?.close(); } const onMIDISuccess = (access) => { const inputs = access.inputs; - + if (inputs.size < 2) { toast.show({ description: 'No MIDI Keyboard found' }); return; @@ -115,7 +113,7 @@ const PlayView = ({ songId, type, route }: RouteProps) => { try { const data = JSON.parse(message.data); if (data.type == 'end') { - navigation.navigate('Score', { songId: song.data!.id }); + navigation.navigate('Score', { songId: song.data!.id, ...data }); return; } const points = data.info.score; @@ -151,7 +149,7 @@ const PlayView = ({ songId, type, route }: RouteProps) => { default: break; } - } + } toast.show({ description: formattedMessage, placement: 'top', colorScheme: messageColor ?? 'secondary' }); } catch (e) { console.log(e); @@ -216,7 +214,6 @@ const PlayView = ({ songId, type, route }: RouteProps) => { timestamp={Math.max(0, time)} onEndReached={() => { onEnd(); - navigation.navigate('Score', { songId: song.data.id }); }} /> { !partitionRendered && } @@ -269,7 +266,7 @@ const PlayView = ({ songId, type, route }: RouteProps) => { {midiKeyboardFound && <> - } onPress={() => { + } onPress={() => { if (paused) { onResume(); } else { @@ -294,7 +291,6 @@ const PlayView = ({ songId, type, route }: RouteProps) => { } onPress={() => { onEnd(); - navigation.navigate('Score', { songId: song.data.id }); }}/> } @@ -304,4 +300,4 @@ const PlayView = ({ songId, type, route }: RouteProps) => { ); } -export default PlayView \ No newline at end of file +export default PlayView diff --git a/front/views/ScoreView.tsx b/front/views/ScoreView.tsx index 3a309c5..6278d69 100644 --- a/front/views/ScoreView.tsx +++ b/front/views/ScoreView.tsx @@ -8,19 +8,27 @@ import API from '../API'; import { useQueries, useQuery } from "react-query"; import { LoadingView } from "../components/Loading"; -type ScoreViewProps = { songId: number } +type ScoreViewProps = { + songId: number + overallScore: number, + score: { + missed: number, + good: number, + great: number, + perfect: number, + maxScore: number, + } +} -const ScoreView = ({ songId, route }: RouteProps) => { - const theme = useTheme(); +const ScoreView = ({ songId, overallScore, score }: RouteProps) => { const navigation = useNavigation(); const songQuery = useQuery(['song', songId], () => API.getSong(songId)); const artistQuery = useQuery(['song', songId, "artist"], () => API.getArtist(songQuery.data!.artistId!), { enabled: songQuery.data != undefined } ); - const songHistoryQuery = useQuery(["song", "history"], () => API.getUserPlayHistory()); // const perfoamnceRecommandationsQuery = useQuery(['song', props.songId, 'score', 'latest', 'recommendations'], () => API.getLastSongPerformanceScore(props.songId)); - const recommendations = useQuery(['song', songId, 'recommendations'], () => API.getUserRecommendations()); + const recommendations = useQuery(['song', 'recommendations'], () => API.getUserRecommendations()); const artistRecommendations = useQueries(recommendations.data ?.filter(({ artistId }) => artistId !== null) .map((song) => ({ @@ -32,8 +40,8 @@ const ScoreView = ({ songId, route }: RouteProps) => { if (!recommendations.data || artistRecommendations.find(({ data }) => !data) || !songHistoryQuery.data || !songQuery.data || (songQuery.data.artistId && !artistQuery.data)) { return ; } - const songScore = songHistoryQuery.data.find((history) => history.songID == songId); - if (!songScore) { + // I think we don't need that anymore but /shrug + if (!overallScore) { return
) => { t + ' : '}/> - {songScore.score + "pts"} + {overallScore + "pts"} diff --git a/scorometer/main.py b/scorometer/main.py index e93233d..fe71d65 100755 --- a/scorometer/main.py +++ b/scorometer/main.py @@ -282,6 +282,7 @@ class Scorometer: self.info["missed"] += 1 send( { + "type": "end", "overallScore": self.info["score"], "score": { "missed": self.info["missed"],