All files / submodels/goTo model.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

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              4x                   4x             13x          
import { Schema } from 'effect'
import { defineTaggedUnion } from 'foldkit/schema'
 
/**
 * What the last attempt to go somewhere did. Search and "Find my location" share it, because
 * they share one status line and a new attempt of either kind replaces the last one.
 */
export const Status = defineTaggedUnion({
  Idle: {},
  Found: { kind: Schema.String, maybeCaution: Schema.Option(Schema.String) },
  SearchFailed: { reason: Schema.String },
  Locating: { requestId: Schema.Int },
  LocateFailed: { reason: Schema.String },
})
export type Status = typeof Status.Type
 
/** Each location request gets the next id, so a late answer to an earlier request is not taken for the current one. */
export const Model = Schema.Struct({
  query: Schema.String,
  status: Status,
  locateRequestCount: Schema.Int,
})
export type Model = typeof Model.Type
 
export const init = (): Model => ({
  query: '',
  status: Status.Idle(),
  locateRequestCount: 0,
})