import Button from 'react-bootstrap/Button' import { Form, Input, SubmitButton } from '../components/form' import { useRouter } from 'next/router' import Link from 'next/link' import * as Yup from 'yup' import { gql, useMutation } from '@apollo/client' import LayoutCenter from '../components/layout-center' import { ensureProtocol } from '../lib/url' export const DiscussionSchema = Yup.object({ title: Yup.string().required('required').trim() }) export function DiscussionForm () { const router = useRouter() const [createDiscussion] = useMutation( gql` mutation createDiscussion($title: String!, $text: String) { createDiscussion(title: $title, text: $text) { id } }` ) return (
{ const { data: { createDiscussion: { id } }, error } = await createDiscussion({ variables: values }) if (error) { throw new Error({ message: error.toString() }) } router.push(`items/${id}`) }} > text optional} name='text' as='textarea' rows={4} /> post
) } export const LinkSchema = Yup.object({ title: Yup.string().required('required').trim(), url: Yup.string().test({ name: 'url', test: (value) => { try { value = ensureProtocol(value) const valid = new URL(value) return Boolean(valid) } catch { return false } }, message: 'invalid url' }).required('required') }) export function LinkForm () { const router = useRouter() const [createLink] = useMutation( gql` mutation createLink($title: String!, $url: String!) { createLink(title: $title, url: $url) { id } }` ) return (
{ const { data: { createLink: { id } }, error } = await createLink({ variables: values }) if (error) { throw new Error({ message: error.toString() }) } router.push(`items/${id}`) }} > post
) } export function PostForm () { const router = useRouter() if (!router.query.type) { return (
or
) } if (router.query.type === 'discussion') { return } else { return } } export default function Post () { return ( ) }