Reorganise by feature, rename to Novelly, add Aspire and a pre-push hook
The layered split into Domain/Application/Infrastructure/Api was forcing organisation by layer: adding one capability meant touching four projects and four folders that each held a slice of it. Those four projects are now one feature-organised Novelly.Api, where each folder — Projects, Characters, Chapters, Beats, Scenes, Tags, Agent — holds its entity, DTOs, service and endpoints together. Common/ holds what genuinely crosses features (the patch semantics, the two exception types, DraftStatus) and Data/ holds the DbContext and migrations. Six .NET projects become five: the three layer projects are gone, and Novelly.AppHost and Novelly.ServiceDefaults are new. - Namespaces move from NovelSoftware.* to Novelly.*, including the entity type names recorded in the EF model snapshots. The migration ids are untouched, so an existing novel.db still migrates cleanly — verified against a fresh file. - Aspire orchestration mirrors the mic-check setup: the AppHost starts the API on :5080 and the Vite dev server on :5173, and the API picks up OpenTelemetry, health checks and service discovery from ServiceDefaults. /health and /alive now answer in development. - A Husky pre-push hook runs scripts/ci/prepush.sh: build, test, then a web build. The scripts are plain bash so CI can run the same steps. - The MCP server's env var is now NOVELLY_API_URL. Verified beyond the build: 44 tests pass, the web client builds, the API was exercised over curl (project/chapter/beat/tag round trip, tag cross-reference, 503 on the agent without a key while conversation listing still returns 200), the MCP server was driven over stdio JSON-RPC (26 tools, errors still surface the API's own message rather than being flattened), and the AppHost was run to confirm both resources come up and Vite proxies /api through to the API. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S56bfZMGe1hnhpWP4CjjNw
This commit is contained in:
co-authored by
Claude Opus 5
parent
30e0c6926e
commit
725758ccd9
@@ -0,0 +1,24 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
||||
"plugins": ["react", "typescript", "oxc"],
|
||||
"rules": {
|
||||
"react/rules-of-hooks": "error",
|
||||
"react/only-export-components": ["warn", { "allowConstantExport": true }]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some Oxlint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the Oxlint configuration
|
||||
|
||||
If you are developing a production application, we recommend enabling type-aware lint rules by installing `oxlint-tsgolint` and editing `.oxlintrc.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"$schema": "./node_modules/oxlint/configuration_schema.json",
|
||||
"plugins": ["react", "typescript", "oxc"],
|
||||
"options": {
|
||||
"typeAware": true
|
||||
},
|
||||
"rules": {
|
||||
"react/rules-of-hooks": "error",
|
||||
"react/only-export-components": ["warn", { "allowConstantExport": true }]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
See the [Oxlint rules documentation](https://oxc.rs/docs/guide/usage/linter/rules) for the full list of rules and categories.
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Novel Software</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
Generated
+2053
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "novelly-web",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "oxlint",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tanstack/react-query": "^5.101.4",
|
||||
"react": "^19.2.8",
|
||||
"react-dom": "^19.2.8",
|
||||
"react-router-dom": "^7.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.3.3",
|
||||
"@types/node": "^24.13.3",
|
||||
"@types/react": "^19.2.17",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^6.0.4",
|
||||
"oxlint": "^1.75.0",
|
||||
"playwright": "^1.62.1",
|
||||
"tailwindcss": "^4.3.3",
|
||||
"typescript": "~6.0.2",
|
||||
"vite": "^8.2.0"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
@@ -0,0 +1,24 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||
</symbol>
|
||||
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||
</symbol>
|
||||
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||
</symbol>
|
||||
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||
</symbol>
|
||||
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
@@ -0,0 +1,26 @@
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
import ProjectsPage from './pages/ProjectsPage'
|
||||
import ProjectLayout from './pages/ProjectLayout'
|
||||
import OverviewPage from './pages/OverviewPage'
|
||||
import CharactersPage from './pages/CharactersPage'
|
||||
import TagsPage from './pages/TagsPage'
|
||||
import ChaptersPage from './pages/ChaptersPage'
|
||||
import ChapterPage from './pages/ChapterPage'
|
||||
import AgentPage from './pages/AgentPage'
|
||||
|
||||
export default function App() {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/" element={<ProjectsPage />} />
|
||||
<Route path="/projects/:projectId" element={<ProjectLayout />}>
|
||||
<Route index element={<OverviewPage />} />
|
||||
<Route path="characters" element={<CharactersPage />} />
|
||||
<Route path="chapters" element={<ChaptersPage />} />
|
||||
<Route path="chapters/:chapterId" element={<ChapterPage />} />
|
||||
<Route path="tags" element={<TagsPage />} />
|
||||
<Route path="agent" element={<AgentPage />} />
|
||||
</Route>
|
||||
<Route path="*" element={<ProjectsPage />} />
|
||||
</Routes>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
const BASE = import.meta.env.VITE_API_BASE ?? ''
|
||||
|
||||
/** An API error carrying the ProblemDetails message so the UI can show something useful. */
|
||||
export class ApiError extends Error {
|
||||
readonly status: number
|
||||
|
||||
constructor(message: string, status: number) {
|
||||
super(message)
|
||||
this.name = 'ApiError'
|
||||
this.status = status
|
||||
}
|
||||
}
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(`${BASE}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...init?.headers,
|
||||
},
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
let detail = response.statusText
|
||||
try {
|
||||
const problem = await response.json()
|
||||
detail = problem.detail ?? problem.title ?? detail
|
||||
} catch {
|
||||
// Non-JSON error body — the status text is the best we have.
|
||||
}
|
||||
throw new ApiError(detail, response.status)
|
||||
}
|
||||
|
||||
if (response.status === 204) {
|
||||
return undefined as T
|
||||
}
|
||||
|
||||
return response.json() as Promise<T>
|
||||
}
|
||||
|
||||
export const api = {
|
||||
get: <T>(path: string) => request<T>(path),
|
||||
post: <T>(path: string, body?: unknown) =>
|
||||
request<T>(path, { method: 'POST', body: JSON.stringify(body ?? {}) }),
|
||||
patch: <T>(path: string, body: unknown) =>
|
||||
request<T>(path, { method: 'PATCH', body: JSON.stringify(body) }),
|
||||
delete: (path: string) => request<void>(path, { method: 'DELETE' }),
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { api } from './client'
|
||||
import type {
|
||||
AgentTurn,
|
||||
Chapter,
|
||||
ChapterSummary,
|
||||
Character,
|
||||
Conversation,
|
||||
ConversationSummary,
|
||||
Beat,
|
||||
Project,
|
||||
ProjectSummary,
|
||||
Scene,
|
||||
TagReferences,
|
||||
TagSummary,
|
||||
} from './types'
|
||||
|
||||
export const keys = {
|
||||
projects: ['projects'] as const,
|
||||
project: (id: string) => ['projects', id] as const,
|
||||
characters: (projectId: string) => ['projects', projectId, 'characters'] as const,
|
||||
tags: (projectId: string) => ['projects', projectId, 'tags'] as const,
|
||||
tagRefs: (tagId: string) => ['tags', tagId, 'references'] as const,
|
||||
chapters: (projectId: string) => ['projects', projectId, 'chapters'] as const,
|
||||
chapter: (id: string) => ['chapters', id] as const,
|
||||
conversations: (projectId: string) => ['projects', projectId, 'conversations'] as const,
|
||||
conversation: (id: string) => ['conversations', id] as const,
|
||||
}
|
||||
|
||||
// --- Projects ---------------------------------------------------------------
|
||||
|
||||
export const useProjects = () =>
|
||||
useQuery({ queryKey: keys.projects, queryFn: () => api.get<ProjectSummary[]>('/api/projects') })
|
||||
|
||||
export const useProject = (id: string) =>
|
||||
useQuery({ queryKey: keys.project(id), queryFn: () => api.get<Project>(`/api/projects/${id}`) })
|
||||
|
||||
export function useCreateProject() {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: { title: string; author?: string; genre?: string; logline?: string }) =>
|
||||
api.post<Project>('/api/projects', body),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.projects }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateProject(id: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: Partial<Project>) => api.patch<Project>(`/api/projects/${id}`, body),
|
||||
onSuccess: (updated) => {
|
||||
qc.setQueryData(keys.project(id), updated)
|
||||
qc.invalidateQueries({ queryKey: keys.projects })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteProject() {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/projects/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.projects }),
|
||||
})
|
||||
}
|
||||
|
||||
// --- Characters -------------------------------------------------------------
|
||||
|
||||
export const useCharacters = (projectId: string) =>
|
||||
useQuery({
|
||||
queryKey: keys.characters(projectId),
|
||||
queryFn: () => api.get<Character[]>(`/api/projects/${projectId}/characters`),
|
||||
})
|
||||
|
||||
export function useCreateCharacter(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: Partial<Character> & { name: string }) =>
|
||||
api.post<Character>(`/api/projects/${projectId}/characters`, body),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: keys.characters(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.tags(projectId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateCharacter(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: Partial<Omit<Character, 'tags'>> & { id: string; tags?: string[] }) =>
|
||||
api.patch<Character>(`/api/characters/${id}`, body),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: keys.characters(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.tags(projectId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteCharacter(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/characters/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.characters(projectId) }),
|
||||
})
|
||||
}
|
||||
|
||||
// --- Tags --------------------------------------------------------------------
|
||||
|
||||
export const useTags = (projectId: string) =>
|
||||
useQuery({
|
||||
queryKey: keys.tags(projectId),
|
||||
queryFn: () => api.get<TagSummary[]>(`/api/projects/${projectId}/tags`),
|
||||
})
|
||||
|
||||
export const useTagReferences = (tagId: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: keys.tagRefs(tagId ?? ''),
|
||||
queryFn: () => api.get<TagReferences>(`/api/tags/${tagId}/references`),
|
||||
enabled: Boolean(tagId),
|
||||
})
|
||||
|
||||
export function useUpdateTag(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: { id: string; name?: string; color?: string }) =>
|
||||
api.patch<TagSummary>(`/api/tags/${id}`, body),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.tags(projectId) }),
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Deleting a tag strips it from every character, chapter and beat that carried it, so
|
||||
* this invalidates the whole cache rather than trying to enumerate what moved.
|
||||
*/
|
||||
export function useDeleteTag() {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/tags/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries(),
|
||||
})
|
||||
}
|
||||
|
||||
// --- Beats (a chapter's outline) ---------------------------------------------
|
||||
|
||||
export function useCreateBeat(chapterId: string, projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: Partial<Beat> & { title: string }) =>
|
||||
api.post<Beat>(`/api/chapters/${chapterId}/beats`, body),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: keys.chapter(chapterId) })
|
||||
qc.invalidateQueries({ queryKey: keys.tags(projectId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateBeat(chapterId: string, projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: Partial<Omit<Beat, 'tags'>> & { id: string; tags?: string[] }) =>
|
||||
api.patch<Beat>(`/api/beats/${id}`, body),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: keys.chapter(chapterId) })
|
||||
qc.invalidateQueries({ queryKey: keys.tags(projectId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteBeat(chapterId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/beats/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapter(chapterId) }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useReorderBeats(chapterId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (beatIds: string[]) =>
|
||||
api.post<Beat[]>(`/api/chapters/${chapterId}/beats/reorder`, { beatIds }),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapter(chapterId) }),
|
||||
})
|
||||
}
|
||||
|
||||
// --- Chapters and scenes ----------------------------------------------------
|
||||
|
||||
export const useChapters = (projectId: string) =>
|
||||
useQuery({
|
||||
queryKey: keys.chapters(projectId),
|
||||
queryFn: () => api.get<ChapterSummary[]>(`/api/projects/${projectId}/chapters`),
|
||||
})
|
||||
|
||||
export const useChapter = (id: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: keys.chapter(id ?? ''),
|
||||
queryFn: () => api.get<Chapter>(`/api/chapters/${id}`),
|
||||
enabled: Boolean(id),
|
||||
})
|
||||
|
||||
export function useCreateChapter(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: Partial<Chapter> & { title: string }) =>
|
||||
api.post<Chapter>(`/api/projects/${projectId}/chapters`, body),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapters(projectId) }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateChapter(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: Partial<Omit<Chapter, 'tags'>> & { id: string; tags?: string[] }) =>
|
||||
api.patch<Chapter>(`/api/chapters/${id}`, body),
|
||||
onSuccess: (updated) => {
|
||||
qc.setQueryData(keys.chapter(updated.id), updated)
|
||||
qc.invalidateQueries({ queryKey: keys.chapters(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.tags(projectId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteChapter(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/chapters/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapters(projectId) }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useCreateScene(chapterId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: Partial<Scene> & { title: string }) =>
|
||||
api.post<Scene>(`/api/chapters/${chapterId}/scenes`, body),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapter(chapterId) }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useUpdateScene(chapterId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: ({ id, ...body }: Partial<Scene> & { id: string }) =>
|
||||
api.patch<Scene>(`/api/scenes/${id}`, body),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapter(chapterId) }),
|
||||
})
|
||||
}
|
||||
|
||||
export function useDeleteScene(chapterId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/scenes/${id}`),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: keys.chapter(chapterId) }),
|
||||
})
|
||||
}
|
||||
|
||||
// --- Agent ------------------------------------------------------------------
|
||||
|
||||
export const useConversations = (projectId: string) =>
|
||||
useQuery({
|
||||
queryKey: keys.conversations(projectId),
|
||||
queryFn: () => api.get<ConversationSummary[]>(`/api/projects/${projectId}/agent/conversations`),
|
||||
})
|
||||
|
||||
export const useConversation = (id: string | undefined) =>
|
||||
useQuery({
|
||||
queryKey: keys.conversation(id ?? ''),
|
||||
queryFn: () => api.get<Conversation>(`/api/conversations/${id}`),
|
||||
enabled: Boolean(id),
|
||||
})
|
||||
|
||||
export function useSendAgentMessage(projectId: string) {
|
||||
const qc = useQueryClient()
|
||||
return useMutation({
|
||||
mutationFn: (body: { message: string; conversationId?: string }) =>
|
||||
api.post<AgentTurn>(`/api/projects/${projectId}/agent/messages`, body),
|
||||
onSuccess: (turn) => {
|
||||
qc.invalidateQueries({ queryKey: keys.conversations(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.conversation(turn.conversationId) })
|
||||
// The agent edits project data through its tools, so anything on screen may be stale.
|
||||
qc.invalidateQueries({ queryKey: keys.characters(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.tags(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.chapters(projectId) })
|
||||
qc.invalidateQueries({ queryKey: keys.project(projectId) })
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
// Mirrors the DTOs in the Novelly.Api feature folders. Enums travel as their names.
|
||||
|
||||
export type CharacterRole =
|
||||
| 'Protagonist'
|
||||
| 'Antagonist'
|
||||
| 'Deuteragonist'
|
||||
| 'Supporting'
|
||||
| 'Minor'
|
||||
| 'Mentor'
|
||||
| 'LoveInterest'
|
||||
| 'Foil'
|
||||
|
||||
export const characterRoles: CharacterRole[] = [
|
||||
'Protagonist',
|
||||
'Antagonist',
|
||||
'Deuteragonist',
|
||||
'Supporting',
|
||||
'Minor',
|
||||
'Mentor',
|
||||
'LoveInterest',
|
||||
'Foil',
|
||||
]
|
||||
|
||||
export type DraftStatus = 'Planned' | 'Outlined' | 'Drafted' | 'Revised' | 'Final'
|
||||
|
||||
export const draftStatuses: DraftStatus[] = ['Planned', 'Outlined', 'Drafted', 'Revised', 'Final']
|
||||
|
||||
export interface ProjectSummary {
|
||||
id: string
|
||||
title: string
|
||||
author: string | null
|
||||
genre: string | null
|
||||
logline: string | null
|
||||
targetWordCount: number | null
|
||||
characterCount: number
|
||||
chapterCount: number
|
||||
wordCount: number
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface Project {
|
||||
id: string
|
||||
title: string
|
||||
author: string | null
|
||||
genre: string | null
|
||||
logline: string | null
|
||||
synopsis: string | null
|
||||
notes: string | null
|
||||
targetWordCount: number | null
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
id: string
|
||||
name: string
|
||||
color: string | null
|
||||
}
|
||||
|
||||
export interface TagSummary extends Tag {
|
||||
characterCount: number
|
||||
chapterCount: number
|
||||
beatCount: number
|
||||
totalCount: number
|
||||
}
|
||||
|
||||
export interface TagReferences {
|
||||
tag: Tag
|
||||
characters: { id: string; name: string; role: string }[]
|
||||
chapters: { id: string; number: number; title: string; summary: string | null }[]
|
||||
beats: {
|
||||
id: string
|
||||
chapterId: string
|
||||
chapterNumber: number
|
||||
chapterTitle: string
|
||||
sortOrder: number
|
||||
title: string
|
||||
characterName: string | null
|
||||
whatHappened: string | null
|
||||
}[]
|
||||
}
|
||||
|
||||
/** One row of a chapter's outline. Flat and ordered — no nesting. */
|
||||
export interface Beat {
|
||||
id: string
|
||||
chapterId: string
|
||||
sortOrder: number
|
||||
title: string
|
||||
characterId: string | null
|
||||
characterName: string | null
|
||||
whatHappened: string | null
|
||||
whatsNext: string | null
|
||||
sceneId: string | null
|
||||
sceneTitle: string | null
|
||||
tags: Tag[]
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface Relationship {
|
||||
id: string
|
||||
relatedCharacterId: string
|
||||
relatedCharacterName: string
|
||||
relationshipType: string
|
||||
description: string | null
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
id: string
|
||||
projectId: string
|
||||
name: string
|
||||
role: CharacterRole
|
||||
age: string | null
|
||||
pronouns: string | null
|
||||
occupation: string | null
|
||||
appearance: string | null
|
||||
personality: string | null
|
||||
backstory: string | null
|
||||
want: string | null
|
||||
need: string | null
|
||||
internalConflict: string | null
|
||||
externalConflict: string | null
|
||||
arcSummary: string | null
|
||||
voice: string | null
|
||||
notes: string | null
|
||||
relationships: Relationship[]
|
||||
tags: Tag[]
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface Scene {
|
||||
id: string
|
||||
chapterId: string
|
||||
sortOrder: number
|
||||
title: string
|
||||
summary: string | null
|
||||
goal: string | null
|
||||
conflict: string | null
|
||||
outcome: string | null
|
||||
povCharacterId: string | null
|
||||
povCharacterName: string | null
|
||||
location: string | null
|
||||
prose: string | null
|
||||
wordCount: number
|
||||
status: DraftStatus
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface ChapterSummary {
|
||||
id: string
|
||||
projectId: string
|
||||
number: number
|
||||
title: string
|
||||
summary: string | null
|
||||
povCharacterId: string | null
|
||||
povCharacterName: string | null
|
||||
setting: string | null
|
||||
status: DraftStatus
|
||||
targetWordCount: number | null
|
||||
beatCount: number
|
||||
sceneCount: number
|
||||
wordCount: number
|
||||
tags: Tag[]
|
||||
}
|
||||
|
||||
export interface Chapter extends Omit<ChapterSummary, 'beatCount' | 'sceneCount' | 'wordCount'> {
|
||||
notes: string | null
|
||||
beats: Beat[]
|
||||
scenes: Scene[]
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface ToolCall {
|
||||
name: string
|
||||
input: string
|
||||
result: string
|
||||
}
|
||||
|
||||
export interface AgentMessage {
|
||||
id: string
|
||||
role: 'User' | 'Assistant'
|
||||
content: string
|
||||
toolCalls: ToolCall[]
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
export interface ConversationSummary {
|
||||
id: string
|
||||
projectId: string
|
||||
title: string
|
||||
messageCount: number
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface Conversation extends ConversationSummary {
|
||||
messages: AgentMessage[]
|
||||
}
|
||||
|
||||
export interface AgentTurn {
|
||||
conversationId: string
|
||||
message: AgentMessage
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { useState } from 'react'
|
||||
import type { Tag } from '../api/types'
|
||||
|
||||
export function TagChip({ tag, onRemove }: { tag: Tag; onRemove?: () => void }) {
|
||||
const tone = tag.color ?? 'var(--accent)'
|
||||
|
||||
return (
|
||||
<span
|
||||
className="inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium"
|
||||
style={{ color: tone, background: `color-mix(in srgb, ${tone} 14%, transparent)` }}
|
||||
>
|
||||
{tag.name}
|
||||
{onRemove && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onRemove}
|
||||
className="opacity-60 transition hover:opacity-100"
|
||||
aria-label={`Remove tag ${tag.name}`}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
)}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a set of tags and lets you add or remove them by name. The API creates unknown
|
||||
* tags on the fly, so typing a new one is a single action rather than "create the tag,
|
||||
* then apply it".
|
||||
*/
|
||||
export function TagEditor({
|
||||
tags,
|
||||
suggestions = [],
|
||||
onChange,
|
||||
label,
|
||||
}: {
|
||||
tags: Tag[]
|
||||
suggestions?: string[]
|
||||
onChange: (names: string[]) => void
|
||||
label?: string
|
||||
}) {
|
||||
const [draft, setDraft] = useState('')
|
||||
const listId = `tag-suggestions-${label ?? 'default'}`
|
||||
|
||||
const add = () => {
|
||||
const name = draft.trim()
|
||||
if (!name) return
|
||||
// Case-insensitive, matching how the API resolves tag names.
|
||||
if (!tags.some((t) => t.name.toLowerCase() === name.toLowerCase())) {
|
||||
onChange([...tags.map((t) => t.name), name])
|
||||
}
|
||||
setDraft('')
|
||||
}
|
||||
|
||||
const remove = (name: string) =>
|
||||
onChange(tags.filter((t) => t.name !== name).map((t) => t.name))
|
||||
|
||||
const unused = suggestions.filter(
|
||||
(s) => !tags.some((t) => t.name.toLowerCase() === s.toLowerCase()),
|
||||
)
|
||||
|
||||
return (
|
||||
<div>
|
||||
{label && <span className="label">{label}</span>}
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{tags.map((tag) => (
|
||||
<TagChip key={tag.id} tag={tag} onRemove={() => remove(tag.name)} />
|
||||
))}
|
||||
<input
|
||||
className="input w-32 flex-1 px-2 py-0.5 text-xs"
|
||||
value={draft}
|
||||
list={listId}
|
||||
placeholder="Add tag…"
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onBlur={add}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ',') {
|
||||
e.preventDefault()
|
||||
add()
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<datalist id={listId}>
|
||||
{unused.map((name) => (
|
||||
<option key={name} value={name} />
|
||||
))}
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import type { DraftStatus } from '../api/types'
|
||||
|
||||
export function Spinner({ label = 'Loading' }: { label?: string }) {
|
||||
return (
|
||||
<div className="flex items-center gap-2 py-8 text-sm muted">
|
||||
<span
|
||||
className="h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"
|
||||
aria-hidden
|
||||
/>
|
||||
{label}…
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function ErrorNote({ error }: { error: unknown }) {
|
||||
const message = error instanceof Error ? error.message : String(error)
|
||||
return (
|
||||
<div
|
||||
role="alert"
|
||||
className="rounded-md px-3 py-2 text-sm"
|
||||
style={{ background: 'var(--accent-soft)', color: 'var(--accent)' }}
|
||||
>
|
||||
{message}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function EmptyState({ title, hint }: { title: string; hint?: ReactNode }) {
|
||||
return (
|
||||
<div className="card px-6 py-10 text-center">
|
||||
<p className="font-medium">{title}</p>
|
||||
{hint && <p className="mx-auto mt-1 max-w-md text-sm muted">{hint}</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const statusTone: Record<DraftStatus, string> = {
|
||||
Planned: '#8a8178',
|
||||
Outlined: '#5b7fa8',
|
||||
Drafted: '#a8813f',
|
||||
Revised: '#63914f',
|
||||
Final: '#4a8f7b',
|
||||
}
|
||||
|
||||
export function StatusBadge({ status }: { status: DraftStatus }) {
|
||||
const tone = statusTone[status]
|
||||
return (
|
||||
<span
|
||||
className="inline-block rounded-full px-2 py-0.5 text-[0.6875rem] font-semibold tracking-wide uppercase"
|
||||
style={{ color: tone, background: `color-mix(in srgb, ${tone} 14%, transparent)` }}
|
||||
>
|
||||
{status}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* A field that saves when it loses focus. Writing tools live or die on not making the
|
||||
* user hunt for a save button, so every editable field here commits on blur.
|
||||
*/
|
||||
export function AutoField({
|
||||
label,
|
||||
value,
|
||||
onCommit,
|
||||
multiline,
|
||||
rows = 3,
|
||||
placeholder,
|
||||
serif,
|
||||
}: {
|
||||
label?: string
|
||||
value: string | null | undefined
|
||||
onCommit: (next: string) => void
|
||||
multiline?: boolean
|
||||
rows?: number
|
||||
placeholder?: string
|
||||
serif?: boolean
|
||||
}) {
|
||||
const [draft, setDraft] = useState(value ?? '')
|
||||
const committed = useRef(value ?? '')
|
||||
|
||||
// Adopt changes that arrive from elsewhere (the agent, another tab) unless the user
|
||||
// is mid-edit, which would yank text out from under them.
|
||||
useEffect(() => {
|
||||
const incoming = value ?? ''
|
||||
if (incoming !== committed.current) {
|
||||
committed.current = incoming
|
||||
setDraft(incoming)
|
||||
}
|
||||
}, [value])
|
||||
|
||||
const commit = () => {
|
||||
if (draft !== committed.current) {
|
||||
committed.current = draft
|
||||
onCommit(draft)
|
||||
}
|
||||
}
|
||||
|
||||
const className = `input ${serif ? 'prose-serif' : ''}`
|
||||
|
||||
return (
|
||||
<label className="block">
|
||||
{label && <span className="label">{label}</span>}
|
||||
{multiline ? (
|
||||
<textarea
|
||||
className={className}
|
||||
rows={rows}
|
||||
value={draft}
|
||||
placeholder={placeholder}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onBlur={commit}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
className={className}
|
||||
value={draft}
|
||||
placeholder={placeholder}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onBlur={commit}
|
||||
onKeyDown={(e) => e.key === 'Enter' && e.currentTarget.blur()}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
export function Select<T extends string>({
|
||||
label,
|
||||
value,
|
||||
options,
|
||||
onChange,
|
||||
}: {
|
||||
label?: string
|
||||
value: T
|
||||
options: readonly T[]
|
||||
onChange: (next: T) => void
|
||||
}) {
|
||||
return (
|
||||
<label className="block">
|
||||
{label && <span className="label">{label}</span>}
|
||||
<select className="input" value={value} onChange={(e) => onChange(e.target.value as T)}>
|
||||
{options.map((option) => (
|
||||
<option key={option} value={option}>
|
||||
{option}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
export function Modal({
|
||||
title,
|
||||
onClose,
|
||||
children,
|
||||
}: {
|
||||
title: string
|
||||
onClose: () => void
|
||||
children: ReactNode
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose()
|
||||
window.addEventListener('keydown', onKey)
|
||||
return () => window.removeEventListener('keydown', onKey)
|
||||
}, [onClose])
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-start justify-center overflow-y-auto bg-black/40 p-6"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className="card mt-12 w-full max-w-lg p-5 shadow-xl"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
role="dialog"
|
||||
aria-modal
|
||||
aria-label={title}
|
||||
>
|
||||
<div className="mb-4 flex items-center justify-between">
|
||||
<h2 className="text-lg font-semibold">{title}</h2>
|
||||
<button className="btn px-2 py-1" onClick={onClose} aria-label="Close">
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
@import 'tailwindcss';
|
||||
|
||||
@theme {
|
||||
--font-sans: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
|
||||
--font-ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
|
||||
--font-mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
|
||||
}
|
||||
|
||||
/*
|
||||
* Warm paper light theme, cool ink dark theme. Colours are declared as variables so
|
||||
* every surface, border and accent moves together when the scheme flips.
|
||||
*/
|
||||
:root {
|
||||
--paper: #faf7f0;
|
||||
--surface: #ffffff;
|
||||
--surface-sunken: #f2ede2;
|
||||
--ink: #241f1a;
|
||||
--ink-muted: #6b6157;
|
||||
--line: #e0d8c8;
|
||||
--accent: #9a4a2f;
|
||||
--accent-soft: #f6e9e2;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
--paper: #16151a;
|
||||
--surface: #1e1d24;
|
||||
--surface-sunken: #131217;
|
||||
--ink: #ece7de;
|
||||
--ink-muted: #9a9288;
|
||||
--line: #322f39;
|
||||
--accent: #e08b62;
|
||||
--accent-soft: #2c2229;
|
||||
color-scheme: dark;
|
||||
}
|
||||
}
|
||||
|
||||
:root[data-theme='dark'] {
|
||||
--paper: #16151a;
|
||||
--surface: #1e1d24;
|
||||
--surface-sunken: #131217;
|
||||
--ink: #ece7de;
|
||||
--ink-muted: #9a9288;
|
||||
--line: #322f39;
|
||||
--accent: #e08b62;
|
||||
--accent-soft: #2c2229;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
:root[data-theme='light'] {
|
||||
--paper: #faf7f0;
|
||||
--surface: #ffffff;
|
||||
--surface-sunken: #f2ede2;
|
||||
--ink: #241f1a;
|
||||
--ink-muted: #6b6157;
|
||||
--line: #e0d8c8;
|
||||
--accent: #9a4a2f;
|
||||
--accent-soft: #f6e9e2;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
html,
|
||||
body,
|
||||
#root {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
background: var(--paper);
|
||||
color: var(--ink);
|
||||
font-family: var(--font-ui);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
}
|
||||
|
||||
@layer components {
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 0.5rem;
|
||||
}
|
||||
|
||||
.btn {
|
||||
@apply inline-flex items-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition;
|
||||
border: 1px solid var(--line);
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.btn:hover:not(:disabled) {
|
||||
background: var(--surface-sunken);
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
@apply cursor-not-allowed opacity-50;
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
filter: brightness(1.08);
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
.input {
|
||||
@apply w-full rounded-md px-2.5 py-1.5 text-sm outline-none transition;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.input:focus {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
|
||||
}
|
||||
|
||||
.label {
|
||||
@apply mb-1 block text-xs font-semibold tracking-wide uppercase;
|
||||
color: var(--ink-muted);
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: var(--ink-muted);
|
||||
}
|
||||
|
||||
.prose-serif {
|
||||
font-family: var(--font-sans);
|
||||
@apply text-[1.0625rem] leading-relaxed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import { StrictMode } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { BrowserRouter } from 'react-router-dom'
|
||||
import App from './App'
|
||||
import './index.css'
|
||||
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: { staleTime: 15_000, refetchOnWindowFocus: false, retry: 1 },
|
||||
},
|
||||
})
|
||||
|
||||
createRoot(document.getElementById('root')!).render(
|
||||
<StrictMode>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
</BrowserRouter>
|
||||
</QueryClientProvider>
|
||||
</StrictMode>,
|
||||
)
|
||||
@@ -0,0 +1,159 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useConversation, useConversations, useSendAgentMessage } from '../api/hooks'
|
||||
import type { AgentMessage } from '../api/types'
|
||||
import { ErrorNote, Spinner } from '../components/ui'
|
||||
|
||||
const starters = [
|
||||
'Read the brief and tell me what the outline is missing.',
|
||||
"Draft a three-act skeleton from the logline, then stop so I can react.",
|
||||
'Look at my protagonist: is the want genuinely in tension with the need?',
|
||||
]
|
||||
|
||||
export default function AgentPage() {
|
||||
const { projectId = '' } = useParams()
|
||||
const { data: conversations } = useConversations(projectId)
|
||||
const [conversationId, setConversationId] = useState<string | undefined>()
|
||||
const { data: conversation } = useConversation(conversationId)
|
||||
const send = useSendAgentMessage(projectId)
|
||||
const [draft, setDraft] = useState('')
|
||||
const endRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
endRef.current?.scrollIntoView({ behavior: 'smooth' })
|
||||
}, [conversation?.messages.length, send.isPending])
|
||||
|
||||
const submit = (message: string) => {
|
||||
const trimmed = message.trim()
|
||||
if (!trimmed || send.isPending) return
|
||||
setDraft('')
|
||||
send.mutate(
|
||||
{ message: trimmed, conversationId },
|
||||
{ onSuccess: (turn) => setConversationId(turn.conversationId) },
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-[15rem_1fr]">
|
||||
<aside className="grid content-start gap-2">
|
||||
<button
|
||||
className="btn btn-primary w-full justify-center"
|
||||
onClick={() => setConversationId(undefined)}
|
||||
>
|
||||
New conversation
|
||||
</button>
|
||||
{conversations?.map((item) => (
|
||||
<button
|
||||
key={item.id}
|
||||
onClick={() => setConversationId(item.id)}
|
||||
className="card px-3 py-2 text-left text-sm transition hover:shadow-sm"
|
||||
style={
|
||||
item.id === conversationId
|
||||
? { borderColor: 'var(--accent)', background: 'var(--accent-soft)' }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<div className="truncate">{item.title}</div>
|
||||
<div className="text-xs muted">
|
||||
{item.messageCount} message{item.messageCount === 1 ? '' : 's'}
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</aside>
|
||||
|
||||
<section className="flex min-h-[70vh] flex-col">
|
||||
<div className="flex-1 space-y-4 overflow-y-auto pb-4">
|
||||
{!conversation && (
|
||||
<div className="card p-6">
|
||||
<h2 className="text-lg font-semibold">Your writing partner</h2>
|
||||
<p className="mt-1 text-sm muted">
|
||||
It can read and edit the brief, the outline, character dossiers, chapters and
|
||||
scenes — the same data you see in the other tabs.
|
||||
</p>
|
||||
<div className="mt-4 grid gap-2">
|
||||
{starters.map((starter) => (
|
||||
<button
|
||||
key={starter}
|
||||
className="btn justify-start text-left"
|
||||
onClick={() => submit(starter)}
|
||||
>
|
||||
{starter}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{conversation?.messages.map((message) => (
|
||||
<MessageBubble key={message.id} message={message} />
|
||||
))}
|
||||
|
||||
{send.isPending && <Spinner label="Thinking" />}
|
||||
{send.error && <ErrorNote error={send.error} />}
|
||||
<div ref={endRef} />
|
||||
</div>
|
||||
|
||||
<form
|
||||
className="flex gap-2 pt-3"
|
||||
style={{ borderTop: '1px solid var(--line)' }}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault()
|
||||
submit(draft)
|
||||
}}
|
||||
>
|
||||
<textarea
|
||||
className="input flex-1 resize-none"
|
||||
rows={3}
|
||||
value={draft}
|
||||
placeholder="Ask about structure, a character's arc, or what the next beat should do…"
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
||||
e.preventDefault()
|
||||
submit(draft)
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<button className="btn btn-primary self-end" disabled={!draft.trim() || send.isPending}>
|
||||
Send
|
||||
</button>
|
||||
</form>
|
||||
<p className="mt-1 text-xs muted">⌘/Ctrl + Enter to send.</p>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function MessageBubble({ message }: { message: AgentMessage }) {
|
||||
const isUser = message.role === 'User'
|
||||
|
||||
return (
|
||||
<div className={isUser ? 'flex justify-end' : ''}>
|
||||
<div
|
||||
className={`card max-w-[46rem] px-4 py-3 ${isUser ? '' : 'w-full'}`}
|
||||
style={isUser ? { background: 'var(--accent-soft)', borderColor: 'transparent' } : undefined}
|
||||
>
|
||||
<div className="prose-serif whitespace-pre-wrap">{message.content}</div>
|
||||
|
||||
{message.toolCalls.length > 0 && (
|
||||
<details className="mt-3">
|
||||
<summary className="cursor-pointer text-xs muted">
|
||||
{message.toolCalls.length} change
|
||||
{message.toolCalls.length === 1 ? '' : 's'} made
|
||||
</summary>
|
||||
<ul className="mt-2 grid gap-2">
|
||||
{message.toolCalls.map((call, index) => (
|
||||
<li key={index} className="rounded-md p-2 text-xs" style={{ background: 'var(--surface-sunken)' }}>
|
||||
<div className="font-mono font-semibold">{call.name}</div>
|
||||
<pre className="mt-1 overflow-x-auto whitespace-pre-wrap break-words opacity-70">
|
||||
{call.input}
|
||||
</pre>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,406 @@
|
||||
import { useState } from 'react'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import {
|
||||
useChapter,
|
||||
useCharacters,
|
||||
useCreateBeat,
|
||||
useCreateScene,
|
||||
useDeleteBeat,
|
||||
useDeleteChapter,
|
||||
useDeleteScene,
|
||||
useReorderBeats,
|
||||
useTags,
|
||||
useUpdateBeat,
|
||||
useUpdateChapter,
|
||||
useUpdateScene,
|
||||
} from '../api/hooks'
|
||||
import { draftStatuses, type Beat, type Chapter, type Scene } from '../api/types'
|
||||
import { AutoField, ErrorNote, Select, Spinner, StatusBadge } from '../components/ui'
|
||||
import { TagEditor } from '../components/TagEditor'
|
||||
|
||||
export default function ChapterPage() {
|
||||
const { projectId = '', chapterId = '' } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const { data: chapter, isPending, error } = useChapter(chapterId)
|
||||
const { data: characters } = useCharacters(projectId)
|
||||
const { data: allTags } = useTags(projectId)
|
||||
const update = useUpdateChapter(projectId)
|
||||
const remove = useDeleteChapter(projectId)
|
||||
const createBeat = useCreateBeat(chapterId, projectId)
|
||||
const createScene = useCreateScene(chapterId)
|
||||
|
||||
if (isPending) return <Spinner label="Loading chapter" />
|
||||
if (error) return <ErrorNote error={error} />
|
||||
if (!chapter) return null
|
||||
|
||||
const patch = (body: Partial<Omit<Chapter, 'tags'>> & { tags?: string[] }) =>
|
||||
update.mutate({ id: chapter.id, ...body })
|
||||
|
||||
const suggestions = allTags?.map((t) => t.name) ?? []
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-4">
|
||||
<Link to={`/projects/${projectId}/chapters`} className="text-sm muted hover:underline">
|
||||
← All chapters
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<section className="card mb-6 p-5">
|
||||
<div className="grid gap-4 sm:grid-cols-[4rem_1fr_10rem]">
|
||||
<label className="block">
|
||||
<span className="label">No.</span>
|
||||
<input
|
||||
className="input"
|
||||
type="number"
|
||||
min={1}
|
||||
defaultValue={chapter.number}
|
||||
onBlur={(e) => {
|
||||
const number = Number(e.target.value)
|
||||
if (number > 0 && number !== chapter.number) patch({ number })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<AutoField
|
||||
label="Title"
|
||||
value={chapter.title}
|
||||
onCommit={(title) => title.trim() && patch({ title })}
|
||||
/>
|
||||
<Select
|
||||
label="Status"
|
||||
value={chapter.status}
|
||||
options={draftStatuses}
|
||||
onChange={(status) => patch({ status })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid gap-4 sm:grid-cols-2">
|
||||
<label className="block">
|
||||
<span className="label">POV character</span>
|
||||
<select
|
||||
className="input"
|
||||
value={chapter.povCharacterName ?? '—'}
|
||||
onChange={(e) => {
|
||||
const match = characters?.find((c) => c.name === e.target.value)
|
||||
patch({ povCharacterId: match?.id ?? null })
|
||||
}}
|
||||
>
|
||||
{['—', ...(characters?.map((c) => c.name) ?? [])].map((name) => (
|
||||
<option key={name}>{name}</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<AutoField
|
||||
label="Setting"
|
||||
value={chapter.setting}
|
||||
onCommit={(setting) => patch({ setting })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4">
|
||||
<TagEditor
|
||||
label="Tags"
|
||||
tags={chapter.tags}
|
||||
suggestions={suggestions}
|
||||
onChange={(tags) => patch({ tags })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 flex items-end justify-between gap-4">
|
||||
<div className="text-sm muted">
|
||||
{chapter.beats.length} beats · {chapter.scenes.length} scenes ·{' '}
|
||||
{chapter.scenes.reduce((sum, s) => sum + s.wordCount, 0).toLocaleString()} words
|
||||
</div>
|
||||
<button
|
||||
className="btn"
|
||||
style={{ color: 'var(--accent)' }}
|
||||
onClick={() => {
|
||||
if (confirm(`Delete chapter “${chapter.title}” and everything in it?`)) {
|
||||
remove.mutate(chapter.id, {
|
||||
onSuccess: () => navigate(`/projects/${projectId}/chapters`),
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
Delete chapter
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{/* The outline: a paragraph, then the beat table. */}
|
||||
<section className="mb-8">
|
||||
<h2 className="mb-1 text-lg font-semibold">Outline</h2>
|
||||
<p className="mb-3 text-sm muted">
|
||||
A paragraph on what the chapter does, then the beats that carry it.
|
||||
</p>
|
||||
|
||||
<div className="card mb-4 p-4">
|
||||
<AutoField
|
||||
value={chapter.summary}
|
||||
multiline
|
||||
rows={5}
|
||||
serif
|
||||
placeholder="What this chapter is for: where it starts, what shifts, where it leaves the reader."
|
||||
onCommit={(summary) => patch({ summary })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<BeatTable
|
||||
chapter={chapter}
|
||||
projectId={projectId}
|
||||
characters={characters?.map((c) => ({ id: c.id, name: c.name })) ?? []}
|
||||
suggestions={suggestions}
|
||||
/>
|
||||
|
||||
<button
|
||||
className="btn btn-primary mt-3"
|
||||
onClick={() => createBeat.mutate({ title: 'New beat' })}
|
||||
disabled={createBeat.isPending}
|
||||
>
|
||||
Add beat
|
||||
</button>
|
||||
{createBeat.error && (
|
||||
<div className="mt-2">
|
||||
<ErrorNote error={createBeat.error} />
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* The prose layer. */}
|
||||
<section>
|
||||
<div className="mb-3 flex items-center justify-between">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">Scenes</h2>
|
||||
<p className="text-sm muted">Where the prose lives. Beats can be grouped under these.</p>
|
||||
</div>
|
||||
<button
|
||||
className="btn"
|
||||
onClick={() => createScene.mutate({ title: 'New scene' })}
|
||||
disabled={createScene.isPending}
|
||||
>
|
||||
Add scene
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<ul className="grid gap-3">
|
||||
{chapter.scenes.map((scene) => (
|
||||
<SceneCard key={scene.id} chapterId={chapter.id} scene={scene} />
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function BeatTable({
|
||||
chapter,
|
||||
projectId,
|
||||
characters,
|
||||
suggestions,
|
||||
}: {
|
||||
chapter: Chapter
|
||||
projectId: string
|
||||
characters: { id: string; name: string }[]
|
||||
suggestions: string[]
|
||||
}) {
|
||||
const update = useUpdateBeat(chapter.id, projectId)
|
||||
const remove = useDeleteBeat(chapter.id)
|
||||
const reorder = useReorderBeats(chapter.id)
|
||||
|
||||
if (chapter.beats.length === 0) {
|
||||
return (
|
||||
<div className="card px-6 py-8 text-center text-sm muted">
|
||||
No beats yet. Each one is a short handle — “she burns the atlas” — plus what happened and
|
||||
what it sets up.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const move = (index: number, delta: number) => {
|
||||
const ids = chapter.beats.map((b) => b.id)
|
||||
const target = index + delta
|
||||
if (target < 0 || target >= ids.length) return
|
||||
;[ids[index], ids[target]] = [ids[target], ids[index]]
|
||||
reorder.mutate(ids)
|
||||
}
|
||||
|
||||
const patch = (id: string, body: Partial<Omit<Beat, 'tags'>> & { tags?: string[] }) =>
|
||||
update.mutate({ id, ...body })
|
||||
|
||||
return (
|
||||
<div className="card overflow-x-auto">
|
||||
<table className="w-full min-w-[64rem] border-collapse text-sm">
|
||||
<thead>
|
||||
<tr style={{ borderBottom: '1px solid var(--line)' }}>
|
||||
<th className="w-16 px-2 py-2 text-left text-xs font-semibold uppercase muted">#</th>
|
||||
<th className="w-56 px-2 py-2 text-left text-xs font-semibold uppercase muted">Beat</th>
|
||||
<th className="w-36 px-2 py-2 text-left text-xs font-semibold uppercase muted">
|
||||
Character
|
||||
</th>
|
||||
<th className="px-2 py-2 text-left text-xs font-semibold uppercase muted">
|
||||
What happened
|
||||
</th>
|
||||
<th className="px-2 py-2 text-left text-xs font-semibold uppercase muted">What's next</th>
|
||||
<th className="w-32 px-2 py-2 text-left text-xs font-semibold uppercase muted">Scene</th>
|
||||
<th className="w-8" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{chapter.beats.map((beat, index) => (
|
||||
<tr key={beat.id} style={{ borderBottom: '1px solid var(--line)' }}>
|
||||
<td className="px-2 py-2 align-top">
|
||||
<div className="flex items-center gap-1">
|
||||
<span className="w-4 text-xs muted">{index + 1}</span>
|
||||
<div className="flex flex-col">
|
||||
<button
|
||||
className="text-xs leading-none muted disabled:opacity-25"
|
||||
onClick={() => move(index, -1)}
|
||||
disabled={index === 0 || reorder.isPending}
|
||||
aria-label="Move beat up"
|
||||
>
|
||||
▲
|
||||
</button>
|
||||
<button
|
||||
className="text-xs leading-none muted disabled:opacity-25"
|
||||
onClick={() => move(index, 1)}
|
||||
disabled={index === chapter.beats.length - 1 || reorder.isPending}
|
||||
aria-label="Move beat down"
|
||||
>
|
||||
▼
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td className="px-2 py-2 align-top">
|
||||
<AutoField
|
||||
value={beat.title}
|
||||
placeholder="Three to five words"
|
||||
onCommit={(title) => title.trim() && patch(beat.id, { title })}
|
||||
/>
|
||||
<div className="mt-1.5">
|
||||
<TagEditor
|
||||
tags={beat.tags}
|
||||
suggestions={suggestions}
|
||||
onChange={(tags) => patch(beat.id, { tags })}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td className="px-2 py-2 align-top">
|
||||
<select
|
||||
className="input"
|
||||
value={beat.characterName ?? '—'}
|
||||
onChange={(e) => {
|
||||
const match = characters.find((c) => c.name === e.target.value)
|
||||
patch(beat.id, { characterId: match?.id ?? null })
|
||||
}}
|
||||
>
|
||||
{['—', ...characters.map((c) => c.name)].map((name) => (
|
||||
<option key={name}>{name}</option>
|
||||
))}
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td className="px-2 py-2 align-top">
|
||||
<AutoField
|
||||
value={beat.whatHappened}
|
||||
multiline
|
||||
rows={3}
|
||||
serif
|
||||
placeholder="The event itself."
|
||||
onCommit={(whatHappened) => patch(beat.id, { whatHappened })}
|
||||
/>
|
||||
</td>
|
||||
|
||||
<td className="px-2 py-2 align-top">
|
||||
<AutoField
|
||||
value={beat.whatsNext}
|
||||
multiline
|
||||
rows={3}
|
||||
serif
|
||||
placeholder="What it sets in motion."
|
||||
onCommit={(whatsNext) => patch(beat.id, { whatsNext })}
|
||||
/>
|
||||
</td>
|
||||
|
||||
<td className="px-2 py-2 align-top">
|
||||
<select
|
||||
className="input"
|
||||
value={beat.sceneTitle ?? '—'}
|
||||
onChange={(e) => {
|
||||
const match = chapter.scenes.find((s) => s.title === e.target.value)
|
||||
patch(beat.id, { sceneId: match?.id ?? null })
|
||||
}}
|
||||
>
|
||||
{['—', ...chapter.scenes.map((s) => s.title)].map((title) => (
|
||||
<option key={title}>{title}</option>
|
||||
))}
|
||||
</select>
|
||||
</td>
|
||||
|
||||
<td className="px-2 py-2 align-top">
|
||||
<button
|
||||
className="text-xs muted transition hover:opacity-100"
|
||||
style={{ color: 'var(--accent)' }}
|
||||
onClick={() => confirm(`Delete beat “${beat.title}”?`) && remove.mutate(beat.id)}
|
||||
aria-label={`Delete beat ${beat.title}`}
|
||||
>
|
||||
✕
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SceneCard({ chapterId, scene }: { chapterId: string; scene: Scene }) {
|
||||
const [showProse, setShowProse] = useState(Boolean(scene.prose))
|
||||
const update = useUpdateScene(chapterId)
|
||||
const remove = useDeleteScene(chapterId)
|
||||
const patch = (body: Partial<Scene>) => update.mutate({ id: scene.id, ...body })
|
||||
|
||||
return (
|
||||
<li className="card p-4">
|
||||
<div className="grid gap-3 sm:grid-cols-[1fr_9rem]">
|
||||
<AutoField value={scene.title} onCommit={(title) => title.trim() && patch({ title })} />
|
||||
<Select value={scene.status} options={draftStatuses} onChange={(status) => patch({ status })} />
|
||||
</div>
|
||||
|
||||
<div className="mt-3 flex items-center justify-between gap-3 text-xs muted">
|
||||
<div className="flex items-center gap-3">
|
||||
<StatusBadge status={scene.status} />
|
||||
<span>{scene.wordCount.toLocaleString()} words</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button className="btn px-2 py-1 text-xs" onClick={() => setShowProse((v) => !v)}>
|
||||
{showProse ? 'Hide prose' : 'Write prose'}
|
||||
</button>
|
||||
<button
|
||||
className="btn px-2 py-1 text-xs"
|
||||
style={{ color: 'var(--accent)' }}
|
||||
onClick={() => confirm(`Delete scene “${scene.title}”?`) && remove.mutate(scene.id)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{showProse && (
|
||||
<div className="mt-3">
|
||||
<AutoField
|
||||
value={scene.prose}
|
||||
multiline
|
||||
rows={16}
|
||||
serif
|
||||
placeholder="The scene itself. The beats grouped under it are the plan; this is the prose."
|
||||
onCommit={(prose) => patch({ prose })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</li>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
import { Link, useParams } from 'react-router-dom'
|
||||
import { useChapters, useCreateChapter } from '../api/hooks'
|
||||
import { EmptyState, ErrorNote, Spinner, StatusBadge } from '../components/ui'
|
||||
import { TagChip } from '../components/TagEditor'
|
||||
|
||||
export default function ChaptersPage() {
|
||||
const { projectId = '' } = useParams()
|
||||
const { data: chapters, isPending, error } = useChapters(projectId)
|
||||
const create = useCreateChapter(projectId)
|
||||
|
||||
if (isPending) return <Spinner label="Loading chapters" />
|
||||
if (error) return <ErrorNote error={error} />
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="mb-5 flex items-center justify-between gap-4">
|
||||
<h2 className="text-xl font-semibold">Chapters</h2>
|
||||
<button
|
||||
className="btn btn-primary"
|
||||
onClick={() => create.mutate({ title: 'Untitled chapter' })}
|
||||
disabled={create.isPending}
|
||||
>
|
||||
Add chapter
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{create.error && <ErrorNote error={create.error} />}
|
||||
|
||||
{chapters?.length === 0 ? (
|
||||
<EmptyState
|
||||
title="No chapters yet"
|
||||
hint="A chapter is a summary paragraph plus a table of beats. Add one and start outlining."
|
||||
/>
|
||||
) : (
|
||||
<ul className="grid gap-2">
|
||||
{chapters?.map((chapter) => (
|
||||
<li key={chapter.id}>
|
||||
<Link
|
||||
to={`/projects/${projectId}/chapters/${chapter.id}`}
|
||||
className="card flex items-center gap-4 px-5 py-3 transition hover:shadow-md"
|
||||
>
|
||||
<span className="w-8 shrink-0 text-right text-sm font-semibold muted">
|
||||
{chapter.number}
|
||||
</span>
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="truncate font-medium">{chapter.title}</div>
|
||||
{chapter.summary && <div className="truncate text-sm muted">{chapter.summary}</div>}
|
||||
{chapter.tags.length > 0 && (
|
||||
<div className="mt-1 flex flex-wrap gap-1">
|
||||
{chapter.tags.map((tag) => (
|
||||
<TagChip key={tag.id} tag={tag} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-3 text-xs muted">
|
||||
{chapter.povCharacterName && <span>POV: {chapter.povCharacterName}</span>}
|
||||
<span>{chapter.beatCount} beats</span>
|
||||
<span>{chapter.sceneCount} scenes</span>
|
||||
<span>{chapter.wordCount.toLocaleString()} words</span>
|
||||
<StatusBadge status={chapter.status} />
|
||||
</div>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,271 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import {
|
||||
useCharacters,
|
||||
useCreateCharacter,
|
||||
useDeleteCharacter,
|
||||
useTags,
|
||||
useUpdateCharacter,
|
||||
} from '../api/hooks'
|
||||
import { characterRoles, type Character } from '../api/types'
|
||||
import { AutoField, EmptyState, ErrorNote, Modal, Select, Spinner } from '../components/ui'
|
||||
import { TagEditor } from '../components/TagEditor'
|
||||
|
||||
export default function CharactersPage() {
|
||||
const { projectId = '' } = useParams()
|
||||
const { data: characters, isPending, error } = useCharacters(projectId)
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||
const [adding, setAdding] = useState(false)
|
||||
|
||||
if (isPending) return <Spinner label="Loading characters" />
|
||||
if (error) return <ErrorNote error={error} />
|
||||
|
||||
const selected = characters?.find((c) => c.id === selectedId) ?? characters?.[0]
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-[16rem_1fr]">
|
||||
<aside className="grid content-start gap-2">
|
||||
<button className="btn btn-primary w-full justify-center" onClick={() => setAdding(true)}>
|
||||
Add character
|
||||
</button>
|
||||
{characters?.map((character) => (
|
||||
<button
|
||||
key={character.id}
|
||||
onClick={() => setSelectedId(character.id)}
|
||||
className="card px-3 py-2 text-left transition hover:shadow-sm"
|
||||
style={
|
||||
character.id === selected?.id
|
||||
? { borderColor: 'var(--accent)', background: 'var(--accent-soft)' }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<div className="truncate font-medium">{character.name}</div>
|
||||
<div className="text-xs muted">{character.role}</div>
|
||||
</button>
|
||||
))}
|
||||
</aside>
|
||||
|
||||
<section>
|
||||
{!selected ? (
|
||||
<EmptyState
|
||||
title="No characters yet"
|
||||
hint="Add the protagonist first — most outline questions resolve once you know what they want."
|
||||
/>
|
||||
) : (
|
||||
<CharacterSheet key={selected.id} projectId={projectId} character={selected} />
|
||||
)}
|
||||
</section>
|
||||
|
||||
{adding && (
|
||||
<AddCharacterModal
|
||||
projectId={projectId}
|
||||
onClose={() => setAdding(false)}
|
||||
onCreated={setSelectedId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function CharacterSheet({ projectId, character }: { projectId: string; character: Character }) {
|
||||
const { data: allTags } = useTags(projectId)
|
||||
const update = useUpdateCharacter(projectId)
|
||||
const remove = useDeleteCharacter(projectId)
|
||||
const patch = (body: Partial<Omit<Character, 'tags'>> & { tags?: string[] }) =>
|
||||
update.mutate({ id: character.id, ...body })
|
||||
|
||||
return (
|
||||
<div className="card p-5">
|
||||
<div className="mb-5 flex items-start justify-between gap-4">
|
||||
<div className="grid flex-1 gap-3 sm:grid-cols-[1fr_12rem]">
|
||||
<AutoField
|
||||
label="Name"
|
||||
value={character.name}
|
||||
onCommit={(name) => name.trim() && patch({ name })}
|
||||
/>
|
||||
<Select
|
||||
label="Role"
|
||||
value={character.role}
|
||||
options={characterRoles}
|
||||
onChange={(role) => patch({ role })}
|
||||
/>
|
||||
</div>
|
||||
<button
|
||||
className="btn mt-6"
|
||||
style={{ color: 'var(--accent)' }}
|
||||
onClick={() => {
|
||||
if (confirm(`Delete ${character.name}?`)) remove.mutate(character.id)
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 sm:grid-cols-3">
|
||||
<AutoField label="Age" value={character.age} onCommit={(age) => patch({ age })} />
|
||||
<AutoField
|
||||
label="Pronouns"
|
||||
value={character.pronouns}
|
||||
onCommit={(pronouns) => patch({ pronouns })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Occupation"
|
||||
value={character.occupation}
|
||||
onCommit={(occupation) => patch({ occupation })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-5">
|
||||
<TagEditor
|
||||
label="Tags"
|
||||
tags={character.tags}
|
||||
suggestions={allTags?.map((t) => t.name) ?? []}
|
||||
onChange={(tags) => patch({ tags })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-6 grid gap-4 lg:grid-cols-2">
|
||||
<AutoField
|
||||
label="Wants"
|
||||
value={character.want}
|
||||
multiline
|
||||
rows={3}
|
||||
placeholder="What they are consciously chasing."
|
||||
onCommit={(want) => patch({ want })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Needs"
|
||||
value={character.need}
|
||||
multiline
|
||||
rows={3}
|
||||
placeholder="What the story will make them face instead."
|
||||
onCommit={(need) => patch({ need })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Internal conflict"
|
||||
value={character.internalConflict}
|
||||
multiline
|
||||
onCommit={(internalConflict) => patch({ internalConflict })}
|
||||
/>
|
||||
<AutoField
|
||||
label="External conflict"
|
||||
value={character.externalConflict}
|
||||
multiline
|
||||
onCommit={(externalConflict) => patch({ externalConflict })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Arc"
|
||||
value={character.arcSummary}
|
||||
multiline
|
||||
onCommit={(arcSummary) => patch({ arcSummary })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Voice"
|
||||
value={character.voice}
|
||||
multiline
|
||||
placeholder="Register, rhythm, the words they reach for."
|
||||
onCommit={(voice) => patch({ voice })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Appearance"
|
||||
value={character.appearance}
|
||||
multiline
|
||||
onCommit={(appearance) => patch({ appearance })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Personality"
|
||||
value={character.personality}
|
||||
multiline
|
||||
onCommit={(personality) => patch({ personality })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 grid gap-4">
|
||||
<AutoField
|
||||
label="Backstory"
|
||||
value={character.backstory}
|
||||
multiline
|
||||
rows={5}
|
||||
serif
|
||||
onCommit={(backstory) => patch({ backstory })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Notes"
|
||||
value={character.notes}
|
||||
multiline
|
||||
onCommit={(notes) => patch({ notes })}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{character.relationships.length > 0 && (
|
||||
<div className="mt-6">
|
||||
<h3 className="label">Relationships</h3>
|
||||
<ul className="grid gap-1 text-sm">
|
||||
{character.relationships.map((relationship) => (
|
||||
<li key={relationship.id}>
|
||||
<span className="font-medium">{relationship.relatedCharacterName}</span>
|
||||
<span className="muted"> — {relationship.relationshipType}</span>
|
||||
{relationship.description && <span className="muted">: {relationship.description}</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{update.error && (
|
||||
<div className="mt-4">
|
||||
<ErrorNote error={update.error} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function AddCharacterModal({
|
||||
projectId,
|
||||
onClose,
|
||||
onCreated,
|
||||
}: {
|
||||
projectId: string
|
||||
onClose: () => void
|
||||
onCreated: (id: string) => void
|
||||
}) {
|
||||
const create = useCreateCharacter(projectId)
|
||||
const [name, setName] = useState('')
|
||||
const [role, setRole] = useState<Character['role']>('Supporting')
|
||||
|
||||
const submit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!name.trim()) return
|
||||
create.mutate(
|
||||
{ name: name.trim(), role },
|
||||
{
|
||||
onSuccess: (character) => {
|
||||
onCreated(character.id)
|
||||
onClose()
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal title="Add character" onClose={onClose}>
|
||||
<form onSubmit={submit} className="grid gap-3">
|
||||
<label className="block">
|
||||
<span className="label">Name</span>
|
||||
<input className="input" autoFocus value={name} onChange={(e) => setName(e.target.value)} />
|
||||
</label>
|
||||
<Select label="Role" value={role} options={characterRoles} onChange={setRole} />
|
||||
{create.error && <ErrorNote error={create.error} />}
|
||||
<div className="mt-1 flex justify-end gap-2">
|
||||
<button type="button" className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button className="btn btn-primary" disabled={!name.trim() || create.isPending}>
|
||||
Add
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useChapters, useCharacters, useDeleteProject, useProject, useUpdateProject } from '../api/hooks'
|
||||
import { AutoField, ErrorNote, Spinner } from '../components/ui'
|
||||
|
||||
export default function OverviewPage() {
|
||||
const { projectId = '' } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const { data: project, isPending } = useProject(projectId)
|
||||
const { data: characters } = useCharacters(projectId)
|
||||
const { data: chapters } = useChapters(projectId)
|
||||
const update = useUpdateProject(projectId)
|
||||
const remove = useDeleteProject()
|
||||
|
||||
if (isPending || !project) return <Spinner label="Loading brief" />
|
||||
|
||||
const drafted = chapters?.reduce((sum, c) => sum + c.wordCount, 0) ?? 0
|
||||
const target = project.targetWordCount ?? 0
|
||||
const percent = target > 0 ? Math.min(100, Math.round((drafted / target) * 100)) : null
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-[1fr_18rem]">
|
||||
<section className="card p-5">
|
||||
<h2 className="mb-4 text-sm font-semibold tracking-wide uppercase muted">The brief</h2>
|
||||
<div className="grid gap-4">
|
||||
<AutoField
|
||||
label="Title"
|
||||
value={project.title}
|
||||
onCommit={(title) => title.trim() && update.mutate({ title })}
|
||||
/>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
<AutoField
|
||||
label="Author"
|
||||
value={project.author}
|
||||
onCommit={(author) => update.mutate({ author })}
|
||||
/>
|
||||
<AutoField label="Genre" value={project.genre} onCommit={(genre) => update.mutate({ genre })} />
|
||||
</div>
|
||||
<AutoField
|
||||
label="Logline"
|
||||
value={project.logline}
|
||||
multiline
|
||||
rows={2}
|
||||
placeholder="Who wants what, and what stands in the way."
|
||||
onCommit={(logline) => update.mutate({ logline })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Synopsis"
|
||||
value={project.synopsis}
|
||||
multiline
|
||||
rows={8}
|
||||
serif
|
||||
placeholder="The whole story in a few paragraphs, ending included."
|
||||
onCommit={(synopsis) => update.mutate({ synopsis })}
|
||||
/>
|
||||
<AutoField
|
||||
label="Notes"
|
||||
value={project.notes}
|
||||
multiline
|
||||
rows={4}
|
||||
placeholder="Theme, tone, comparable titles, research threads."
|
||||
onCommit={(notes) => update.mutate({ notes })}
|
||||
/>
|
||||
<label className="block max-w-48">
|
||||
<span className="label">Target word count</span>
|
||||
<input
|
||||
className="input"
|
||||
type="number"
|
||||
min={0}
|
||||
step={1000}
|
||||
defaultValue={project.targetWordCount ?? ''}
|
||||
onBlur={(e) => {
|
||||
const value = Number(e.target.value)
|
||||
if (Number.isFinite(value) && value !== project.targetWordCount) {
|
||||
update.mutate({ targetWordCount: value || null })
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
{update.error && (
|
||||
<div className="mt-3">
|
||||
<ErrorNote error={update.error} />
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<aside className="grid content-start gap-4">
|
||||
<div className="card p-5">
|
||||
<h2 className="mb-3 text-sm font-semibold tracking-wide uppercase muted">Progress</h2>
|
||||
<p className="text-2xl font-semibold">{drafted.toLocaleString()}</p>
|
||||
<p className="text-sm muted">
|
||||
words drafted{target > 0 && ` of ${target.toLocaleString()}`}
|
||||
</p>
|
||||
{percent !== null && (
|
||||
<div
|
||||
className="mt-3 h-1.5 overflow-hidden rounded-full"
|
||||
style={{ background: 'var(--surface-sunken)' }}
|
||||
>
|
||||
<div
|
||||
className="h-full rounded-full transition-all"
|
||||
style={{ width: `${percent}%`, background: 'var(--accent)' }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<dl className="mt-4 grid grid-cols-2 gap-3 text-sm">
|
||||
<div>
|
||||
<dt className="muted">Characters</dt>
|
||||
<dd className="font-medium">{characters?.length ?? 0}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt className="muted">Chapters</dt>
|
||||
<dd className="font-medium">{chapters?.length ?? 0}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</div>
|
||||
|
||||
<div className="card p-5">
|
||||
<h2 className="mb-2 text-sm font-semibold tracking-wide uppercase muted">Danger zone</h2>
|
||||
<p className="mb-3 text-sm muted">
|
||||
Deleting a novel removes its outline, characters, chapters and conversations.
|
||||
</p>
|
||||
<button
|
||||
className="btn w-full"
|
||||
style={{ color: 'var(--accent)' }}
|
||||
onClick={() => {
|
||||
if (confirm(`Delete “${project.title}” and everything in it? This cannot be undone.`)) {
|
||||
remove.mutate(projectId, { onSuccess: () => navigate('/') })
|
||||
}
|
||||
}}
|
||||
>
|
||||
Delete this novel
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import { NavLink, Outlet, useParams, Link } from 'react-router-dom'
|
||||
import { useProject } from '../api/hooks'
|
||||
import { ErrorNote, Spinner } from '../components/ui'
|
||||
|
||||
const tabs = [
|
||||
{ to: '', label: 'Overview', end: true },
|
||||
{ to: 'characters', label: 'Characters' },
|
||||
{ to: 'chapters', label: 'Chapters' },
|
||||
{ to: 'tags', label: 'Tags' },
|
||||
{ to: 'agent', label: 'Agent' },
|
||||
]
|
||||
|
||||
export default function ProjectLayout() {
|
||||
const { projectId = '' } = useParams()
|
||||
const { data: project, isPending, error } = useProject(projectId)
|
||||
|
||||
return (
|
||||
<div className="min-h-full">
|
||||
<header className="sticky top-0 z-10 border-b" style={{ borderColor: 'var(--line)', background: 'var(--surface)' }}>
|
||||
<div className="mx-auto flex max-w-6xl items-center gap-4 px-6 py-3">
|
||||
<Link to="/" className="text-sm muted hover:underline">
|
||||
← Novels
|
||||
</Link>
|
||||
<h1 className="truncate text-base font-semibold">{project?.title ?? '…'}</h1>
|
||||
</div>
|
||||
<nav className="mx-auto flex max-w-6xl gap-1 px-4">
|
||||
{tabs.map((tab) => (
|
||||
<NavLink
|
||||
key={tab.label}
|
||||
to={tab.to}
|
||||
end={tab.end}
|
||||
className={({ isActive }) =>
|
||||
`border-b-2 px-3 py-2 text-sm font-medium transition ${
|
||||
isActive ? 'border-current' : 'border-transparent'
|
||||
}`
|
||||
}
|
||||
style={({ isActive }) => ({ color: isActive ? 'var(--accent)' : 'var(--ink-muted)' })}
|
||||
>
|
||||
{tab.label}
|
||||
</NavLink>
|
||||
))}
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main className="mx-auto max-w-6xl px-6 py-8">
|
||||
{error && <ErrorNote error={error} />}
|
||||
{isPending ? <Spinner label="Loading project" /> : <Outlet context={{ projectId }} />}
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useCreateProject, useProjects } from '../api/hooks'
|
||||
import { EmptyState, ErrorNote, Modal, Spinner } from '../components/ui'
|
||||
|
||||
export default function ProjectsPage() {
|
||||
const { data: projects, isPending, error } = useProjects()
|
||||
const [creating, setCreating] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl px-6 py-12">
|
||||
<header className="mb-8 flex items-end justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-3xl font-semibold tracking-tight">Your novels</h1>
|
||||
<p className="mt-1 text-sm muted">
|
||||
Outlines, character dossiers, and a writing partner that knows the book.
|
||||
</p>
|
||||
</div>
|
||||
<button className="btn btn-primary" onClick={() => setCreating(true)}>
|
||||
New novel
|
||||
</button>
|
||||
</header>
|
||||
|
||||
{error && <ErrorNote error={error} />}
|
||||
{isPending && <Spinner label="Loading projects" />}
|
||||
|
||||
{projects?.length === 0 && (
|
||||
<EmptyState
|
||||
title="Nothing here yet"
|
||||
hint="Start with a title and a one-sentence logline. Everything else can come later."
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="grid gap-3">
|
||||
{projects?.map((project) => (
|
||||
<Link
|
||||
key={project.id}
|
||||
to={`/projects/${project.id}`}
|
||||
className="card block px-5 py-4 transition hover:shadow-md"
|
||||
>
|
||||
<div className="flex items-baseline justify-between gap-4">
|
||||
<h2 className="text-lg font-semibold">{project.title}</h2>
|
||||
<span className="text-xs muted">
|
||||
{project.genre ?? 'Uncategorised'}
|
||||
{project.author && ` · ${project.author}`}
|
||||
</span>
|
||||
</div>
|
||||
{project.logline && <p className="mt-1 text-sm muted">{project.logline}</p>}
|
||||
<div className="mt-3 flex gap-4 text-xs muted">
|
||||
<span>{project.characterCount} characters</span>
|
||||
<span>{project.chapterCount} chapters</span>
|
||||
<span>
|
||||
{project.wordCount.toLocaleString()}
|
||||
{project.targetWordCount
|
||||
? ` / ${project.targetWordCount.toLocaleString()} words`
|
||||
: ' words'}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{creating && <CreateProjectModal onClose={() => setCreating(false)} />}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function CreateProjectModal({ onClose }: { onClose: () => void }) {
|
||||
const create = useCreateProject()
|
||||
const [title, setTitle] = useState('')
|
||||
const [author, setAuthor] = useState('')
|
||||
const [genre, setGenre] = useState('')
|
||||
const [logline, setLogline] = useState('')
|
||||
|
||||
const submit = (e: React.FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!title.trim()) return
|
||||
create.mutate(
|
||||
{
|
||||
title: title.trim(),
|
||||
author: author.trim() || undefined,
|
||||
genre: genre.trim() || undefined,
|
||||
logline: logline.trim() || undefined,
|
||||
},
|
||||
{ onSuccess: onClose },
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal title="New novel" onClose={onClose}>
|
||||
<form onSubmit={submit} className="grid gap-3">
|
||||
<label className="block">
|
||||
<span className="label">Title</span>
|
||||
<input
|
||||
className="input"
|
||||
autoFocus
|
||||
value={title}
|
||||
onChange={(e) => setTitle(e.target.value)}
|
||||
placeholder="Working title"
|
||||
/>
|
||||
</label>
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<label className="block">
|
||||
<span className="label">Author</span>
|
||||
<input className="input" value={author} onChange={(e) => setAuthor(e.target.value)} />
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="label">Genre</span>
|
||||
<input className="input" value={genre} onChange={(e) => setGenre(e.target.value)} />
|
||||
</label>
|
||||
</div>
|
||||
<label className="block">
|
||||
<span className="label">Logline</span>
|
||||
<textarea
|
||||
className="input"
|
||||
rows={2}
|
||||
value={logline}
|
||||
onChange={(e) => setLogline(e.target.value)}
|
||||
placeholder="One sentence: who wants what, and what stands in the way."
|
||||
/>
|
||||
</label>
|
||||
|
||||
{create.error && <ErrorNote error={create.error} />}
|
||||
|
||||
<div className="mt-1 flex justify-end gap-2">
|
||||
<button type="button" className="btn" onClick={onClose}>
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" className="btn btn-primary" disabled={!title.trim() || create.isPending}>
|
||||
{create.isPending ? 'Creating…' : 'Create'}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,180 @@
|
||||
import { useState } from 'react'
|
||||
import { Link, useParams } from 'react-router-dom'
|
||||
import { useDeleteTag, useTagReferences, useTags, useUpdateTag } from '../api/hooks'
|
||||
import { EmptyState, ErrorNote, Spinner } from '../components/ui'
|
||||
import { TagChip } from '../components/TagEditor'
|
||||
|
||||
export default function TagsPage() {
|
||||
const { projectId = '' } = useParams()
|
||||
const { data: tags, isPending, error } = useTags(projectId)
|
||||
const [selectedId, setSelectedId] = useState<string | undefined>()
|
||||
|
||||
if (isPending) return <Spinner label="Loading tags" />
|
||||
if (error) return <ErrorNote error={error} />
|
||||
|
||||
const selected = tags?.find((t) => t.id === selectedId) ?? tags?.[0]
|
||||
|
||||
return (
|
||||
<div className="grid gap-6 lg:grid-cols-[18rem_1fr]">
|
||||
<aside className="grid content-start gap-2">
|
||||
<div>
|
||||
<h2 className="text-lg font-semibold">Tags</h2>
|
||||
<p className="text-sm muted">
|
||||
Applied from a character, chapter or beat. Pick one to see everything carrying it.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{tags?.length === 0 && (
|
||||
<p className="mt-2 text-sm muted">
|
||||
No tags yet. Add one from a character, chapter or beat and it will appear here.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{tags?.map((tag) => (
|
||||
<button
|
||||
key={tag.id}
|
||||
onClick={() => setSelectedId(tag.id)}
|
||||
className="card flex items-center justify-between gap-2 px-3 py-2 text-left transition hover:shadow-sm"
|
||||
style={
|
||||
tag.id === selected?.id
|
||||
? { borderColor: 'var(--accent)', background: 'var(--accent-soft)' }
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<TagChip tag={tag} />
|
||||
<span className="text-xs muted">{tag.totalCount}</span>
|
||||
</button>
|
||||
))}
|
||||
</aside>
|
||||
|
||||
<section>
|
||||
{!selected ? (
|
||||
<EmptyState
|
||||
title="Nothing tagged yet"
|
||||
hint="Tags cross-reference the book: attach one to a character, a chapter and a beat, then trace it from here."
|
||||
/>
|
||||
) : (
|
||||
<TagReferencePanel key={selected.id} projectId={projectId} tagId={selected.id} />
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function TagReferencePanel({ projectId, tagId }: { projectId: string; tagId: string }) {
|
||||
const { data, isPending, error } = useTagReferences(tagId)
|
||||
const update = useUpdateTag(projectId)
|
||||
const remove = useDeleteTag()
|
||||
|
||||
if (isPending) return <Spinner label="Loading references" />
|
||||
if (error) return <ErrorNote error={error} />
|
||||
if (!data) return null
|
||||
|
||||
const empty =
|
||||
data.characters.length === 0 && data.chapters.length === 0 && data.beats.length === 0
|
||||
|
||||
return (
|
||||
<div className="grid gap-4">
|
||||
<div className="card flex flex-wrap items-end justify-between gap-3 p-4">
|
||||
<label className="block">
|
||||
<span className="label">Tag name</span>
|
||||
<input
|
||||
className="input w-64"
|
||||
defaultValue={data.tag.name}
|
||||
onBlur={(e) => {
|
||||
const name = e.target.value.trim()
|
||||
if (name && name !== data.tag.name) update.mutate({ id: tagId, name })
|
||||
}}
|
||||
/>
|
||||
</label>
|
||||
<label className="block">
|
||||
<span className="label">Colour</span>
|
||||
<input
|
||||
className="input h-9 w-20 p-1"
|
||||
type="color"
|
||||
defaultValue={data.tag.color ?? '#9a4a2f'}
|
||||
onBlur={(e) => update.mutate({ id: tagId, color: e.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
className="btn"
|
||||
style={{ color: 'var(--accent)' }}
|
||||
onClick={() =>
|
||||
confirm(`Delete the tag “${data.tag.name}”? What carries it is left alone.`) &&
|
||||
remove.mutate(tagId)
|
||||
}
|
||||
>
|
||||
Delete tag
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{update.error && <ErrorNote error={update.error} />}
|
||||
|
||||
{empty && (
|
||||
<EmptyState
|
||||
title="Nothing carries this tag"
|
||||
hint="Apply it from a character, chapter or beat and it will show up here."
|
||||
/>
|
||||
)}
|
||||
|
||||
{data.characters.length > 0 && (
|
||||
<div className="card p-4">
|
||||
<h3 className="label">Characters</h3>
|
||||
<ul className="grid gap-1 text-sm">
|
||||
{data.characters.map((c) => (
|
||||
<li key={c.id}>
|
||||
<Link to={`/projects/${projectId}/characters`} className="hover:underline">
|
||||
{c.name}
|
||||
</Link>
|
||||
<span className="muted"> — {c.role}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.chapters.length > 0 && (
|
||||
<div className="card p-4">
|
||||
<h3 className="label">Chapters</h3>
|
||||
<ul className="grid gap-1 text-sm">
|
||||
{data.chapters.map((c) => (
|
||||
<li key={c.id}>
|
||||
<Link
|
||||
to={`/projects/${projectId}/chapters/${c.id}`}
|
||||
className="font-medium hover:underline"
|
||||
>
|
||||
{c.number}. {c.title}
|
||||
</Link>
|
||||
{c.summary && <span className="muted"> — {c.summary}</span>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{data.beats.length > 0 && (
|
||||
<div className="card p-4">
|
||||
<h3 className="label">Beats</h3>
|
||||
<ul className="grid gap-2 text-sm">
|
||||
{data.beats.map((b) => (
|
||||
<li key={b.id}>
|
||||
<Link
|
||||
to={`/projects/${projectId}/chapters/${b.chapterId}`}
|
||||
className="font-medium hover:underline"
|
||||
>
|
||||
{b.title}
|
||||
</Link>
|
||||
<span className="muted">
|
||||
{' '}
|
||||
— ch. {b.chapterNumber} “{b.chapterTitle}”, beat {b.sortOrder}
|
||||
{b.characterName && `, ${b.characterName}`}
|
||||
</span>
|
||||
{b.whatHappened && <div className="prose-serif muted">{b.whatHappened}</div>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023", "DOM"],
|
||||
"module": "esnext",
|
||||
"types": ["vite/client"],
|
||||
"allowArbitraryExtensions": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "es2023",
|
||||
"lib": ["ES2023"],
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"module": "nodenext",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
server: {
|
||||
port: 5173,
|
||||
// Proxy the API in dev so the browser sees a single origin and CORS never enters
|
||||
// the picture during local development.
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: process.env.VITE_API_URL ?? 'http://localhost:5080',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user