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' import { useMe } from '../components/me' 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 (
) } 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 ( ) } export function PostForm () { const router = useRouter() const me = useMe() if (!router.query.type) { return (