diff --git a/common/post.ts b/common/post.ts index 45503b22..77130a2c 100644 --- a/common/post.ts +++ b/common/post.ts @@ -3,6 +3,7 @@ import { JSONContent } from '@tiptap/core' export type Post = { id: string title: string + subtitle: string content: JSONContent creatorId: string // User id createdTime: number @@ -17,3 +18,4 @@ export type DateDoc = Post & { } export const MAX_POST_TITLE_LENGTH = 480 +export const MAX_POST_SUBTITLE_LENGTH = 480 diff --git a/functions/src/create-post.ts b/functions/src/create-post.ts index e9d6ae8f..96e3c66a 100644 --- a/functions/src/create-post.ts +++ b/functions/src/create-post.ts @@ -3,7 +3,11 @@ import * as admin from 'firebase-admin' import { getUser } from './utils' import { slugify } from '../../common/util/slugify' import { randomString } from '../../common/util/random' -import { Post, MAX_POST_TITLE_LENGTH } from '../../common/post' +import { + Post, + MAX_POST_TITLE_LENGTH, + MAX_POST_SUBTITLE_LENGTH, +} from '../../common/post' import { APIError, newEndpoint, validate } from './api' import { JSONContent } from '@tiptap/core' import { z } from 'zod' @@ -36,6 +40,7 @@ const contentSchema: z.ZodType = z.lazy(() => const postSchema = z.object({ title: z.string().min(1).max(MAX_POST_TITLE_LENGTH), + subtitle: z.string().min(1).max(MAX_POST_SUBTITLE_LENGTH), content: contentSchema, groupId: z.string().optional(), @@ -48,10 +53,8 @@ const postSchema = z.object({ export const createpost = newEndpoint({}, async (req, auth) => { const firestore = admin.firestore() - const { title, content, groupId, question, ...otherProps } = validate( - postSchema, - req.body - ) + const { title, subtitle, content, groupId, question, ...otherProps } = + validate(postSchema, req.body) const creator = await getUser(auth.uid) if (!creator) @@ -89,6 +92,7 @@ export const createpost = newEndpoint({}, async (req, auth) => { creatorId: creator.id, slug, title, + subtitle, createdTime: Date.now(), content: content, contractSlug, diff --git a/web/components/create-post.tsx b/web/components/create-post.tsx index c176e61d..6d42051c 100644 --- a/web/components/create-post.tsx +++ b/web/components/create-post.tsx @@ -13,6 +13,8 @@ import { Group } from 'common/group' export function CreatePost(props: { group?: Group }) { const [title, setTitle] = useState('') + const [subtitle, setSubtitle] = useState('') + const [error, setError] = useState('') const [isSubmitting, setIsSubmitting] = useState(false) @@ -22,12 +24,17 @@ export function CreatePost(props: { group?: Group }) { disabled: isSubmitting, }) - const isValid = editor && title.length > 0 && editor.isEmpty === false + const isValid = + editor && + title.length > 0 && + subtitle.length > 0 && + editor.isEmpty === false async function savePost(title: string) { if (!editor) return const newPost = { title: title, + subtitle: subtitle, content: editor.getJSON(), groupId: group?.id, } @@ -62,6 +69,20 @@ export function CreatePost(props: { group?: Group }) { onChange={(e) => setTitle(e.target.value || '')} /> + +