All files / presentation/ui/src TimeDisplaySettings.tsx

100% Statements 8/8
72.72% Branches 8/11
100% Functions 3/3
100% Lines 8/8

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          30x 30x 30x   30x               1x 1x                       1x         1x                                      
import React, { useId } from "react";
import { useTimeDisplay } from "./TimeDisplay";
 
export default function TimeDisplaySettings() {
  const { format, timezone, storageError, setFormat, setTimezone } =
    useTimeDisplay();
  const formatId = useId();
  const timezoneId = useId();
 
  return (
    <fieldset className="transit-time-settings">
      <legend>Time display</legend>
      <label htmlFor={formatId}>Clock</label>
      <select
        id={formatId}
        value={format}
        onChange={event => {
          Eif (event.target.value === "12h" || event.target.value === "24h") {
            setFormat(event.target.value);
          }
        }}
      >
        <option value="12h">12-hour</option>
        <option value="24h">24-hour</option>
      </select>
      <label htmlFor={timezoneId}>Timezone</label>
      <select
        id={timezoneId}
        value={timezone}
        onChange={event => {
          Eif (
            event.target.value === "default" ||
            event.target.value === "local" ||
            event.target.value === "utc"
          ) {
            setTimezone(event.target.value);
          }
        }}
      >
        <option value="default">Current display default</option>
        <option value="local">Device local time</option>
        <option value="utc">UTC</option>
      </select>
      <small>
        Current default: device local time; trip directions use Pacific time.
      </small>
      {storageError && (
        <small role="status">
          Could not save this preference in browser storage.
        </small>
      )}
    </fieldset>
  );
}