Skip to content

Commit

Permalink
Add optional title attribute to glossary
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiodxa committed Feb 24, 2024
1 parent 3162abe commit bc937e7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/models/glossary.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Post } from "~/models/post.server";
interface GlossaryMeta extends BaseMeta {
slug: string;
term: string;
title?: string;
definition: string;
}

Expand Down Expand Up @@ -35,6 +36,10 @@ export class Glossary extends Post<GlossaryMeta> {
return this.meta.term;
}

get title() {
return this.meta.title;
}

get definition() {
return this.meta.definition;
}
Expand Down
22 changes: 17 additions & 5 deletions app/routes/_.cms.glossary/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ export async function action({ request, context }: ActionFunctionArgs) {
let intent = formData.get("intent");

if (intent === INTENT.create) {
let { term, definition } = Schemas.formData()
.pipe(z.object({ term: z.string(), definition: z.string() }))
let { term, title, definition } = Schemas.formData()
.pipe(
z.object({
term: z.string(),
title: z.string().optional(),
definition: z.string(),
}),
)
.parse(formData);

let slug = parameterize(term);
Expand All @@ -33,7 +39,7 @@ export async function action({ request, context }: ActionFunctionArgs) {

await Glossary.create(
{ db },
{ authorId: user.id, slug, term, definition },
{ authorId: user.id, slug, term, title, definition },
);

let cache = new Cache.KVStore(context.kv.cache, context.waitUntil);
Expand All @@ -58,8 +64,14 @@ export default function Component() {

<Form method="post" className="max-w-xs">
<input type="hidden" name="intent" value={INTENT.create} />
<TextField label="Term" name="term" />
<TextField type="textarea" label="Definition" name="definition" />
<TextField label="Term" name="term" isRequired />
<TextField label="Title" name="title" />
<TextField
type="textarea"
label="Definition"
name="definition"
isRequired
/>

<Button type="submit" variant="primary">
Create
Expand Down

0 comments on commit bc937e7

Please sign in to comment.