Files
TREK/client/src/components/Dashboard/useCollectionLists.ts
T
Maurice 18eeb16aa0 refactor(dashboard): share the widget logic and plugin hooks between desktop and phone
The currency converter, the world clocks, the collection lists, the plugin widgets and card badges and the card date format each existed once per dashboard. They now live in useCurrencyConverter, useDashboardTimezones, useCollectionLists, useDashboardPlugins and dashboardModel; the phone keeps aborting a pending rate request through an option.
2026-10-09 15:19:50 +02:00

30 lines
790 B
TypeScript

import type { Collection } from '@trek/shared';
import { useEffect, useState } from 'react';
import { collectionsApi } from '../../api/collections';
/** The user's saved-place lists for the dashboard widgets, loaded once on mount. */
export function useCollectionLists() {
const [lists, setLists] = useState<Collection[]>([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
let cancelled = false;
void (async () => {
try {
const data = await collectionsApi.list();
if (!cancelled) setLists(data.collections);
} catch {
if (!cancelled) setLists([]);
} finally {
if (!cancelled) setLoading(false);
}
})();
return () => {
cancelled = true;
};
}, []);
return { lists, loading };
}