Skip to main content
useFlightEvents provides access to the live flight event log. It hydrates from GET /api/flight-events on mount, then subscribes to flight:event Socket.io events to append new events as they arrive. Comment mutations (add, edit, delete) use optimistic updates.

Import

import { useFlightEvents } from "@skyvexsoftware/stratos-sdk";

Signature

function useFlightEvents(
  options?: UseFlightEventsOptions
): UseFlightEventsReturn

type UseFlightEventsOptions = {
  flightId?: string | number | null;
  categories?: EventCategory[];
};

type UseFlightEventsReturn = {
  events: FlightLogEvent[];
  isTracking: boolean;
  isLoading: boolean;
  addComment: (message: string) => void;
  editComment: (id: string, message: string) => void;
  deleteComment: (id: string) => void;
};

Parameters

ParameterTypeDescription
options.flightIdstring | number | nullFilter events to a specific flight. Defaults to the current active flight.
options.categoriesEventCategory[]Filter events by category. If omitted, all categories are returned.

Return value

FieldTypeDescription
eventsFlightLogEvent[]Ordered array of flight events (filtered if categories was provided)
isTrackingbooleanWhether a flight is currently active
isLoadingbooleanTrue during the initial REST fetch
addComment(message: string) => voidAdd a pilot comment event to the current flight
editComment(id: string, message: string) => voidEdit an existing comment (optimistic update)
deleteComment(id: string) => voidDelete a comment (optimistic update)

FlightLogEvent

type FlightLogEvent = {
  eventId: string;
  category: EventCategory;
  message: string;
  timestamp: number;
  phase: FlightPhase;
};

EventCategory enum

enum EventCategory {
  SYSTEM   = "system",   // Simulator connection, tracking start/end
  PHASE    = "phase",    // Flight phase transitions
  CONTROLS = "controls", // Gear, flaps, reverser events
  WARNING  = "warning",  // Stall, overspeed, crash detection
}
Note: there is no INFO category. Pilot comments are stored as SYSTEM events with a distinct source flag.

Usage

import { useFlightEvents } from "@skyvexsoftware/stratos-sdk";

export function EventLog() {
  const { events, isLoading, addComment } = useFlightEvents();

  if (isLoading) return <p>Loading events...</p>;

  return (
    <div>
      <ul>
        {events.map((event) => (
          <li key={event.eventId}>
            [{event.category}] {event.message}
          </li>
        ))}
      </ul>
      <button onClick={() => addComment("Cruising at FL350")}>
        Add Comment
      </button>
    </div>
  );
}

Filtering by category

import { useFlightEvents, EventCategory } from "@skyvexsoftware/stratos-sdk";

// Show only phase transitions and warnings
const { events } = useFlightEvents({
  categories: [EventCategory.PHASE, EventCategory.WARNING],
});

Editing and deleting comments

const { events, editComment, deleteComment } = useFlightEvents();

const commentEvents = events.filter((e) => e.category === EventCategory.SYSTEM);

commentEvents.forEach((event) => {
  // Edit: fires a PUT to /api/flight-events/comments/:id with optimistic update
  editComment(event.eventId, "Updated message");

  // Delete: fires a DELETE to /api/flight-events/comments/:id with optimistic removal
  deleteComment(event.eventId);
});

Notes

  • New events arriving via Socket.io are appended to the end of the events array without invalidating or refetching the full query.
  • addComment does not use an optimistic update — the new comment event arrives via the flight:event Socket.io broadcast and is appended automatically.
  • editComment and deleteComment apply optimistic updates immediately and roll back on API error.
  • The staleTime: Infinity setting means events are never automatically re-fetched in the background.