sitesmith: null-safe esc() in Navbar/Menu/Logo + clear chat button

The prior null-safe esc patch only matched 'const esc =' declarations;
Menu/Navbar/Logo use 'function esc(str: string)' syntax and slipped
through. Patched those three to coerce non-strings the same way.

Added "Clear chat" button in the modal header that appears when there's
any message history. Confirms with the user before posting to the new
clear_history endpoint, which deletes all messages + the thread row
for the current site (usage rows are preserved for billing).
This commit is contained in:
2026-05-24 16:03:02 -07:00
parent 069ea1235a
commit 906695379b
5 changed files with 42 additions and 7 deletions
+18 -1
View File
@@ -49,5 +49,22 @@ export function useSitesmith(siteId: number) {
return j;
}, [whpConfig, siteId, fetchHistory, refreshEntitlement]);
return { summary, messages, loading, error, send, refreshEntitlement };
const clearHistory = useCallback(async (): Promise<{ ok: boolean; cleared?: number; error?: string }> => {
if (!whpConfig) return { ok: false, error: 'No WHP config' };
try {
const r = await fetch(`${apiBase(whpConfig.apiUrl)}?action=clear_history`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': whpConfig.csrfToken },
body: JSON.stringify({ site_id: siteId }),
});
const j = await r.json();
if (j.ok) setMessages([]);
return j;
} catch (e: any) {
return { ok: false, error: String(e?.message ?? e) };
}
}, [whpConfig, siteId]);
return { summary, messages, loading, error, send, refreshEntitlement, clearHistory };
}