Front: Prettier
This commit is contained in:
committed by
Clément Le Bihan
parent
0416e1ba41
commit
3dea5a0865
+61
-17
@@ -30,22 +30,64 @@ import TextButton from './components/TextButton';
|
|||||||
|
|
||||||
const protectedRoutes = () =>
|
const protectedRoutes = () =>
|
||||||
({
|
({
|
||||||
Home: { component: HomeView, options: { title: translate('welcome'), headerLeft: null }, link: '/' },
|
Home: {
|
||||||
|
component: HomeView,
|
||||||
|
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' },
|
||||||
Settings: { component: SetttingsNavigator, options: { title: 'Settings' }, link: '/settings' },
|
Settings: {
|
||||||
Song: { component: SongLobbyView, options: { title: translate('play') }, link: '/song/:songId' },
|
component: SetttingsNavigator,
|
||||||
Artist: { component: ArtistDetailsView, options: { title: translate('artistFilter') }, link: '/artist/:artistId' },
|
options: { title: 'Settings' },
|
||||||
Score: { component: ScoreView, options: { title: translate('score'), headerLeft: null }, link: undefined },
|
link: '/settings',
|
||||||
Search: { component: SearchView, options: { title: translate('search') }, link: '/search/:query?' },
|
},
|
||||||
|
Song: {
|
||||||
|
component: SongLobbyView,
|
||||||
|
options: { title: translate('play') },
|
||||||
|
link: '/song/:songId',
|
||||||
|
},
|
||||||
|
Artist: {
|
||||||
|
component: ArtistDetailsView,
|
||||||
|
options: { title: translate('artistFilter') },
|
||||||
|
link: '/artist/:artistId',
|
||||||
|
},
|
||||||
|
Score: {
|
||||||
|
component: ScoreView,
|
||||||
|
options: { title: translate('score'), headerLeft: null },
|
||||||
|
link: undefined,
|
||||||
|
},
|
||||||
|
Search: {
|
||||||
|
component: SearchView,
|
||||||
|
options: { title: translate('search') },
|
||||||
|
link: '/search/:query?',
|
||||||
|
},
|
||||||
User: { component: ProfileView, options: { title: translate('user') }, link: '/user' },
|
User: { component: ProfileView, options: { title: translate('user') }, link: '/user' },
|
||||||
} as const);
|
} as const);
|
||||||
|
|
||||||
const publicRoutes = () =>
|
const publicRoutes = () =>
|
||||||
({
|
({
|
||||||
Start: { component: StartPageView, options: { title: 'Chromacase', headerShown: false }, link: '/' },
|
Start: {
|
||||||
Login: { component: (params: RouteProps<{}>) => AuthenticationView({ isSignup: false, ...params }), options: { title: translate('signInBtn') }, link: '/login' },
|
component: StartPageView,
|
||||||
Signup: { component: (params: RouteProps<{}>) => AuthenticationView({ isSignup: true, ...params }), options: { title: translate('signUpBtn') }, link: '/signup' },
|
options: { title: 'Chromacase', headerShown: false },
|
||||||
Oops: { component: ProfileErrorView, options: { title: 'Oops', headerShown: false }, link: undefined },
|
link: '/',
|
||||||
|
},
|
||||||
|
Login: {
|
||||||
|
component: (params: RouteProps<{}>) =>
|
||||||
|
AuthenticationView({ isSignup: false, ...params }),
|
||||||
|
options: { title: translate('signInBtn') },
|
||||||
|
link: '/login',
|
||||||
|
},
|
||||||
|
Signup: {
|
||||||
|
component: (params: RouteProps<{}>) =>
|
||||||
|
AuthenticationView({ isSignup: true, ...params }),
|
||||||
|
options: { title: translate('signUpBtn') },
|
||||||
|
link: '/signup',
|
||||||
|
},
|
||||||
|
Oops: {
|
||||||
|
component: ProfileErrorView,
|
||||||
|
options: { title: 'Oops', headerShown: false },
|
||||||
|
link: undefined,
|
||||||
|
},
|
||||||
} as const);
|
} as const);
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
@@ -91,7 +133,9 @@ const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) =
|
|||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
const routesToLinkingConfig = (routes: Partial<Record<keyof AppRouteParams, { link?: string }>>) => {
|
const routesToLinkingConfig = (
|
||||||
|
routes: Partial<Record<keyof AppRouteParams, { link?: string }>>
|
||||||
|
) => {
|
||||||
const pagesToRoute = {} as Record<keyof AppRouteParams, string>;
|
const pagesToRoute = {} as Record<keyof AppRouteParams, string>;
|
||||||
Object.keys(routes).forEach((route) => {
|
Object.keys(routes).forEach((route) => {
|
||||||
const index = route as keyof AppRouteParams;
|
const index = route as keyof AppRouteParams;
|
||||||
@@ -101,9 +145,9 @@ const routesToLinkingConfig = (routes: Partial<Record<keyof AppRouteParams, { li
|
|||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
prefixes: [],
|
prefixes: [],
|
||||||
config: { screens: pagesToRoute }
|
config: { screens: pagesToRoute },
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
|
|
||||||
const ProfileErrorView = (props: { onTryAgain: () => void }) => {
|
const ProfileErrorView = (props: { onTryAgain: () => void }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
@@ -148,7 +192,7 @@ export const Router = () => {
|
|||||||
if (userProfile.isSuccess && accessToken) {
|
if (userProfile.isSuccess && accessToken) {
|
||||||
return 'authed';
|
return 'authed';
|
||||||
}
|
}
|
||||||
return 'noAuth'
|
return 'noAuth';
|
||||||
}, [userProfile, accessToken]);
|
}, [userProfile, accessToken]);
|
||||||
const routes = useMemo(() => {
|
const routes = useMemo(() => {
|
||||||
if (authStatus == 'authed') {
|
if (authStatus == 'authed') {
|
||||||
@@ -165,13 +209,13 @@ export const Router = () => {
|
|||||||
|
|
||||||
if (authStatus == 'loading') {
|
if (authStatus == 'loading') {
|
||||||
// We dont want this to be a screen, as this lead to a navigator without the requested route, and fallback.
|
// We dont want this to be a screen, as this lead to a navigator without the requested route, and fallback.
|
||||||
return <LoadingView/>;
|
return <LoadingView />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<NavigationContainer
|
<NavigationContainer
|
||||||
linking={routesToLinkingConfig(routes)}
|
linking={routesToLinkingConfig(routes)}
|
||||||
fallback={<LoadingView/>}
|
fallback={<LoadingView />}
|
||||||
theme={colorScheme == 'light' ? DefaultTheme : DarkTheme}
|
theme={colorScheme == 'light' ? DefaultTheme : DarkTheme}
|
||||||
>
|
>
|
||||||
<Stack.Navigator>
|
<Stack.Navigator>
|
||||||
|
|||||||
Reference in New Issue
Block a user