Add saved layouts, and make /stp an ordinary canvas page
A layout is a named copy of one canvas page's boxes and background (models.Layout, layout.graphql), saved from the canvas's new Layouts button and loaded onto any page from there or from the admin Pages tab. Loading onto a page with boxes asks whether to replace them or add on top; a replace first saves the page as a "<page> before <layout>" layout so it can be undone. Copies, not links: editing a page never changes a layout or another page. The copying is server-side in one transaction, and everything is @admin since a layout keeps admin-only boxes. /stp loses its static route and becomes a Page with slug "stp", created once at start-up (ensureStpPage), so it can be renamed, hidden or deleted like a shrine. Its boxes were already keyed "stp". Home3.vue is kept as legacy; its starter is now "Old /stp grid" in pageStarters.js. ConfirmDialog gains an optional second button. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* Page backgrounds (the `Background` GraphQL type), one per canvas page key —
|
||||
* "index" for the landing page, "stp", or a Page slug such as
|
||||
* "index" for the landing page, or a Page slug such as "stp" or
|
||||
* "shrines/evangelion" — and which one is on screen.
|
||||
*
|
||||
* DefaultLayout paints `style` behind everything, navbar included, so a
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
* Boxes on one canvas page (views/home3/BoxCanvas.vue) — full CRUD, built on
|
||||
* createCrudStore().
|
||||
*
|
||||
* `useBoxesStore(page)` returns the store for that page key: "stp" for the
|
||||
* home page, "index" for the landing page's overlay, or a Page slug. Each key
|
||||
* `useBoxesStore(page)` returns the store for that page key: "index" for the
|
||||
* landing page, or a Page slug ("stp" for the home page). Each key
|
||||
* gets its own Pinia store (id `boxes:<page>`), so moving between pages
|
||||
* neither refetches a page already visited nor mixes two pages' boxes.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Saved layouts (the `Layout` GraphQL type): named copies of a canvas page's
|
||||
* boxes and background — full CRUD, built on createCrudStore(), plus apply().
|
||||
*
|
||||
* `create({ name, page })` saves that page as it is now; `update` only
|
||||
* renames. What a layout holds never reaches the browser, only its size: the
|
||||
* server does both the copying in and the copying out.
|
||||
*
|
||||
* Admin only, so nothing fetches it until an admin opens a layouts list
|
||||
* (views/home3/LayoutPanel.vue, the admin panel's Pages tab).
|
||||
*/
|
||||
|
||||
import { createCrudStore } from "@/stores/createCrudStore";
|
||||
import { gql } from "@/graphql";
|
||||
import { useBoxesStore } from "@/stores/boxes";
|
||||
import { useBackgroundStore } from "@/stores/background";
|
||||
|
||||
const LAYOUT_FIELDS = `
|
||||
id
|
||||
name
|
||||
sourcePage
|
||||
boxCount
|
||||
hasBackground
|
||||
createdAt
|
||||
`;
|
||||
|
||||
export const useLayoutsStore = createCrudStore("layouts", {
|
||||
type: "Layout",
|
||||
list: "layouts",
|
||||
fields: LAYOUT_FIELDS,
|
||||
// The list query is newest first.
|
||||
insert: "prepend",
|
||||
deleteReturns: "object",
|
||||
extend: ({ fetch }) => ({
|
||||
/**
|
||||
* Copy layout `id` onto page key `page`, replacing what is there or
|
||||
* adding on top. Throws on failure.
|
||||
*/
|
||||
async apply(id, page, replace) {
|
||||
await gql(
|
||||
`mutation ApplyLayout($id: ID!, $page: String!, $replace: Boolean!) {
|
||||
applyLayout(id: $id, page: $page, replace: $replace) { id }
|
||||
}`,
|
||||
{ id, page, replace },
|
||||
);
|
||||
// The page's own stores are refetched rather than patched from the
|
||||
// answer, so they stay in the shape their list query gives. A replace
|
||||
// also saved the old page as a new layout, hence the list too.
|
||||
await Promise.all([useBoxesStore(page).fetch(), useBackgroundStore().load(page), replace && fetch()]);
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
/** How a page key reads to a person: "/" for the landing page. */
|
||||
export function pagePath(page) {
|
||||
return page === "index" ? "/" : `/${page}`;
|
||||
}
|
||||
Reference in New Issue
Block a user