mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-14 04:20:07 +02:00
add new context menu implementation
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { useSessionStorage } from '/@/shared/hooks/use-session-storage';
|
||||
|
||||
interface RecentPlaylists {
|
||||
[serverId: string]: string;
|
||||
}
|
||||
|
||||
const RECENT_PLAYLISTS_KEY = 'recent-playlists';
|
||||
const DEFAULT_VALUE: RecentPlaylists = {};
|
||||
|
||||
export const useRecentPlaylists = (serverId: null | string) => {
|
||||
const [recentPlaylists, setRecentPlaylists] = useSessionStorage<RecentPlaylists>({
|
||||
defaultValue: DEFAULT_VALUE,
|
||||
key: RECENT_PLAYLISTS_KEY,
|
||||
});
|
||||
|
||||
const getRecentPlaylistId = useCallback((): null | string => {
|
||||
if (!serverId) return null;
|
||||
return recentPlaylists[serverId] || null;
|
||||
}, [recentPlaylists, serverId]);
|
||||
|
||||
const addRecentPlaylist = useCallback(
|
||||
(playlistId: string) => {
|
||||
if (!serverId || !playlistId) return;
|
||||
|
||||
setRecentPlaylists({
|
||||
...recentPlaylists,
|
||||
[serverId]: playlistId,
|
||||
});
|
||||
},
|
||||
[recentPlaylists, serverId, setRecentPlaylists],
|
||||
);
|
||||
|
||||
return {
|
||||
addRecentPlaylist,
|
||||
recentPlaylistId: getRecentPlaylistId(),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user