[app] Rose: Wire identity and the care log into the garden; e2e and offline tend the rose
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@rosea/content": "workspace:*",
|
||||
"@rosea/identity": "workspace:*",
|
||||
"@rosea/schema": "workspace:*",
|
||||
"@rosea/storage": "workspace:*",
|
||||
"@rosea/ui": "workspace:*"
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
<script lang="ts">
|
||||
import { guessTown } from '@rosea/content/guess';
|
||||
import { openProfile } from '@rosea/storage';
|
||||
import { Shell, type SunsetWiring } from '@rosea/ui';
|
||||
import { createIdentity } from '@rosea/identity';
|
||||
import { openStorage } from '@rosea/storage';
|
||||
import { Shell, type RoseWiring, type SunsetWiring } from '@rosea/ui';
|
||||
import { version } from '../package.json';
|
||||
// Bundled at build time, so the letter is precached and opens offline (letter-slot.md L1).
|
||||
import letter from '../../../docs/LETTER.md?raw';
|
||||
|
||||
// The device's own zone, read here and nowhere else: the engine never asks the
|
||||
// device anything (CLAUDE.md §2). Only the zone's name; never GPS, never a lookup.
|
||||
const deviceZone = new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
const profile = openProfile();
|
||||
const storage = openStorage();
|
||||
|
||||
// The town list is large, so it loads on the first search (sunset-place.md P5).
|
||||
// A failed load is forgotten, so the next keystroke tries again.
|
||||
@@ -22,10 +24,38 @@
|
||||
const sunset: SunsetWiring = {
|
||||
guess: guessTown(deviceZone),
|
||||
search: async (query) => (await loadTowns()).searchTowns(query),
|
||||
load: () => profile.loadSunsetPlace(),
|
||||
save: (choice) => profile.saveSunsetPlace(choice),
|
||||
load: () => storage.loadSunsetPlace(),
|
||||
save: (choice) => storage.saveSunsetPlace(choice),
|
||||
now: () => Date.now()
|
||||
};
|
||||
|
||||
// The player's key names their rose (rose.md). Kept once; if the device will not
|
||||
// keep it, this visit still has a rose, under a key that lasts until closing.
|
||||
let identity: ReturnType<RoseWiring['identity']> | undefined;
|
||||
async function findIdentity(): ReturnType<RoseWiring['identity']> {
|
||||
try {
|
||||
const kept = await storage.loadIdentity();
|
||||
if (kept) return { publicKey: kept.publicKey, kept: true };
|
||||
} catch (error) {
|
||||
console.error('identity: the device could not read the kept key', error);
|
||||
}
|
||||
const fresh = await createIdentity();
|
||||
try {
|
||||
return { publicKey: (await storage.keepIdentity(fresh)).publicKey, kept: true };
|
||||
} catch (error) {
|
||||
console.error('identity: the device could not keep the key; this visit uses one that lasts until closing', error);
|
||||
return { publicKey: fresh.publicKey, kept: false };
|
||||
}
|
||||
}
|
||||
|
||||
const rose: RoseWiring = {
|
||||
identity: () => (identity ??= findIdentity()),
|
||||
loadCare: () => storage.loadCare(),
|
||||
appendCare: (event) => storage.appendCare(event),
|
||||
clientVersion: version,
|
||||
deviceZone,
|
||||
now: () => Date.now()
|
||||
};
|
||||
</script>
|
||||
|
||||
<Shell {letter} {sunset} />
|
||||
<Shell {letter} {sunset} {rose} />
|
||||
|
||||
Reference in New Issue
Block a user