Front: Settings URL: Tweak to avoid code repitition

This commit is contained in:
Arthur Jamet
2023-06-21 16:27:22 +01:00
committed by Clément Le Bihan
parent f362531d42
commit 45595408fe
2 changed files with 14 additions and 4 deletions

View File

@@ -40,6 +40,9 @@ const protectedRoutes = () =>
component: SetttingsNavigator,
options: { title: 'Settings' },
link: '/settings/:screen?',
stringify: {
screen: () => '',
},
},
Song: {
component: SongLobbyView,
@@ -134,13 +137,20 @@ const routesToScreens = (routes: Partial<Record<keyof AppRouteParams, Route>>) =
));
const routesToLinkingConfig = (
routes: Partial<Record<keyof AppRouteParams, { link?: string }>>
routes: Partial<
Record<keyof AppRouteParams, { link?: string; stringify?: Record<string, () => string> }>
>
) => {
const pagesToRoute = {} as Record<keyof AppRouteParams, string>;
// Too lazy to (find the) type
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const pagesToRoute = {} as Record<keyof AppRouteParams, any>;
Object.keys(routes).forEach((route) => {
const index = route as keyof AppRouteParams;
if (routes[index]?.link) {
pagesToRoute[index] = routes[index]!.link!;
pagesToRoute[index] = {
path: routes[index]!.link!,
stringify: routes[index]!.stringify,
};
}
});
return {

View File

@@ -79,7 +79,7 @@ type SetttingsNavigatorProps = {
const SetttingsNavigator = (props?: RouteProps<SetttingsNavigatorProps>) => {
const userQuery = useQuery(['user'], () => API.getUserInfo());
const user = useMemo(() => userQuery.data, [userQuery]);
console.log(props?.screen);
if (userQuery.isLoading) {
return (
<Center style={{ flex: 1 }}>