Front: Play Page: add SlideView
This commit is contained in:
@@ -7,7 +7,6 @@ import SongLobbyView from './views/SongLobbyView';
|
|||||||
import AuthenticationView from './views/AuthenticationView';
|
import AuthenticationView from './views/AuthenticationView';
|
||||||
import HomeView from './views/HomeView';
|
import HomeView from './views/HomeView';
|
||||||
import SearchView from './views/SearchView';
|
import SearchView from './views/SearchView';
|
||||||
import PartitionView from './views/PartitionView';
|
|
||||||
import SetttingsNavigator from './views/SettingsView';
|
import SetttingsNavigator from './views/SettingsView';
|
||||||
import { useQuery } from 'react-query';
|
import { useQuery } from 'react-query';
|
||||||
import API from './API';
|
import API from './API';
|
||||||
@@ -27,7 +26,6 @@ export const protectedRoutes = <>
|
|||||||
<Stack.Screen name="Score" component={ScoreView} options={{ title: translate('score') }} />
|
<Stack.Screen name="Score" component={ScoreView} options={{ title: translate('score') }} />
|
||||||
<Stack.Screen name="Search" component={SearchView} options={{ title: translate('search') }} />
|
<Stack.Screen name="Search" component={SearchView} options={{ title: translate('search') }} />
|
||||||
<Stack.Screen name="User" component={ProfileView} options={{ title: translate('user') }} />
|
<Stack.Screen name="User" component={ProfileView} options={{ title: translate('user') }} />
|
||||||
<Stack.Screen name="Partition" component={PartitionView} options={{ title: translate('partition') }} />
|
|
||||||
</>;
|
</>;
|
||||||
|
|
||||||
export const publicRoutes = <React.Fragment>
|
export const publicRoutes = <React.Fragment>
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ type PartitionVisualizerProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const PartitionVisualizer = ({ songId }: PartitionVisualizerProps) => {
|
const PartitionVisualizer = ({ songId }: PartitionVisualizerProps) => {
|
||||||
const partitionRessources = useQuery(["partition"], () =>
|
|
||||||
API.getPartitionRessources(songId)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!partitionRessources.data) {
|
if (!partitionRessources.data) {
|
||||||
return (
|
return (
|
||||||
@@ -22,7 +20,7 @@ const PartitionVisualizer = ({ songId }: PartitionVisualizerProps) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<SlideView sources={partitionRessources.data} speed={200} startAt={0} />
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Text } from "native-base";
|
|||||||
import { translate } from "../i18n/i18n";
|
import { translate } from "../i18n/i18n";
|
||||||
import { en } from "../i18n/Translations";
|
import { en } from "../i18n/Translations";
|
||||||
import { RootState, useSelector } from "../state/Store";
|
import { RootState, useSelector } from "../state/Store";
|
||||||
import { Text } from "native-base";
|
|
||||||
|
|
||||||
type TranslateProps = {
|
type TranslateProps = {
|
||||||
translationKey: keyof typeof en;
|
translationKey: keyof typeof en;
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { Box } from "native-base";
|
|
||||||
import API from "../API";
|
|
||||||
import PartitionVisualizer from "../components/PartitionVisualizer/PartitionVisualizer";
|
|
||||||
|
|
||||||
const PartitionView = () => {
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box style={{ padding: 10 }}>
|
|
||||||
<PartitionVisualizer songId={1} />
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PartitionView;
|
|
||||||
@@ -9,6 +9,8 @@ import API from '../API';
|
|||||||
import LoadingComponent from '../components/Loading';
|
import LoadingComponent from '../components/Loading';
|
||||||
import Constants from 'expo-constants';
|
import Constants from 'expo-constants';
|
||||||
import { useStopwatch } from 'react-timer-hook';
|
import { useStopwatch } from 'react-timer-hook';
|
||||||
|
import PartitionVisualizer from '../components/PartitionVisualizer/PartitionVisualizer';
|
||||||
|
import SlideView from '../components/PartitionVisualizer/SlideView';
|
||||||
|
|
||||||
type PlayViewProps = {
|
type PlayViewProps = {
|
||||||
songId: number
|
songId: number
|
||||||
@@ -21,6 +23,9 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
const webSocket = useRef<WebSocket>();
|
const webSocket = useRef<WebSocket>();
|
||||||
const timer = useStopwatch({ autoStart: false });
|
const timer = useStopwatch({ autoStart: false });
|
||||||
const [paused, setPause] = useState<boolean>();
|
const [paused, setPause] = useState<boolean>();
|
||||||
|
const partitionRessources = useQuery(["partition"], () =>
|
||||||
|
API.getPartitionRessources(songId)
|
||||||
|
);
|
||||||
|
|
||||||
const onPause = () => {
|
const onPause = () => {
|
||||||
timer.pause();
|
timer.pause();
|
||||||
@@ -33,6 +38,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
}
|
}
|
||||||
const onResume = () => {
|
const onResume = () => {
|
||||||
setPause(false);
|
setPause(false);
|
||||||
|
timer.start();
|
||||||
webSocket.current?.send(JSON.stringify({
|
webSocket.current?.send(JSON.stringify({
|
||||||
type: "pause",
|
type: "pause",
|
||||||
paused: false,
|
paused: false,
|
||||||
@@ -66,11 +72,15 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
timer.start();
|
timer.start();
|
||||||
};
|
};
|
||||||
webSocket.current.onmessage = (message) => {
|
webSocket.current.onmessage = (message) => {
|
||||||
const data = JSON.parse(message.data);
|
try {
|
||||||
if (data.type == 'end') {
|
const data = JSON.parse(message.data);
|
||||||
navigation.navigate('Score');
|
if (data.type == 'end') {
|
||||||
} else if (data.song_launched == undefined) {
|
navigation.navigate('Score');
|
||||||
toast.show({ description: data, placement: 'top', colorScheme: 'secondary' });
|
} else if (data.song_launched == undefined) {
|
||||||
|
toast.show({ description: data, placement: 'top', colorScheme: 'secondary' });
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setPause(false);
|
setPause(false);
|
||||||
@@ -106,7 +116,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
}, [])
|
}, [])
|
||||||
const score = 20;
|
const score = 20;
|
||||||
|
|
||||||
if (!song.data) {
|
if (!song.data || !partitionRessources.data) {
|
||||||
return <Center style={{ flexGrow: 1 }}>
|
return <Center style={{ flexGrow: 1 }}>
|
||||||
<LoadingComponent/>
|
<LoadingComponent/>
|
||||||
</Center>
|
</Center>
|
||||||
@@ -114,6 +124,7 @@ const PlayView = ({ songId }: PlayViewProps) => {
|
|||||||
return (
|
return (
|
||||||
<SafeAreaView style={{ flexGrow: 1, flexDirection: 'column' }}>
|
<SafeAreaView style={{ flexGrow: 1, flexDirection: 'column' }}>
|
||||||
<View style={{ flexGrow: 1 }}>
|
<View style={{ flexGrow: 1 }}>
|
||||||
|
<SlideView sources={partitionRessources.data} speed={200} startAt={0} />
|
||||||
</View>
|
</View>
|
||||||
<Box shadow={4} style={{ height: '12%', width:'100%', borderWidth: 0.5, margin: 5 }}>
|
<Box shadow={4} style={{ height: '12%', width:'100%', borderWidth: 0.5, margin: 5 }}>
|
||||||
<Row justifyContent='space-between' style={{ flexGrow: 1, alignItems: 'center' }} >
|
<Row justifyContent='space-between' style={{ flexGrow: 1, alignItems: 'center' }} >
|
||||||
|
|||||||
Reference in New Issue
Block a user