You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
640 B
23 lines
640 B
import { useEffect, useState } from 'react';
|
|
import { Playlist } from './types';
|
|
import { getPlaylist } from './api';
|
|
|
|
export function usePlaylist(playlistId?: number) {
|
|
const [playlist, setPlaylist] = useState<Playlist>({ items: [], interval: '5m', name: '' });
|
|
const [loading, setLoading] = useState<boolean>(true);
|
|
|
|
useEffect(() => {
|
|
const initPlaylist = async () => {
|
|
if (!playlistId) {
|
|
setLoading(false);
|
|
return;
|
|
}
|
|
const list = await getPlaylist(playlistId);
|
|
setPlaylist(list);
|
|
setLoading(false);
|
|
};
|
|
initPlaylist();
|
|
}, [playlistId]);
|
|
|
|
return { playlist, loading };
|
|
}
|
|
|