mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Update album artist base route
This commit is contained in:
parent
6746903808
commit
45aef104fe
8 changed files with 17 additions and 51 deletions
|
|
@ -1,13 +1,13 @@
|
|||
// Referenced from: https://betterprogramming.pub/the-best-way-to-manage-routes-in-a-react-project-with-typescript-c4e8d4422d64
|
||||
|
||||
export enum AppRoute {
|
||||
ACTION_REQUIRED = '/action-required',
|
||||
EXPLORE = '/explore',
|
||||
HOME = '/',
|
||||
LIBRARY_ALBUMARTISTS = '/library/album-artists',
|
||||
LIBRARY_ALBUMARTISTS_DETAIL = '/library/album-artists/:albumArtistId',
|
||||
LIBRARY_ALBUMS = '/library/albums',
|
||||
LIBRARY_ALBUMS_DETAIL = '/library/albums/:albumId',
|
||||
LIBRARY_ALBUM_ARTISTS = '/library/album-artists',
|
||||
LIBRARY_ALBUM_ARTISTS_DETAIL = '/library/album-artists/:albumArtistId',
|
||||
LIBRARY_ALBUM_ARTISTS_DETAIL_DISCOGRAPHY = '/library/album-artists/:albumArtistId/discography',
|
||||
LIBRARY_ALBUM_ARTISTS_DETAIL_TOP_SONGS = '/library/album-artists/:albumArtistId/top-songs',
|
||||
LIBRARY_ARTISTS = '/library/artists',
|
||||
LIBRARY_ARTISTS_DETAIL = '/library/artists/:artistId',
|
||||
LIBRARY_FOLDERS = '/library/folders',
|
||||
|
|
@ -20,39 +20,3 @@ export enum AppRoute {
|
|||
SEARCH = '/search',
|
||||
SERVERS = '/servers',
|
||||
}
|
||||
|
||||
type TArgs =
|
||||
| { path: AppRoute.HOME }
|
||||
| { path: AppRoute.ACTION_REQUIRED }
|
||||
| { path: AppRoute.NOW_PLAYING }
|
||||
| { path: AppRoute.EXPLORE }
|
||||
| { path: AppRoute.PLAYING }
|
||||
| { path: AppRoute.SERVERS }
|
||||
| { path: AppRoute.SEARCH }
|
||||
| { path: AppRoute.LIBRARY_ARTISTS }
|
||||
| { path: AppRoute.LIBRARY_ARTISTS_DETAIL }
|
||||
| { path: AppRoute.LIBRARY_ALBUMARTISTS }
|
||||
| {
|
||||
params: { albumArtistId: string };
|
||||
path: AppRoute.LIBRARY_ALBUMARTISTS_DETAIL;
|
||||
}
|
||||
| { path: AppRoute.LIBRARY_ALBUMS }
|
||||
| { path: AppRoute.LIBRARY_FOLDERS }
|
||||
| { path: AppRoute.LIBRARY_SONGS }
|
||||
| {
|
||||
params: { albumId: string };
|
||||
path: AppRoute.LIBRARY_ALBUMS_DETAIL;
|
||||
};
|
||||
|
||||
type TArgsWithParams = Extract<TArgs, { params: any; path: any }>;
|
||||
|
||||
export const createPath = (args: TArgs) => {
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
if (args.hasOwnProperty('params') === false) return args.path;
|
||||
|
||||
// Create a path by replacing params in the route definition
|
||||
return Object.entries((args as TArgsWithParams).params).reduce(
|
||||
(previousValue: string, [param, value]) => previousValue.replace(`:${param}`, `${value}`),
|
||||
args.path,
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue