Files
gods-eye-view/src/ui/locationSearch.js
T
Manjunath PaparajuandSameh Khamis a3f4af91f8 Add the Omnibar: one field above the footer for places, layers and commands
On desktop the dock becomes one search bar (Omnibar.vue) that shows the
rows the line-reading pipeline makes: places with nearby suggestions,
coordinates, map items, layers, commands, plans such as "go to Austin and
show flights", guided walks through the real controls, and Ask GEV for
questions. Enter runs only what the line asks for outright. The map
credits move below the bar onto the Power Up row, the voice waveform
shows in the bar while voice is on, and the dock's Location and Visual
trays are hidden in this layout. The phone layout is unchanged. Long
place names are kept out of automatic Ask GEV.

Co-authored-by: Sameh Khamis <[email protected]>
2026-11-18 15:00:06 -08:00

150 lines
4.1 KiB
JavaScript

import { createStateChannel } from '../app/stateChannel.js';
/** One cancellable place lookup at a time, under the caller's camera authority. */
export class LocationSearch {
constructor({
input,
setSearching = () => {},
begin,
isCurrent,
beforeFly,
search,
onStart,
onResult,
onMissing,
onError,
onSettled,
}) {
Object.assign(this, {
input,
setSearching,
begin,
isCurrent,
beforeFly,
search,
onStart,
onResult,
onMissing,
onError,
onSettled,
});
this.controller = null;
this.generation = 0;
this.destroyed = false;
this.state = {
status: 'idle',
searching: false,
query: '',
generation: null,
requestId: 0,
destination: null,
error: null,
};
this.channel = createStateChannel(() => this.state);
}
getState() {
return this.channel.getSnapshot();
}
subscribe(listener, options) {
return this.channel.subscribe(listener, options);
}
async run(query) {
query = String(query || '').trim();
if (!query || this.destroyed) return;
const authority = this.begin();
if (authority === false) {
this.setSearching(false);
this.input?.blur();
return;
}
this.controller?.abort();
const controller = new AbortController();
this.controller = controller;
const generation = ++this.generation;
const current = () =>
!this.destroyed &&
generation === this.generation &&
this.isCurrent(authority);
const change = (type) => ({
type,
generation: authority,
requestId: generation,
query,
});
this.state = {
status: 'searching',
searching: true,
query,
generation: authority,
requestId: generation,
destination: null,
error: null,
};
try {
this.onStart?.(authority);
if (!current() || controller.signal.aborted) return;
this.setSearching(true);
this.channel.publish(change('started'));
if (!current() || controller.signal.aborted) return;
const destination = await this.search(query, {
signal: controller.signal,
beforeFly: () => current() && this.beforeFly(authority),
});
if (!current() || controller.signal.aborted) return;
if (destination?.cancelled) return;
if (destination) {
this.onResult?.(destination, query);
if (!current() || controller.signal.aborted) return;
this.state = {
...this.state,
status: 'found',
destination: { ...destination },
};
this.channel.publish(change('found'));
// Found and still the current search: a plan may go on.
return current() && !controller.signal.aborted;
} else {
this.onMissing?.();
if (!current() || controller.signal.aborted) return;
this.state = { ...this.state, status: 'missing' };
this.channel.publish(change('missing'));
}
} catch (error) {
if (controller.signal.aborted || !current()) return;
this.onError?.(error);
if (!current() || controller.signal.aborted) return;
this.state = {
...this.state,
status: 'failed',
error: { message: String(error?.message || error) },
};
this.channel.publish(change('failed'));
} finally {
if (this.controller === controller) this.controller = null;
if (!this.destroyed) {
if (generation === this.generation)
this.state = {
...this.state,
searching: false,
status:
this.state.status === 'searching'
? 'cancelled'
: this.state.status,
};
this.onSettled?.(authority);
this.channel.publish(change('settled'));
}
}
}
destroy() {
if (this.destroyed) return;
this.destroyed = true;
this.generation++;
this.controller?.abort();
this.controller = null;
this.state = { ...this.state, status: 'disposed', searching: false };
this.channel.getSnapshot();
this.channel.destroy();
}
}