mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-15 04:51:06 +02:00
refactor some usePlayerSong consumers to only fetch needed properties
This commit is contained in:
@@ -1984,6 +1984,26 @@ export const usePlayerSong = () => {
|
||||
);
|
||||
};
|
||||
|
||||
export const usePlayerSongProperties = <T extends keyof QueueSong>(
|
||||
properties: T[],
|
||||
): Partial<Pick<QueueSong, T>> => {
|
||||
return usePlayerStoreBase(
|
||||
useShallow((state) => {
|
||||
const song = state.getCurrentSong();
|
||||
if (!song) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const result = {} as Pick<QueueSong, T>;
|
||||
|
||||
for (const prop of properties) {
|
||||
result[prop] = song[prop];
|
||||
}
|
||||
return result;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
export const usePlayerNum = () => {
|
||||
return usePlayerStoreBase((state) => state.player.playerNum);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user