Make the scoreview use scorometer's information

This commit is contained in:
2023-05-23 18:36:34 +09:00
parent b1d2027d4b
commit 47e0861d47
3 changed files with 22 additions and 17 deletions

View File

@@ -89,13 +89,11 @@ const PlayView = ({ songId, type, route }: RouteProps<PlayViewProps>) => {
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<PlayViewProps>) => {
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<PlayViewProps>) => {
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<PlayViewProps>) => {
timestamp={Math.max(0, time)}
onEndReached={() => {
onEnd();
navigation.navigate('Score', { songId: song.data.id });
}}
/>
{ !partitionRendered && <LoadingComponent/> }
@@ -269,7 +266,7 @@ const PlayView = ({ songId, type, route }: RouteProps<PlayViewProps>) => {
{midiKeyboardFound && <>
<IconButton size='sm' variant='solid' icon={
<Icon as={Ionicons} name={paused ? "play" : "pause"}/>
} onPress={() => {
} onPress={() => {
if (paused) {
onResume();
} else {
@@ -294,7 +291,6 @@ const PlayView = ({ songId, type, route }: RouteProps<PlayViewProps>) => {
<Icon as={Ionicons} name="stop"/>
} onPress={() => {
onEnd();
navigation.navigate('Score', { songId: song.data.id });
}}/>
</>}
</Row>
@@ -304,4 +300,4 @@ const PlayView = ({ songId, type, route }: RouteProps<PlayViewProps>) => {
);
}
export default PlayView
export default PlayView

View File

@@ -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<ScoreViewProps>) => {
const theme = useTheme();
const ScoreView = ({ songId, overallScore, score }: RouteProps<ScoreViewProps>) => {
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<ScoreViewProps>) => {
if (!recommendations.data || artistRecommendations.find(({ data }) => !data) || !songHistoryQuery.data || !songQuery.data || (songQuery.data.artistId && !artistQuery.data)) {
return <LoadingView/>;
}
const songScore = songHistoryQuery.data.find((history) => history.songID == songId);
if (!songScore) {
// I think we don't need that anymore but /shrug
if (!overallScore) {
return <Center>
<Translate translationKey="unknownError"/>
<TextButton
@@ -70,7 +78,7 @@ const ScoreView = ({ songId, route }: RouteProps<ScoreViewProps>) => {
<Row style={{ alignItems: 'center' }}>
<Translate translationKey='score' format={(t) => t + ' : '}/>
<Text bold fontSize='xl'>
{songScore.score + "pts"}
{overallScore + "pts"}
</Text>
</Row>
</Column>

View File

@@ -282,6 +282,7 @@ class Scorometer:
self.info["missed"] += 1
send(
{
"type": "end",
"overallScore": self.info["score"],
"score": {
"missed": self.info["missed"],