Wiki Phase 4: full-text search + revision history
Final phase of the wiki upgrade (see WIKI_UPGRADE.md). Schema (additive): wiki_revisions table (per-save content snapshots). The FULLTEXT index on wiki_pages(title, body) shipped in Phase 1. Search: - MATCH ... AGAINST natural-language search over title + body, ordered by relevance - public: GET /public/wiki?q= (published only); admin: GET /admin/wiki?q= (all statuses) - public wiki index gains a search box; admin list gains a search field Revision history: - every create/update snapshots the page into wiki_revisions - admin endpoints: list revisions, get one, and restore (restore overwrites the page, rebuilds links, and appends a new revision — history stays append-only); logged as wiki.revision.restore - editor gains a History modal: revision list + word-level diff (jsdiff) of a chosen revision against the current page, with one-click restore Verified end-to-end: search matches body and title; two edits produce three revisions; diff renders added/removed words; restore reverts and records a new revision. No console errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { Link, useSearchParams } from 'react-router-dom'
|
||||
import PublicLayout from '../../components/PublicLayout.jsx'
|
||||
import PageHeader from '../../components/PageHeader.jsx'
|
||||
@@ -5,6 +6,30 @@ import { Loading, ErrorState, EmptyState } from '../../components/PageState.jsx'
|
||||
import { useAsync } from '../../lib/useAsync.js'
|
||||
import { api } from '../../api/client.js'
|
||||
|
||||
function SearchBox({ initial, onSubmit }) {
|
||||
const [term, setTerm] = useState(initial || '')
|
||||
return (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
onSubmit(term.trim())
|
||||
}}
|
||||
style={{ display: 'flex', gap: 8, maxWidth: 460, margin: '0 auto 8px' }}
|
||||
>
|
||||
<input
|
||||
type="search"
|
||||
value={term}
|
||||
onChange={(e) => setTerm(e.target.value)}
|
||||
className="input"
|
||||
placeholder="Search the wiki…"
|
||||
/>
|
||||
<button type="submit" className="btn btn-primary btn-sq">
|
||||
Search
|
||||
</button>
|
||||
</form>
|
||||
)
|
||||
}
|
||||
|
||||
// Group published pages under their category, preserving category sort order and
|
||||
// collecting anything uncategorized into a trailing section.
|
||||
function groupByCategory(categories, pages) {
|
||||
@@ -36,16 +61,19 @@ function PageCard({ page }) {
|
||||
}
|
||||
|
||||
export default function Wiki() {
|
||||
const [searchParams] = useSearchParams()
|
||||
const [searchParams, setSearchParams] = useSearchParams()
|
||||
const activeCategory = searchParams.get('category')
|
||||
const activeTag = searchParams.get('tag')
|
||||
// Tag view fetches a tag-filtered page list; otherwise all pages (grouped here).
|
||||
const activeQ = searchParams.get('q')
|
||||
// Search / tag views fetch a filtered page list; otherwise all pages (grouped here).
|
||||
const pageOpts = activeQ ? { q: activeQ } : activeTag ? { tag: activeTag } : {}
|
||||
const { loading, error, data } = useAsync(
|
||||
() =>
|
||||
Promise.all([api.wikiCategories(), api.wiki(activeTag ? { tag: activeTag } : {})]).then(
|
||||
([categories, pages]) => ({ categories, pages }),
|
||||
),
|
||||
[activeTag],
|
||||
Promise.all([api.wikiCategories(), api.wiki(pageOpts)]).then(([categories, pages]) => ({
|
||||
categories,
|
||||
pages,
|
||||
})),
|
||||
[activeTag, activeQ],
|
||||
)
|
||||
|
||||
const allSections = data ? groupByCategory(data.categories, data.pages) : []
|
||||
@@ -53,7 +81,10 @@ export default function Wiki() {
|
||||
? allSections.filter((s) => s.slug === activeCategory)
|
||||
: allSections
|
||||
const hasPages = data && data.pages.length > 0
|
||||
const filtered = Boolean(activeCategory || activeTag)
|
||||
const flat = Boolean(activeTag || activeQ) // flat-list views
|
||||
const filtered = Boolean(activeCategory || activeTag || activeQ)
|
||||
|
||||
const runSearch = (term) => setSearchParams(term ? { q: term } : {})
|
||||
|
||||
return (
|
||||
<PublicLayout section="wiki">
|
||||
@@ -64,6 +95,8 @@ export default function Wiki() {
|
||||
title="Mysticmoon Wiki"
|
||||
lead="A calm starting point for shard guides, the world and its lore, gameplay systems, and community rules."
|
||||
/>
|
||||
<SearchBox initial={activeQ || ''} onSubmit={runSearch} />
|
||||
|
||||
{loading && <Loading />}
|
||||
{error && <ErrorState message="Could not load the wiki right now." />}
|
||||
{!loading && !error && !hasPages && !filtered && <EmptyState>No wiki pages yet.</EmptyState>}
|
||||
@@ -74,13 +107,14 @@ export default function Wiki() {
|
||||
← All sections
|
||||
</Link>
|
||||
{activeTag && <span className="muted"> · Tagged #{activeTag}</span>}
|
||||
{activeQ && <span className="muted"> · Results for “{activeQ}”</span>}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{/* Tag view: a flat list of matching pages (tags cross categories). */}
|
||||
{!loading && !error && activeTag &&
|
||||
{/* Flat list: search results or a tag filter (both cross categories). */}
|
||||
{!loading && !error && flat &&
|
||||
(data.pages.length === 0 ? (
|
||||
<EmptyState>No pages with this tag.</EmptyState>
|
||||
<EmptyState>{activeQ ? 'No pages match that search.' : 'No pages with this tag.'}</EmptyState>
|
||||
) : (
|
||||
<div className="grid-4" style={{ marginTop: 12 }}>
|
||||
{data.pages.map((p) => (
|
||||
@@ -90,10 +124,10 @@ export default function Wiki() {
|
||||
))}
|
||||
|
||||
{/* Category / full view: grouped sections. */}
|
||||
{!loading && !error && !activeTag && hasPages && activeCategory && sections.length === 0 && (
|
||||
{!loading && !error && !flat && hasPages && activeCategory && sections.length === 0 && (
|
||||
<EmptyState>No pages in this section yet.</EmptyState>
|
||||
)}
|
||||
{!activeTag &&
|
||||
{!flat &&
|
||||
sections.map((section) => (
|
||||
<section key={section.id} style={{ marginTop: 36 }}>
|
||||
<h2
|
||||
|
||||
Reference in New Issue
Block a user