Fixed validator for songhistory

This commit is contained in:
Clément Le Bihan
2023-12-05 12:26:52 +01:00
parent 2c9ec4a7d3
commit f590b573fb
3 changed files with 20 additions and 10 deletions
+3 -5
View File
@@ -1,5 +1,5 @@
/* eslint-disable no-mixed-spaces-and-tabs */
import { View, Image, TouchableOpacity } from 'react-native';
import { View, Image, Pressable } from 'react-native';
import { Divider, Text, ScrollView, Row, useMediaQuery, useTheme } from 'native-base';
import { useQuery } from '../../Queries';
import API from '../../API';
@@ -66,11 +66,9 @@ const SongHistory = (props: { quantity: number }) => {
flex: 1,
}}
>
<TouchableOpacity
onPress={() => navigation.navigate('Play', { songId: song.id })}
>
<Pressable onPress={() => navigation.navigate('Play', { songId: song.id })}>
<Text numberOfLines={1}>{song.name}</Text>
</TouchableOpacity>
</Pressable>
</View>
))
)}
+15 -3
View File
@@ -1,15 +1,27 @@
import * as yup from 'yup';
import ResponseHandler from './ResponseHandler';
import { SongValidator } from './Song';
import { ModelValidator } from './Model';
export const SongHistoryItemValidator = yup.object({
songID: yup.number().required(),
song: SongValidator.required(),
userID: yup.number().required(),
info: yup.object({
good: yup.number().required(),
great: yup.number().required(),
score: yup.number().required(),
wrong: yup.number().required(),
missed: yup.number().required(),
perfect: yup.number().required(),
max_score: yup.number().required(),
max_streak: yup.number().required(),
// there's also a current streak key but it doesn't
// conceptually makes sense outside of the played game
}).required(),
score: yup.number().required(),
playDate: yup.date().required(),
difficulties: yup.mixed().required(),
});
}).concat(ModelValidator);
export type SongHistoryItem = yup.InferType<typeof SongHistoryItemValidator>;
export const SongHistoryItemHandler: ResponseHandler<SongHistoryItem> = {
+2 -2
View File
@@ -360,12 +360,12 @@ const PlayView = ({ songId, route }: RouteProps<PlayViewProps>) => {
[
[
'lastScore',
songHistory.data?.best ?? 0,
songHistory.data?.history.at(0)?.score ?? 0,
() => <Clock color={statColor} />,
] as const,
[
'bestScore',
songHistory.data?.history.at(0)?.score ?? 0,
songHistory.data?.best ?? 0,
() => <Cup color={statColor} />,
],
] as const