mirror of
https://github.com/grafana/grafana.git
synced 2025-02-10 23:55:47 -06:00
* WIP: initial commit * Playlist: Migrates New/Edit to React * Tests: adds tests for PlaylistForm * Tests: adds more tests * Chore: moved some styles * Chore: updates after PR review
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 };
|
|
}
|