Front: Standardise queries (#233)

This commit is contained in:
Arthur Jamet
2023-06-23 15:16:22 +01:00
committed by GitHub
parent 80b06f15fe
commit 857158c6cf
17 changed files with 414 additions and 338 deletions
+7 -4
View File
@@ -16,7 +16,7 @@ import StartPageView from './views/StartPageView';
import HomeView from './views/HomeView';
import SearchView from './views/SearchView';
import SetttingsNavigator from './views/settings/SettingsView';
import { useQuery } from 'react-query';
import { useQuery } from './Queries';
import API, { APIError } from './API';
import PlayView from './views/PlayView';
import ScoreView from './views/ScoreView';
@@ -29,6 +29,9 @@ import { unsetAccessToken } from './state/UserSlice';
import TextButton from './components/TextButton';
import ErrorView from './views/ErrorView';
// Util function to hide route props in URL
const removeMe = () => '';
const protectedRoutes = () =>
({
Home: {
@@ -36,13 +39,13 @@ const protectedRoutes = () =>
options: { title: translate('welcome'), headerLeft: null },
link: '/',
},
Play: { component: PlayView, options: { title: translate('play') }, link: '/play' },
Play: { component: PlayView, options: { title: translate('play') }, link: '/play/:songId' },
Settings: {
component: SetttingsNavigator,
options: { title: 'Settings' },
link: '/settings/:screen?',
stringify: {
screen: () => '',
screen: removeMe,
},
},
Song: {
@@ -188,7 +191,7 @@ const ProfileErrorView = (props: { onTryAgain: () => void }) => {
export const Router = () => {
const dispatch = useDispatch();
const accessToken = useSelector((state: RootState) => state.user.accessToken);
const userProfile = useQuery(['user', 'me', accessToken], () => API.getUserInfo(), {
const userProfile = useQuery(API.getUserInfo, {
retry: 1,
refetchOnWindowFocus: false,
onError: (err) => {