0
2
next: a tab takes one click to its root, and back steps up where it should
Only what this pull adds. It is built on The next grain.social and grain-ios, drawn by HUD.
vendor/hud/web/shell/src/Pager.svelte+2−2
| @@ -39,8 +39,8 @@ | ||
/** A page's call made, and what it answered. */ | ||
load: (call: Call) => Promise<Page>; | ||
onaction: ActionHandler; | ||
/** A page's form's tools (a story added, a report). */ | ||
ontool: UiToolHandler; | ||
/** A page's form's tools (a story added, a report); none signed out, so it offers none. */ | ||
ontool?: UiToolHandler; | ||
/** A page's form's photos uploaded; none signed out. */ | ||
onupload?: UiUploadHandler; | ||
/** A call opened from a page: a sheet over it, or else the pager closes and the app opens it. */ | ||
vendor/hud/web/shell/src/server.ts+10−4
| @@ -34,9 +34,11 @@ async function answer(hud: Caller, call: Call, names: Names): Promise<Answer> { | ||
/** | ||
* The page at a URL, as the app's routes say (routes.ts), answered by HUD | ||
* for the page to draw: a tab's root at the tab's own URL; a route's | ||
* screen that is a tab's root (signed in or out) as that tab; any other | ||
* over the root of the tab its route names (the first, where it names | ||
* none). As the app in the browser draws a URL it has no history of. With | ||
* screen that is a tab's root (signed in or out) as that tab, or that is | ||
* by the account its answer names (the account's own profile, the | ||
* Profile tab's `me`); any other over the root of the tab its route | ||
* names (the first, where it names none). As the app in the browser | ||
* draws a URL it has no history of. With | ||
* it, what the root under it answers (streamed), and its status (404 | ||
* where no route has its path, 502 where HUD could not answer). | ||
*/ | ||
| @@ -59,10 +61,14 @@ export async function screenAt(app: App, url: URL, hud: Caller, signedIn: boolea | ||
if (tab < 0) [tab, screen] = [Math.max(0, app.tabs.findIndex((t) => t.label === found.tab)), found.call]; | ||
} | ||
const root = tabCall(app.tabs[tab], signedIn); | ||
const calls = [...(root ? [root] : []), ...(screen ? [screen] : [])]; | ||
let calls = [...(root ? [root] : []), ...(screen ? [screen] : [])]; | ||
const last = calls.at(-1); | ||
const aside = app.frame?.aside?.call; | ||
const [top, beside] = await Promise.all([last ? answer(hud, last, names) : null, aside ? answer(hud, aside, names) : null]); | ||
// A screen that is a tab's own, by the account its answer named (`/profile/<own handle>`, the Profile tab's `me`): that tab, at its root, drawn from the same answer. | ||
const own = screen ? app.tabs.findIndex((t) => tabPath(app, t, names) === url.pathname) : -1; | ||
const ownRoot = own >= 0 ? tabCall(app.tabs[own], signedIn) : null; | ||
if (ownRoot) [tab, calls] = [own, [ownRoot]]; | ||
// The root under a screen does not show: it streams after the page. | ||
const under = calls.length > 1 ? answer(hud, calls[0], new Names()) : null; | ||
const status = top && 'failed' in top ? 502 : 200; | ||
vendor/hud/web/shell/src/Shell.svelte+35−8
| @@ -44,10 +44,13 @@ | ||
| ||
// An app as a phone app is laid out, framed by its app file's `frame` | ||
// (frame.ts): its tabs, each a nav stack of its own, drawn once first | ||
// chosen and kept as it was left; chosen again, the screen it shows is | ||
// made again, drawn as it was meanwhile (Stack.svelte). Choosing the tab | ||
// on screen again goes back to its root, and at its root asks its call | ||
// afresh. Signed in, a tab with a `badge` shows its count on its icon, | ||
// chosen. Choosing a tab shows its root, as its link says, the screens | ||
// left over it let go and its root made again, drawn as it was | ||
// meanwhile (Stack.svelte); choosing it again at its root asks its call | ||
// afresh. A screen that is a tab's own (a link to the account's own | ||
// profile, its URL) is that tab, chosen, never a copy pushed over | ||
// another tab; and a screen opened over itself is not pushed again. | ||
// Signed in, a tab with a `badge` shows its count on its icon, | ||
// as the server read it for the page, then when the window is focused | ||
// again and each minute it is shown, cleared as the tab is opened (its | ||
// list marks what it shows seen); the account's picture (the frame's | ||
| @@ -343,15 +346,28 @@ | ||
reading.forget(); | ||
} | ||
| ||
/** A tab chosen: its root, as its link says, made again where it answered a while ago; the tab on show, chosen again at its root, asks its call afresh. */ | ||
async function choose(i: number) { | ||
searching = false; | ||
if (i === current) return stacks[i]?.home(); | ||
const again = opened.has(i); | ||
await show(i); | ||
if (again) stacks[i]?.shown(); | ||
if (again) stacks[i]?.rooted(); | ||
moved(i, 'jump'); | ||
} | ||
| ||
/** The tab whose own URL a path is (Profile's, the account's own profile), or -1. */ | ||
const tabAt = (path: string) => app.tabs.findIndex((t) => tabPath(app, t, names) === path); | ||
| ||
/** A call a screen opens that is a tab's own screen: that tab chosen in its place; whether it was. */ | ||
function ontab(call: Call): boolean { | ||
const href = call.args.compose === undefined ? routed(call) : null; | ||
const tab = href ? tabAt(href) : -1; | ||
if (tab < 0) return false; | ||
void choose(tab); | ||
return true; | ||
} | ||
| ||
/** Back a step: the browser's, where the entry before is the screen under this one. */ | ||
function back() { | ||
const here = navigation.here; | ||
| @@ -373,12 +389,20 @@ | ||
}); | ||
}); | ||
| ||
/** A call opened as a screen over the tab `tab`'s, a step on from where it is: where it opens a form (`compose`), that form opens once, as the screen does. */ | ||
/** A call opened as a screen over the tab `tab`'s, a step on from where it is (from its root, on a tab not on show), unless that is the screen on top already: where it opens a form (`compose`), that form opens once, as the screen does. */ | ||
async function openOn(tab: number, call: Call) { | ||
searching = false; | ||
const was = current; | ||
await show(tab); | ||
const under = stacks[tab]?.place().calls ?? []; | ||
const all = stacks[tab]?.place().calls ?? []; | ||
const under = tab === was ? all : all.slice(0, 1); | ||
const top = under.at(-1); | ||
if (top && same(top, call)) { | ||
if (tab === was) return; | ||
stacks[tab]?.rooted(); | ||
moved(tab, 'jump'); | ||
return; | ||
} | ||
const place: Place = { calls: [...under, call], pager: null }; | ||
stacks[tab]?.sync(place); | ||
void enter(tab, place, tab === was ? 'open' : 'jump'); | ||
| @@ -390,9 +414,11 @@ | ||
return openOn(named < 0 ? current : named, found.call); | ||
} | ||
| ||
/** A path of the app's (with its query) opened as a screen, by its routes: on its route's tab, else over the tab on screen. */ | ||
/** A path of the app's (with its query) opened as a screen: a tab's own URL as that tab, else by its routes, on its route's tab, else over the tab on screen. */ | ||
async function visit(url: string) { | ||
const at = new URL(url, location.origin); | ||
const tab = tabAt(at.pathname + at.search); | ||
if (tab >= 0) return choose(tab); | ||
const found = await callOf(at.pathname, at.search, app.routes, resolve); | ||
if (found) await openAt(found); | ||
} | ||
| @@ -578,6 +604,7 @@ | ||
onwrote={wrote} | ||
onmove={(how) => moved(i, how)} | ||
onback={back} | ||
{ontab} | ||
onsignedout={() => { | ||
gone(); | ||
signedIn = false; | ||
vendor/hud/web/shell/src/Stack.svelte+28−7
| @@ -94,7 +94,8 @@ | ||
onsignedout, | ||
onmove, | ||
onback, | ||
onsignout | ||
onsignout, | ||
ontab | ||
}: { | ||
/** The call at the stack's root; null asks to sign in. */ | ||
root: Call | null; | ||
| @@ -136,6 +137,8 @@ | ||
onback: () => void; | ||
/** A view's Sign out asked for (`{ host: 'signOut' }`): the app signs out. */ | ||
onsignout: () => void; | ||
/** A call a screen opens that is a tab's own screen (the account's own profile): the app chooses that tab in its place, and says whether it did. */ | ||
ontab: (call: Call) => boolean; | ||
} = $props(); | ||
| ||
let nextId = 0; | ||
| @@ -340,22 +343,31 @@ | ||
return entry.view.renderer === 'tree' ? { ...entry, view: { ...entry.view, ui: unopened(entry.view.ui) } } : entry; | ||
} | ||
| ||
/** A step up, where the browser's back is not one: the sheet closed, or the pager, or the top level left; the screen shown again made again. */ | ||
/** A step up, where the browser's back is not one (the screen under was not the entry before: a screen opened on another tab, a page loaded): the sheet closed, or the pager, or the top level left, in place of the history entry on show, so the browser's back still goes where it went; the screen shown again made again. */ | ||
export function up() { | ||
void feedback.flush(); | ||
if (sheet) sheet = null; | ||
else if (pager) pager = null; | ||
else if (levels.length > 1) levels = levels.slice(0, -1); | ||
else return; | ||
onmove('jump'); | ||
onmove('replace'); | ||
revalidate(levels.at(-1)); | ||
} | ||
| ||
/** The stack's tab chosen again: the screen it shows made again. */ | ||
/** The top screen made again (unless it answered a moment ago): a write done over it. */ | ||
export function shown() { | ||
revalidate(sheet ?? levels.at(-1)); | ||
} | ||
| ||
/** The stack's tab chosen: back to its root, the sheet and pager closed and the screens over it let go, the root made again unless it answered a moment ago. The app makes the history entry. */ | ||
export function rooted() { | ||
void feedback.flush(); | ||
sheet = null; | ||
pager = null; | ||
if (levels.length > 1) levels = levels.slice(0, 1); | ||
revalidate(levels[0]); | ||
} | ||
| ||
/** The account wrote: every level's answer is old, made again as it shows, and at once for those under the screen on top, which drew the write itself. */ | ||
export function stale() { | ||
wrote = Date.now(); | ||
| @@ -460,11 +472,20 @@ | ||
return answered(result); | ||
}; | ||
| ||
/** Open a call from a level, telling its feed the item was opened: one of a List of `pages` in a pager of them all, a `sheet` one as a sheet over what is open. From the sheet, the sheet and the pager close and it opens in their place. */ | ||
/** Open a call from a level, telling its feed the item was opened: one of a List of `pages` in a pager of them all, a `sheet` one as a sheet over what is open; a tab's own screen as that tab (`ontab`); the screen on top again, nothing. From the sheet, the sheet and the pager close and it opens in their place. */ | ||
function open(level: Level, made: Call, item: UiReport | null, sequence?: UiSequence, asSheet = false) { | ||
const to = level.entry && feedOf(level.entry.view); | ||
const opened = to?.signedIn && item !== null ? to.of(CLICKTHROUGH, item) : null; | ||
if (to && opened) feedback.add(to.feed, opened); | ||
if (!asSheet && !sequence) { | ||
const top = levels.at(-1); | ||
if (made.args.compose === undefined && !sheet && top?.id === level.id && same(made, top.call)) return; | ||
if (ontab(made)) { | ||
sheet = null; | ||
pager = null; | ||
return; | ||
} | ||
} | ||
const fromSheet = level.id === sheet?.id; | ||
if (asSheet && !fromSheet) return openSheet(made); | ||
if (fromSheet) { | ||
| @@ -525,7 +546,7 @@ | ||
paging={paged && ownsPaging(entry) ? { load: () => void loadMore(level), loading: level.more.loading, error: level.more.error } : null} | ||
onreload={() => reload(level)} | ||
onleave={() => leave(level)} | ||
ontool={tool} | ||
ontool={signedIn ? tool : undefined} | ||
onupload={signedIn ? client.uploadBlob : undefined} | ||
onhost={signedIn ? onsignout : undefined} | ||
pending={level.slow && !current(level)} | ||
| @@ -603,7 +624,7 @@ | ||
return { view: entry.view, signIn }; | ||
}} | ||
onaction={act} | ||
ontool={tool} | ||
ontool={signedIn ? tool : undefined} | ||
onupload={signedIn ? client.uploadBlob : undefined} | ||
held={sheet !== null} | ||
onopen={(call, asSheet) => { | ||
vendor/hud/COMMIT+1−1
| @@ -1 +1 @@ | ||
969d9b5573ab10c4eb291de9b6f81aac9af1016b | ||
21ca3878c76a326e5d626c653dfd9c7f929a9e3e | ||