Skip to content

Commit

Permalink
Filter out current playlist on playlist operators
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffvli committed May 3, 2024
1 parent ce0c07e commit 683bb02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ interface PlaylistQueryBuilderProps {
parsedFilter: any,
extraFilters: { limit?: number; sortBy?: string; sortOrder?: string },
) => void;
playlistId?: string;
query: any;
sortBy: SongListSort;
sortOrder: 'asc' | 'desc';
Expand Down Expand Up @@ -89,7 +90,16 @@ export type PlaylistQueryBuilderRef = {

export const PlaylistQueryBuilder = forwardRef(
(
{ sortOrder, sortBy, limit, isSaving, query, onSave, onSaveAs }: PlaylistQueryBuilderProps,
{
sortOrder,
sortBy,
limit,
isSaving,
query,
onSave,
onSaveAs,
playlistId,
}: PlaylistQueryBuilderProps,
ref: Ref<PlaylistQueryBuilderRef>,
) => {
const { t } = useTranslation();
Expand All @@ -105,11 +115,17 @@ export const PlaylistQueryBuilder = forwardRef(

const playlistData = useMemo(() => {
if (!playlists) return [];
return playlists.items.map((p) => ({
label: p.name,
value: p.id,
}));
}, [playlists]);

return playlists.items
.filter((p) => {
if (!playlistId) return true;
return p.id !== playlistId;
})
.map((p) => ({
label: p.name,
value: p.id,
}));
}, [playlistId, playlists]);

const extraFiltersForm = useForm({
initialValues: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const PlaylistDetailSongListRoute = () => {
key={JSON.stringify(detailQuery?.data?.rules)}
isSaving={createPlaylistMutation?.isLoading}
limit={detailQuery?.data?.rules?.limit}
playlistId={playlistId}
query={detailQuery?.data?.rules}
sortBy={detailQuery?.data?.rules?.sort || SongListSort.ALBUM}
sortOrder={detailQuery?.data?.rules?.order || 'asc'}
Expand Down

0 comments on commit 683bb02

Please sign in to comment.