mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
add new play controls to sidebar playlist list
This commit is contained in:
@@ -3,19 +3,18 @@ import { useQuery } from '@tanstack/react-query';
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import { MouseEvent, useCallback, useMemo, useState } from 'react';
|
import { MouseEvent, useCallback, useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { generatePath } from 'react-router';
|
import { generatePath, Link } from 'react-router';
|
||||||
import { Link } from 'react-router';
|
|
||||||
|
|
||||||
import styles from './sidebar-playlist-list.module.css';
|
import styles from './sidebar-playlist-list.module.css';
|
||||||
|
|
||||||
import { usePlayQueueAdd } from '/@/renderer/features/player/hooks/use-playqueue-add';
|
import { usePlayerContext } from '/@/renderer/features/player/context/player-context';
|
||||||
import { playlistsQueries } from '/@/renderer/features/playlists/api/playlists-api';
|
import { playlistsQueries } from '/@/renderer/features/playlists/api/playlists-api';
|
||||||
import { CreatePlaylistForm } from '/@/renderer/features/playlists/components/create-playlist-form';
|
import { CreatePlaylistForm } from '/@/renderer/features/playlists/components/create-playlist-form';
|
||||||
import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item';
|
import { SidebarItem } from '/@/renderer/features/sidebar/components/sidebar-item';
|
||||||
import { AppRoute } from '/@/renderer/router/routes';
|
import { AppRoute } from '/@/renderer/router/routes';
|
||||||
import { useCurrentServer } from '/@/renderer/store';
|
import { useCurrentServer } from '/@/renderer/store';
|
||||||
import { Accordion } from '/@/shared/components/accordion/accordion';
|
import { Accordion } from '/@/shared/components/accordion/accordion';
|
||||||
import { ActionIcon } from '/@/shared/components/action-icon/action-icon';
|
import { ActionIcon, ActionIconGroup } from '/@/shared/components/action-icon/action-icon';
|
||||||
import { ButtonProps } from '/@/shared/components/button/button';
|
import { ButtonProps } from '/@/shared/components/button/button';
|
||||||
import { Group } from '/@/shared/components/group/group';
|
import { Group } from '/@/shared/components/group/group';
|
||||||
import { Text } from '/@/shared/components/text/text';
|
import { Text } from '/@/shared/components/text/text';
|
||||||
@@ -30,7 +29,7 @@ import { Play } from '/@/shared/types/types';
|
|||||||
|
|
||||||
interface PlaylistRowButtonProps extends Omit<ButtonProps, 'onPlay'> {
|
interface PlaylistRowButtonProps extends Omit<ButtonProps, 'onPlay'> {
|
||||||
name: string;
|
name: string;
|
||||||
onPlay: (id: string, playType: Play.LAST | Play.NEXT | Play.NOW | Play.SHUFFLE) => void;
|
onPlay: (id: string, playType: Play) => void;
|
||||||
to: string;
|
to: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,14 +69,13 @@ const RowControls = ({
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group className={styles.controls} gap="xs" wrap="nowrap">
|
<ActionIconGroup className={styles.controls}>
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
icon="mediaPlay"
|
icon="mediaPlay"
|
||||||
iconProps={{
|
iconProps={{
|
||||||
size: 'md',
|
size: 'md',
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!id) return;
|
|
||||||
onPlay(id, Play.NOW);
|
onPlay(id, Play.NOW);
|
||||||
}}
|
}}
|
||||||
size="xs"
|
size="xs"
|
||||||
@@ -93,7 +91,6 @@ const RowControls = ({
|
|||||||
size: 'md',
|
size: 'md',
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!id) return;
|
|
||||||
onPlay(id, Play.SHUFFLE);
|
onPlay(id, Play.SHUFFLE);
|
||||||
}}
|
}}
|
||||||
size="xs"
|
size="xs"
|
||||||
@@ -109,7 +106,6 @@ const RowControls = ({
|
|||||||
size: 'md',
|
size: 'md',
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!id) return;
|
|
||||||
onPlay(id, Play.LAST);
|
onPlay(id, Play.LAST);
|
||||||
}}
|
}}
|
||||||
size="xs"
|
size="xs"
|
||||||
@@ -125,7 +121,6 @@ const RowControls = ({
|
|||||||
size: 'md',
|
size: 'md',
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!id) return;
|
|
||||||
onPlay(id, Play.NEXT);
|
onPlay(id, Play.NEXT);
|
||||||
}}
|
}}
|
||||||
size="xs"
|
size="xs"
|
||||||
@@ -135,12 +130,12 @@ const RowControls = ({
|
|||||||
}}
|
}}
|
||||||
variant="subtle"
|
variant="subtle"
|
||||||
/>
|
/>
|
||||||
</Group>
|
</ActionIconGroup>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SidebarPlaylistList = () => {
|
export const SidebarPlaylistList = () => {
|
||||||
const handlePlayQueueAdd = usePlayQueueAdd();
|
const player = usePlayerContext();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
|
|
||||||
@@ -157,15 +152,9 @@ export const SidebarPlaylistList = () => {
|
|||||||
|
|
||||||
const handlePlayPlaylist = useCallback(
|
const handlePlayPlaylist = useCallback(
|
||||||
(id: string, playType: Play) => {
|
(id: string, playType: Play) => {
|
||||||
handlePlayQueueAdd?.({
|
player.addToQueueByFetch(server.id, [id], LibraryItem.PLAYLIST, playType);
|
||||||
byItemType: {
|
|
||||||
id: [id],
|
|
||||||
type: LibraryItem.PLAYLIST,
|
|
||||||
},
|
|
||||||
playType,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[handlePlayQueueAdd],
|
[player, server.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = playlistsQuery.data;
|
const data = playlistsQuery.data;
|
||||||
@@ -258,7 +247,7 @@ export const SidebarPlaylistList = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const SidebarSharedPlaylistList = () => {
|
export const SidebarSharedPlaylistList = () => {
|
||||||
const handlePlayQueueAdd = usePlayQueueAdd();
|
const player = usePlayerContext();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
|
|
||||||
@@ -275,15 +264,10 @@ export const SidebarSharedPlaylistList = () => {
|
|||||||
|
|
||||||
const handlePlayPlaylist = useCallback(
|
const handlePlayPlaylist = useCallback(
|
||||||
(id: string, playType: Play) => {
|
(id: string, playType: Play) => {
|
||||||
handlePlayQueueAdd?.({
|
if (!server?.id) return;
|
||||||
byItemType: {
|
player.addToQueueByFetch(server.id, [id], LibraryItem.PLAYLIST, playType);
|
||||||
id: [id],
|
|
||||||
type: LibraryItem.PLAYLIST,
|
|
||||||
},
|
|
||||||
playType,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[handlePlayQueueAdd],
|
[player, server?.id],
|
||||||
);
|
);
|
||||||
|
|
||||||
const data = playlistsQuery.data;
|
const data = playlistsQuery.data;
|
||||||
|
|||||||
Reference in New Issue
Block a user