Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

790 B
Raw Blame
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 };
}