Skip to content

Commit

Permalink
handle current location payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
jonesmac committed Nov 25, 2024
1 parent 085cb16 commit 0292e16
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import type { LocationWitnessPayload } from '@xyo-network/api'
import { LocationWitnessSchema } from '@xyo-network/api'
import type { GeographicCoordinateSystemLocationPayload } from '@xyo-network/location-payload-plugin'
import { GeographicCoordinateSystemLocationSchema } from '@xyo-network/location-payload-plugin'
import type { Payload } from '@xyo-network/payload-model'

import { currentLocationToGCS } from './transformers/index.ts'

const validSchemas = {
currentLocation: 'network.xyo.location.current',
gcsLocation: GeographicCoordinateSystemLocationSchema,
}

export const locationPayloadToGCS = (location: Payload) => {
switch (location.schema) {
case LocationWitnessSchema: {
case validSchemas.currentLocation: {
return currentLocationToGCS(location as LocationWitnessPayload)
}
case GeographicCoordinateSystemLocationSchema: {
case validSchemas.gcsLocation: {
return location as GeographicCoordinateSystemLocationPayload
}
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const gcsLocationPayload = {
}

export const currentLocationPayload = {
schema: 'network.xyo.location',
schema: 'network.xyo.location.current',
currentLocation: {
coords: {
accuracy: 600,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const CurrentLocationSchema = 'network.xyo.location.current'
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { GeographicCoordinateSystemLocationSchema, LocationSchema } from '@xyo-network/location-payload-plugin'
import type { Payload } from '@xyo-network/payload-model'
import type { PayloadRenderPluginBase } from '@xyo-network/react-payload-plugin'

const validSchemas: Set<string> = new Set([LocationSchema, GeographicCoordinateSystemLocationSchema])
import { validPointMapSchemas } from './validPointMapSchemas.ts'

const PointMapRenderPluginMeta: PayloadRenderPluginBase = {
canRender: (payload?: Payload) => !!(payload && validSchemas.has(payload.schema)),
canRender: (payload?: Payload) => !!(payload && validPointMapSchemas.has(payload.schema)),
name: 'Point Map',
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { CurrentLocationSchema, GeographicCoordinateSystemLocationSchema } from '@xyo-network/location-payload-plugin'

export const validPointMapSchemas = new Set<string>([CurrentLocationSchema, GeographicCoordinateSystemLocationSchema])

0 comments on commit 0292e16

Please sign in to comment.