Tooltips in the Notebooks chooser
From the development repository at e819bc4. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
fcd6117618
commit
87ba7fc776
10 files changed
+220
-24
No files matched your search
+30
-3
@@ -29,6 +29,13 @@ const LONGEST_WAIT_MS = 2000;
|
||||
/** After a write fails, try again this much later. */
|
||||
const RETRY_MS = 3000;
|
||||
|
||||
/**
|
||||
* A page file in a notebook.
|
||||
* @typedef {object} KeptPage
|
||||
* @property {string} name
|
||||
* @property {number} changed When it was last written, in milliseconds since the epoch.
|
||||
*/
|
||||
|
||||
/**
|
||||
* What keeps the notebooks: the local program's files, or the browser.
|
||||
* @typedef {object} Backend
|
||||
@@ -37,7 +44,7 @@ const RETRY_MS = 3000;
|
||||
* @property {() => Promise<{directory: string, notebooks: string[], trash: boolean}>} listNotebooks
|
||||
* The directory is '' when the notebooks are in the browser; trash
|
||||
* says whether a deleted notebook or page goes to one, or is gone for good.
|
||||
* @property {(notebook: string) => Promise<string[]>} listPages Every page file, Current.svg too.
|
||||
* @property {(notebook: string) => Promise<KeptPage[]>} listPages Every page file, Current.svg too.
|
||||
* @property {(notebook: string, pageName: string) => Promise<string | null>} readPage
|
||||
* @property {(notebook: string, pageName: string, text: string) => Promise<void>} writePage
|
||||
* @property {(notebook: string) => Promise<{kept: string | null, new: boolean}>} keepPage
|
||||
@@ -101,7 +108,8 @@ const inFiles = /** @type {Backend} */ ({
|
||||
async listPages(notebook) {
|
||||
const response = await request('GET', [notebook]);
|
||||
if (!response.ok) throw new Error(`The notebook “${notebook}” cannot be read.`);
|
||||
return (await response.json()).pages;
|
||||
const { pages, changed } = await response.json();
|
||||
return pages.map((/** @type {string} */ name) => ({ name, changed: changed?.[name] ?? 0 }));
|
||||
},
|
||||
async readPage(notebook, pageName) {
|
||||
const response = await request('GET', [notebook, pageName]);
|
||||
@@ -189,8 +197,27 @@ export function discardPage(notebook, pageName) {
|
||||
* notebook, in order; not the page being written.
|
||||
*/
|
||||
export async function listKeptPages(notebook) {
|
||||
return (await listKeptPageDetails(notebook)).map((page) => page.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} notebook
|
||||
* @returns {Promise<KeptPage[]>} The pages kept in the notebook, in
|
||||
* order, with when each was last changed; not the page being written.
|
||||
*/
|
||||
export async function listKeptPageDetails(notebook) {
|
||||
const pages = await backend.listPages(notebook);
|
||||
return pages.filter((name) => name !== CURRENT_PAGE);
|
||||
return pages.filter((page) => page.name !== CURRENT_PAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} notebook
|
||||
* @returns {Promise<number>} When the page being written in the notebook
|
||||
* was last written, in milliseconds since the epoch, or 0 if there is none.
|
||||
*/
|
||||
export async function currentPageChanged(notebook) {
|
||||
const pages = await backend.listPages(notebook);
|
||||
return pages.find((page) => page.name === CURRENT_PAGE)?.changed ?? 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user