Get started

Segment and waypoint lists

The studio's sidebar lists, published on their own. Reach for them when a narrow column suits the page better than a table.

src/ItineraryLists.tsx
/// <reference types="vite/client" />
import { Mountaya } from "@mountaya/client/browser";
import { MountayaProvider, useItinerary } from "@mountaya/client-react";
import { MountayaElementsProvider } from "@mountaya/elements-react/headless";
import { createUiStore } from "@mountaya/studio";
import { ReadOnlySegmentList, WaypointList } from "@mountaya/studio-react";
import { StudioProvider } from "@mountaya/studio-react/headless";
import "@mountaya/studio-react/styles.css";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { useState } from "react";

const client = new Mountaya({
  credential: { publishableKey: import.meta.env.VITE_MOUNTAYA_PUBLISHABLE_KEY },
});
const queryClient = new QueryClient();

// One of your published itineraries.
const ITINERARY_ID = "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21";

const Lists = () => {
  const [store] = useState(createUiStore);
  const { data: itinerary } = useItinerary(ITINERARY_ID, { surface: "published" });

  if (itinerary === undefined) return null;

  return (
    <MountayaElementsProvider client={client}>
      <StudioProvider data={{ store }}>
        <ReadOnlySegmentList
          itineraryId={ITINERARY_ID}
          label="Segments"
          segments={itinerary.segments}
        />
        <WaypointList
          iconLabel={(icon) => icon ?? "Waypoint"}
          itineraryId={ITINERARY_ID}
          label="Waypoints"
          readOnly
          renderIconCircle={() => <span aria-hidden className="waypoint-dot" />}
          waypoints={itinerary.waypoints}
        />
      </StudioProvider>
    </MountayaElementsProvider>
  );
};

export const ItineraryLists = () => (
  <QueryClientProvider client={queryClient}>
    <MountayaProvider client={client}>
      <Lists />
    </MountayaProvider>
  </QueryClientProvider>
);

The waypoint list draws no glyph of its own: renderIconCircle and iconLabel draw the marker and name it your way.

Next steps

Last updated