import { useEffect, useState } from 'react'; import { ipcChannels } from '../../../shared/ipc/contracts'; import type { PlaylistsState } from '../../../shared/types/appPlaylists'; import { getDndApi } from '../dndApi'; const EMPTY: PlaylistsState = { playlists: [], audios: [] }; export function useAppPlaylists(): PlaylistsState { const api = getDndApi(); const [state, setState] = useState(EMPTY); useEffect(() => { void api.invoke(ipcChannels.playlists.getState, {}).then(setState); return api.on(ipcChannels.playlists.stateChanged, (next) => setState(next)); }, [api]); return state; }