mirror of
https://github.com/bitbaum/substrata.git
synced 2026-12-04 14:18:33 +01:00
* feat(home): the homepage, rebuilt ask-first The hero is the Ask box (chatkit composer plus four questions, one built from the worst bottleneck); sending opens /chat with the question started. Worst right now is one row component with a fixed gauge column; what changed falls back to the sweep's unchecked finds or is absent, never an empty box; the numbers are four equal linked cells; doors share one anatomy; the footer is calm. The page is served from a 60 second cache: the shell learns its reader from /api/me in the browser instead of reading the session while rendering. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE * fix(home): centred column, aligned worst rows, broken-word scan Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE --------- Co-authored-by: Claude <noreply@anthropic.com>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
|
|
import type { Reader } from '@/components/portal/AccountMenuView';
|
|
|
|
let inFlight: Promise<Reader> | null = null;
|
|
|
|
/** One request per page load, however many components ask. */
|
|
function readReader(): Promise<Reader> {
|
|
inFlight ??= fetch('/api/me', { cache: 'no-store' })
|
|
.then((r) => {
|
|
if (!r.ok) throw new Error(String(r.status));
|
|
return r.json() as Promise<Reader>;
|
|
})
|
|
.catch(() => {
|
|
inFlight = null;
|
|
// Unreachable means anonymous: the research is public, the menu is not.
|
|
return { signedIn: false, name: null, image: null, reviewer: false, authEnabled: false };
|
|
});
|
|
return inFlight;
|
|
}
|
|
|
|
/**
|
|
* Who is reading, learned in the browser — for a page served from a cache,
|
|
* which cannot read the session. `null` until the answer arrives (and when
|
|
* `enabled` is false, so a page that did read the session pays nothing).
|
|
*/
|
|
export function useReader(enabled: boolean): Reader | null {
|
|
const [reader, setReader] = useState<Reader | null>(null);
|
|
useEffect(() => {
|
|
if (!enabled) return;
|
|
let live = true;
|
|
void readReader().then((r) => live && setReader(r));
|
|
return () => {
|
|
live = false;
|
|
};
|
|
}, [enabled]);
|
|
return reader;
|
|
}
|