From ae3f2015f29e89117f1198ff367312e111b79b0e Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 5 Sep 2024 13:04:15 -0500 Subject: [PATCH] WIP --- src/lib/geo.ts | 25 +++++++++++++++++++++++++ src/state/events.ts | 8 ++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/lib/geo.ts diff --git a/src/lib/geo.ts b/src/lib/geo.ts new file mode 100644 index 0000000000..a51debc449 --- /dev/null +++ b/src/lib/geo.ts @@ -0,0 +1,25 @@ +import {emitGeoUpdated} from '#/state/events' + +let geo: any + +export async function resolveGeo() { + const req = new Promise(y => { + setTimeout(() => { + try { + geo = {country_code: 'US'} + emitGeoUpdated({geo}) + } catch (e) { + } finally { + y(0) + } + }, 1000) + }) + + if (!geo) { + await req + } +} + +export function getGeo() { + return geo +} diff --git a/src/state/events.ts b/src/state/events.ts index dcd36464ec..08536e5062 100644 --- a/src/state/events.ts +++ b/src/state/events.ts @@ -45,3 +45,11 @@ export function listenPostCreated(fn: () => void): UnlistenFn { emitter.on('post-created', fn) return () => emitter.off('post-created', fn) } + +export function emitGeoUpdated({geo}: {geo: any}) { + emitter.emit('geo-updated', geo) +} +export function listenGeoUpdated(fn: ({geo}: {geo: any}) => void): UnlistenFn { + emitter.on('geo-updated', fn) + return () => emitter.off('geo-updated', fn) +}