mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Add favorite hotkey options (#326)
* Add favorite hotkey options * Update wording --------- Co-authored-by: Jeff <42182408+jeffvli@users.noreply.github.com>
This commit is contained in:
parent
ac84088c69
commit
7a580c2c65
4 changed files with 68 additions and 15 deletions
|
|
@ -16,13 +16,14 @@ import {
|
|||
useCurrentSong,
|
||||
useHotkeySettings,
|
||||
useMuted,
|
||||
usePreviousSong,
|
||||
useSidebarStore,
|
||||
useSpeed,
|
||||
useVolume,
|
||||
} from '/@/renderer/store';
|
||||
import { useRightControls } from '../hooks/use-right-controls';
|
||||
import { PlayerButton } from './player-button';
|
||||
import { LibraryItem, ServerType, Song } from '/@/renderer/api/types';
|
||||
import { LibraryItem, QueueSong, ServerType, Song } from '/@/renderer/api/types';
|
||||
import { useCreateFavorite, useDeleteFavorite, useSetRating } from '/@/renderer/features/shared';
|
||||
import { DropdownMenu, Rating } from '/@/renderer/components';
|
||||
import { PlayerbarSlider } from '/@/renderer/features/player/components/playerbar-slider';
|
||||
|
|
@ -38,6 +39,7 @@ export const RightControls = () => {
|
|||
const muted = useMuted();
|
||||
const server = useCurrentServer();
|
||||
const currentSong = useCurrentSong();
|
||||
const previousSong = usePreviousSong();
|
||||
const { setSideBar } = useAppStoreActions();
|
||||
const { rightExpanded: isQueueExpanded } = useSidebarStore();
|
||||
const { bindings } = useHotkeySettings();
|
||||
|
|
@ -56,15 +58,15 @@ export const RightControls = () => {
|
|||
const addToFavoritesMutation = useCreateFavorite({});
|
||||
const removeFromFavoritesMutation = useDeleteFavorite({});
|
||||
|
||||
const handleAddToFavorites = () => {
|
||||
if (!currentSong) return;
|
||||
const handleAddToFavorites = (song: QueueSong | undefined) => {
|
||||
if (!song?.id) return;
|
||||
|
||||
addToFavoritesMutation.mutate({
|
||||
query: {
|
||||
id: [currentSong.id],
|
||||
id: [song.id],
|
||||
type: LibraryItem.SONG,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
serverId: song?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -92,25 +94,25 @@ export const RightControls = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const handleRemoveFromFavorites = () => {
|
||||
if (!currentSong) return;
|
||||
const handleRemoveFromFavorites = (song: QueueSong | undefined) => {
|
||||
if (!song?.id) return;
|
||||
|
||||
removeFromFavoritesMutation.mutate({
|
||||
query: {
|
||||
id: [currentSong.id],
|
||||
id: [song.id],
|
||||
type: LibraryItem.SONG,
|
||||
},
|
||||
serverId: currentSong?.serverId,
|
||||
serverId: song?.serverId,
|
||||
});
|
||||
};
|
||||
|
||||
const handleToggleFavorite = () => {
|
||||
if (!currentSong) return;
|
||||
const handleToggleFavorite = (song: QueueSong | undefined) => {
|
||||
if (!song?.id) return;
|
||||
|
||||
if (currentSong.userFavorite) {
|
||||
handleRemoveFromFavorites();
|
||||
if (song.userFavorite) {
|
||||
handleRemoveFromFavorites(song);
|
||||
} else {
|
||||
handleAddToFavorites();
|
||||
handleAddToFavorites(song);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -126,6 +128,30 @@ export const RightControls = () => {
|
|||
[bindings.volumeUp.isGlobal ? '' : bindings.volumeUp.hotkey, handleVolumeUp],
|
||||
[bindings.volumeMute.isGlobal ? '' : bindings.volumeMute.hotkey, handleMute],
|
||||
[bindings.toggleQueue.isGlobal ? '' : bindings.toggleQueue.hotkey, handleToggleQueue],
|
||||
[
|
||||
bindings.favoriteCurrentAdd.isGlobal ? '' : bindings.favoriteCurrentAdd.hotkey,
|
||||
() => handleAddToFavorites(currentSong),
|
||||
],
|
||||
[
|
||||
bindings.favoriteCurrentRemove.isGlobal ? '' : bindings.favoriteCurrentRemove.hotkey,
|
||||
() => handleRemoveFromFavorites(currentSong),
|
||||
],
|
||||
[
|
||||
bindings.favoriteCurrentToggle.isGlobal ? '' : bindings.favoriteCurrentToggle.hotkey,
|
||||
() => handleToggleFavorite(currentSong),
|
||||
],
|
||||
[
|
||||
bindings.favoritePreviousAdd.isGlobal ? '' : bindings.favoritePreviousAdd.hotkey,
|
||||
() => handleAddToFavorites(previousSong),
|
||||
],
|
||||
[
|
||||
bindings.favoritePreviousRemove.isGlobal ? '' : bindings.favoritePreviousRemove.hotkey,
|
||||
() => handleRemoveFromFavorites(previousSong),
|
||||
],
|
||||
[
|
||||
bindings.favoritePreviousToggle.isGlobal ? '' : bindings.favoritePreviousToggle.hotkey,
|
||||
() => handleToggleFavorite(previousSong),
|
||||
],
|
||||
[bindings.rate0.isGlobal ? '' : bindings.rate0.hotkey, () => handleClearRating(null, 0)],
|
||||
[bindings.rate1.isGlobal ? '' : bindings.rate1.hotkey, () => handleUpdateRating(1)],
|
||||
[bindings.rate2.isGlobal ? '' : bindings.rate2.hotkey, () => handleUpdateRating(2)],
|
||||
|
|
@ -240,7 +266,7 @@ export const RightControls = () => {
|
|||
openDelay: 500,
|
||||
}}
|
||||
variant="secondary"
|
||||
onClick={handleToggleFavorite}
|
||||
onClick={() => handleToggleFavorite(currentSong)}
|
||||
/>
|
||||
{!isMinWidth ? (
|
||||
<PlayerButton
|
||||
|
|
|
|||
|
|
@ -13,6 +13,12 @@ const ipc = isElectron() ? window.electron.ipc : null;
|
|||
const BINDINGS_MAP: Record<BindingActions, string> = {
|
||||
browserBack: 'Browser back',
|
||||
browserForward: 'Browser forward',
|
||||
favoriteCurrentAdd: 'Favorite current song',
|
||||
favoriteCurrentRemove: 'Unfavorite current song',
|
||||
favoriteCurrentToggle: 'Toggle current song favorite',
|
||||
favoritePreviousAdd: 'Favorite previous song',
|
||||
favoritePreviousRemove: 'Unfavorite previous song',
|
||||
favoritePreviousToggle: 'Toggle previous song favorite',
|
||||
globalSearch: 'Global search',
|
||||
localSearch: 'In-page search',
|
||||
next: 'Next track',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue