mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
24 lines
630 B
TypeScript
24 lines
630 B
TypeScript
|
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();
|
||
|
}, []);
|
||
|
|
||
|
return { playlist, loading };
|
||
|
}
|