import m, {MithrilComponent} from '@garage44/mithril'
import {Badge, Button, Table} from '@garage44/mithril/components'
import type {PageSummary} from '@/types'
import {api, notifier} from '@/app'
import {ApiError} from '@/lib/api'
import {local} from '@/lib/reactive'
import {may} from '@/lib/roles'
/**
* Admin › Content › Pages (`docs/mockups/cms`): the site's content pages, what
* is live, and where each language stands against the one it was written in.
*
* Writing is MCP's (`/mcp`, `crates/simulator/src/pages/mcp.rs`): an agent — the
* Midas hub's — makes the JSX and the texts. This page is for looking and for the
* decisions a person may want to take back: preview a draft, publish it, take a
* page down.
*/
export class ContentPages extends MithrilComponent {
s = local({busy: '', languages: [] as string[], loaded: false, pages: [] as PageSummary[]})
oninit() {
void this.load()
}
async load() {
try {
const r = await api.get<{pages: PageSummary[]; languages: string[]}>('/api/admin/pages')
this.s.pages = r.pages
this.s.languages = r.languages
} catch (e) {
notifier.error(e instanceof ApiError ? e.message : 'Could not load the pages')
}
this.s.loaded = true
}
async act(page: PageSummary, what: 'publish' | 'unpublish') {
this.s.busy = page.slug
try {
await api.post(`/api/admin/pages/${encodeURIComponent(page.slug)}/${what}`)
notifier.success(what === 'publish' ? `${page.title || page.slug} is live` : `${page.title || page.slug} is taken down`)
await this.load()
} catch (e) {
notifier.error(e instanceof ApiError ? e.message : `Could not ${what} the page`)
}
this.s.busy = ''
}
view() {
const s = this.s
const publisher = may('pages_publish')
const state = (p: PageSummary) => (
)
const language = (lang: string) => (p: PageSummary) => {
const status = p.languages[lang]
if (lang === p.source_lang) return
Pages are written through MCP at /mcp with an access token that may write pages. Each text is a
$t key with a text per language; a translation turns stale when its source text changes.