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.

2.1 KB
Raw Blame
import { create } from 'zustand'

/**
 * The raw place payload handed to the "Save to Collection" picker. Carries the
 * provenance ids (source_trip_id / source_place_id) when the place originates
 * from a trip, plus the maps identity used both to save and to dedup. Every
 * field is optional except the name so the same target shape works for a trip
 * pool place, a day-assignment place or a manually entered one.
 */
export interface SaveToCollectionTarget {
  name: string
  source_trip_id?: number | null
  source_place_id?: number | null
  description?: string | null
  lat?: number | null
  lng?: number | null
  address?: string | null
  category_id?: number | null
  price?: number | null
  currency?: string | null
  notes?: string | null
  image_url?: string | null
  google_place_id?: string | null
  google_ftid?: string | null
  osm_id?: string | null
  website?: string | null
  phone?: string | null
}

/**
 * A saved tour of a trip to keep in a collection. It goes through the tour's
 * own keep dialog, which copies the tour with its route, never through the
 * place picker, which would keep a bare point.
 */
export interface SaveTourToCollectionTarget {
  tripId: number | string
  placeId: number
  name: string
}

interface SaveToCollectionState {
  /** The place currently shown in the picker, or null when it is closed. */
  target: SaveToCollectionTarget | null
  /** The tour currently shown in the keep dialog, or null when it is closed. */
  tour: SaveTourToCollectionTarget | null
  /** Bumped after every add/remove so other surfaces (the inspector bookmark
   *  indicator) can re-check membership without prop threading. */
  version: number
  open: (target: SaveToCollectionTarget) => void
  close: () => void
  openTour: (tour: SaveTourToCollectionTarget) => void
  closeTour: () => void
  bumpVersion: () => void
}

export const useSaveToCollectionStore = create<SaveToCollectionState>((set, get) => ({
  target: null,
  tour: null,
  version: 0,
  open: (target) => set({ target }),
  close: () => set({ target: null }),
  openTour: (tour) => set({ tour }),
  closeTour: () => set({ tour: null }),
  bumpVersion: () => set({ version: get().version + 1 }),
}))