All files / applications/go-by-transit/src/view/nearby/components PlacesLoadStatus.tsx

100% Statements 6/6
83.33% Branches 5/6
100% Functions 6/6
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70                                        16950x 44x             5x                               10029x                     220x                            
import {
  LoadStatus,
  type LoadIssue as GenericLoadIssue,
} from "@wintermuted/ui-react";
import React from "react";
import FontAwesome from "react-fontawesome";
import {
  categoryName,
  PLACE_CATEGORIES,
  PlaceCategory,
  PlaceSourceState,
} from "@overworld/places/catalog";
import PlacesHelp from "./PlacesHelp";
 
export type LoadIssue = GenericLoadIssue & { label: string };
 
export function placeSourceIssues(
  sources: Record<PlaceCategory, PlaceSourceState>,
  onRetry: (category: PlaceCategory) => void,
): LoadIssue[] {
  return PLACE_CATEGORIES.filter((category) => sources[category].error).map(
    (category) => ({
      label: categoryName(category),
      message: `${categoryName(category)} could not be loaded.${
        sources[category].snapshot
          ? " The previously loaded snapshot is still shown."
          : " Other available places remain usable."
      }`,
      retry: () => onRetry(category),
    }),
  );
}
 
export default function PlacesLoadStatus({
  label,
  issues,
  loading = false,
  warnings = [],
}: {
  label: string;
  issues: LoadIssue[];
  loading?: boolean;
  warnings?: string[];
}) {
  return (
    <LoadStatus
      issues={issues}
      warnings={warnings}
      loading={loading}
      className={`transit-places-load-status${issues.length ? "" : " transit-places-load-status--warning"}`}
      labels={{
        retry: `Retry ${label.toLowerCase()}`,
        loading: `Loading ${label.toLowerCase()}...`,
      }}
      renderHelp={({ message, tone }) => (
        <PlacesHelp
          label={label}
          triggerLabel={`${label} ${tone}`}
          icon="exclamation-triangle"
          text={message}
        />
      )}
      retryIcon={
        <FontAwesome name="refresh" spin={loading} aria-hidden="true" />
      }
      loadingIcon={<FontAwesome name="spinner" spin aria-hidden="true" />}
    />
  );
}