mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 04:51:06 +02:00
feat: add regex filter setting for sidebar playlists (#1589)
* added regex filter for sidebar playlists --------- Co-authored-by: jeffvli <jeffvictorli@gmail.com>
This commit is contained in:
@@ -25,6 +25,12 @@ import {
|
||||
usePermissions,
|
||||
useSidebarPlaylistSorting,
|
||||
} from '/@/renderer/store';
|
||||
import {
|
||||
useCurrentServer,
|
||||
useCurrentServerId,
|
||||
usePermissions,
|
||||
useSidebarPlaylistListFilterRegex,
|
||||
} from '/@/renderer/store';
|
||||
import { formatDurationString } from '/@/renderer/utils';
|
||||
import { Accordion } from '/@/shared/components/accordion/accordion';
|
||||
import { ActionIcon, ActionIconGroup } from '/@/shared/components/action-icon/action-icon';
|
||||
@@ -357,6 +363,7 @@ export const SidebarPlaylistList = () => {
|
||||
const { t } = useTranslation();
|
||||
const server = useCurrentServer();
|
||||
const sidebarPlaylistSorting = useSidebarPlaylistSorting();
|
||||
const filterRegex = useSidebarPlaylistListFilterRegex();
|
||||
|
||||
const playlistsQuery = useQuery(
|
||||
playlistsQueries.list({
|
||||
@@ -400,10 +407,23 @@ export const SidebarPlaylistList = () => {
|
||||
return { ...base, items: playlistsQuery.data?.items };
|
||||
}
|
||||
|
||||
let regex: null | RegExp = null;
|
||||
if (filterRegex) {
|
||||
try {
|
||||
regex = new RegExp(filterRegex, 'i');
|
||||
} catch {
|
||||
// Invalid regex, ignore filtering
|
||||
}
|
||||
}
|
||||
|
||||
const ownedPlaylistItems: Array<Playlist> = [];
|
||||
|
||||
for (const playlist of playlistsQuery.data?.items ?? []) {
|
||||
if (!playlist.owner || playlist.owner === server.username) {
|
||||
// Filter out playlists that match the regex
|
||||
if (regex && regex.test(playlist.name)) {
|
||||
continue;
|
||||
}
|
||||
ownedPlaylistItems.push(playlist);
|
||||
}
|
||||
}
|
||||
@@ -429,6 +449,7 @@ export const SidebarPlaylistList = () => {
|
||||
server.username,
|
||||
sidebarPlaylistSorting,
|
||||
playlistOrder,
|
||||
filterRegex,
|
||||
]);
|
||||
|
||||
const handleReorder = (
|
||||
@@ -533,6 +554,7 @@ export const SidebarSharedPlaylistList = () => {
|
||||
const { t } = useTranslation();
|
||||
const server = useCurrentServer();
|
||||
const sidebarPlaylistSorting = useSidebarPlaylistSorting();
|
||||
const filterRegex = useSidebarPlaylistListFilterRegex();
|
||||
|
||||
const playlistsQuery = useQuery(
|
||||
playlistsQueries.list({
|
||||
@@ -580,10 +602,23 @@ export const SidebarSharedPlaylistList = () => {
|
||||
return { ...base, items: playlistsQuery.data?.items };
|
||||
}
|
||||
|
||||
let regex: null | RegExp = null;
|
||||
if (filterRegex) {
|
||||
try {
|
||||
regex = new RegExp(filterRegex, 'i');
|
||||
} catch {
|
||||
// Invalid regex, ignore filtering
|
||||
}
|
||||
}
|
||||
|
||||
const sharedPlaylistItems: Array<Playlist> = [];
|
||||
|
||||
for (const playlist of playlistsQuery.data?.items ?? []) {
|
||||
if (playlist.owner && playlist.owner !== server.username) {
|
||||
// Filter out playlists that match the regex
|
||||
if (regex && regex.test(playlist.name)) {
|
||||
continue;
|
||||
}
|
||||
sharedPlaylistItems.push(playlist);
|
||||
}
|
||||
}
|
||||
@@ -609,6 +644,7 @@ export const SidebarSharedPlaylistList = () => {
|
||||
server.username,
|
||||
sidebarPlaylistSorting,
|
||||
playlistOrder,
|
||||
filterRegex,
|
||||
]);
|
||||
|
||||
const handleReorder = (
|
||||
|
||||
Reference in New Issue
Block a user