19 lines
598 B
TypeScript
19 lines
598 B
TypeScript
|
|
import { useEffect, useState } from 'react';
|
||
|
|
import { getAlbums, getPhotoTiles } from '../api/photos';
|
||
|
|
import type { Album, PhotoScope, PhotoTile } from '../types';
|
||
|
|
|
||
|
|
const SCOPES: PhotoScope[] = ['Tout', 'Personnes', 'Lieux'];
|
||
|
|
|
||
|
|
export function usePhotos() {
|
||
|
|
const [albums, setAlbums] = useState<Album[]>([]);
|
||
|
|
const [tiles, setTiles] = useState<PhotoTile[]>([]);
|
||
|
|
const [scope, setScope] = useState<PhotoScope>('Tout');
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
void getAlbums().then(setAlbums);
|
||
|
|
void getPhotoTiles().then(setTiles);
|
||
|
|
}, []);
|
||
|
|
|
||
|
|
return { albums, tiles, scopes: SCOPES, scope, setScope };
|
||
|
|
}
|