diff --git a/front/views/PlayView.tsx b/front/views/PlayView.tsx index f3a2d83..48cbb4a 100644 --- a/front/views/PlayView.tsx +++ b/front/views/PlayView.tsx @@ -38,7 +38,7 @@ if (process.env.NODE_ENV != 'development' && Platform.OS === 'web') { const PlayView = ({ songId, type, route }: RouteProps) => { const accessToken = useSelector((state: RootState) => state.user.accessToken); const navigation = useNavigation(); - const song = useQuery(['song', songId], () => API.getSong(songId)); + const song = useQuery(['song', songId], () => API.getSong(songId), { staleTime: Infinity }); const toast = useToast(); const webSocket = useRef(); const [paused, setPause] = useState(true); @@ -180,6 +180,11 @@ const PlayView = ({ songId, type, route }: RouteProps) => { } }, []); useEffect(() => { + // Song.data is updated on navigation.navigate (do not know why) + // Hotfix to prevent midi setup process from reruning on game end + if (navigation.getState().routes.at(-1)?.name != route.name) { + return; + } if (song.data && !webSocket.current && partitionRendered) { navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure); } @@ -191,7 +196,14 @@ const PlayView = ({ songId, type, route }: RouteProps) => { return ( - setPartitionRendered(true)} timestamp={time}/> + setPartitionRendered(true)} + timestamp={time} + onEndReached={() => { + onEnd(); + navigation.navigate('Score', { songId: song.data.id }); + }} + /> { !partitionRendered && }