Fixed validator for songhistory
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable no-mixed-spaces-and-tabs */
|
/* 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 { Divider, Text, ScrollView, Row, useMediaQuery, useTheme } from 'native-base';
|
||||||
import { useQuery } from '../../Queries';
|
import { useQuery } from '../../Queries';
|
||||||
import API from '../../API';
|
import API from '../../API';
|
||||||
@@ -66,11 +66,9 @@ const SongHistory = (props: { quantity: number }) => {
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TouchableOpacity
|
<Pressable onPress={() => navigation.navigate('Play', { songId: song.id })}>
|
||||||
onPress={() => navigation.navigate('Play', { songId: song.id })}
|
|
||||||
>
|
|
||||||
<Text numberOfLines={1}>{song.name}</Text>
|
<Text numberOfLines={1}>{song.name}</Text>
|
||||||
</TouchableOpacity>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,15 +1,27 @@
|
|||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import ResponseHandler from './ResponseHandler';
|
import ResponseHandler from './ResponseHandler';
|
||||||
import { SongValidator } from './Song';
|
import { ModelValidator } from './Model';
|
||||||
|
|
||||||
|
|
||||||
export const SongHistoryItemValidator = yup.object({
|
export const SongHistoryItemValidator = yup.object({
|
||||||
songID: yup.number().required(),
|
songID: yup.number().required(),
|
||||||
song: SongValidator.required(),
|
|
||||||
userID: yup.number().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(),
|
score: yup.number().required(),
|
||||||
playDate: yup.date().required(),
|
playDate: yup.date().required(),
|
||||||
difficulties: yup.mixed().required(),
|
difficulties: yup.mixed().required(),
|
||||||
});
|
}).concat(ModelValidator);
|
||||||
export type SongHistoryItem = yup.InferType<typeof SongHistoryItemValidator>;
|
export type SongHistoryItem = yup.InferType<typeof SongHistoryItemValidator>;
|
||||||
|
|
||||||
export const SongHistoryItemHandler: ResponseHandler<SongHistoryItem> = {
|
export const SongHistoryItemHandler: ResponseHandler<SongHistoryItem> = {
|
||||||
|
|||||||
@@ -360,12 +360,12 @@ const PlayView = ({ songId, route }: RouteProps<PlayViewProps>) => {
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
'lastScore',
|
'lastScore',
|
||||||
songHistory.data?.best ?? 0,
|
songHistory.data?.history.at(0)?.score ?? 0,
|
||||||
() => <Clock color={statColor} />,
|
() => <Clock color={statColor} />,
|
||||||
] as const,
|
] as const,
|
||||||
[
|
[
|
||||||
'bestScore',
|
'bestScore',
|
||||||
songHistory.data?.history.at(0)?.score ?? 0,
|
songHistory.data?.best ?? 0,
|
||||||
() => <Cup color={statColor} />,
|
() => <Cup color={statColor} />,
|
||||||
],
|
],
|
||||||
] as const
|
] as const
|
||||||
|
|||||||
Reference in New Issue
Block a user