mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 18:33:33 +00:00
30 lines
918 B
TypeScript
30 lines
918 B
TypeScript
import { useMemo } from 'react';
|
|
import { useLocation } from 'react-router';
|
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
|
import { GenreTarget, useSettingsStore } from '/@/renderer/store';
|
|
|
|
const ALBUM_REGEX = /albums$/;
|
|
const SONG_REGEX = /songs$/;
|
|
|
|
export const useGenreRoute = () => {
|
|
const { pathname } = useLocation();
|
|
const matchAlbum = ALBUM_REGEX.test(pathname);
|
|
const matchSongs = SONG_REGEX.test(pathname);
|
|
|
|
const baseState = useSettingsStore((state) =>
|
|
state.general.genreTarget === GenreTarget.ALBUM
|
|
? AppRoute.LIBRARY_GENRES_ALBUMS
|
|
: AppRoute.LIBRARY_GENRES_SONGS,
|
|
);
|
|
|
|
return useMemo(() => {
|
|
if (matchAlbum) {
|
|
return AppRoute.LIBRARY_GENRES_ALBUMS;
|
|
}
|
|
if (matchSongs) {
|
|
return AppRoute.LIBRARY_GENRES_SONGS;
|
|
}
|
|
return baseState;
|
|
}, [baseState, matchAlbum, matchSongs]);
|
|
};
|