WIP user bio

This commit is contained in:
keyan 2021-09-23 17:18:48 -05:00
parent 56a3dc9793
commit 027ba6a048
4 changed files with 11 additions and 6 deletions

View File

@ -22,7 +22,6 @@ async function comments (models, id) {
} }
export async function getItem (parent, { id }, { models }) { export async function getItem (parent, { id }, { models }) {
console.log(id)
const [item] = await models.$queryRaw(` const [item] = await models.$queryRaw(`
${SELECT} ${SELECT}
FROM "Item" FROM "Item"

View File

@ -73,7 +73,6 @@ export default {
return Math.floor(user.msats / 1000) return Math.floor(user.msats / 1000)
}, },
bio: async (user, args, { models }) => { bio: async (user, args, { models }) => {
console.log(user)
return getItem(user, { id: user.bioId }, { models }) return getItem(user, { id: user.bioId }, { models })
}, },
hasNewNotes: async (user, args, { models }) => { hasNewNotes: async (user, args, { models }) => {

View File

@ -9,8 +9,11 @@ import { gql, useQuery } from '@apollo/client'
import styles from '../styles/item.module.css' import styles from '../styles/item.module.css'
import { NOFOLLOW_LIMIT } from '../lib/constants' import { NOFOLLOW_LIMIT } from '../lib/constants'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import Link from 'next/link'
import { useMe } from './me'
function BioItem ({ item }) { function BioItem ({ item }) {
const me = useMe()
if (!item.text) { if (!item.text) {
return null return null
} }
@ -18,6 +21,10 @@ function BioItem ({ item }) {
return ( return (
<> <>
<ItemText item={item} /> <ItemText item={item} />
{me?.name === item.user.name &&
<Link href={`/items/${item.id}/edit`} passHref>
<a className='text-right'>edit bio</a>
</Link>}
<Reply parentId={item.id} /> <Reply parentId={item.id} />
</> </>
) )

View File

@ -13,6 +13,7 @@ import * as Yup from 'yup'
import { Form, MarkdownInput, SubmitButton } from '../components/form' import { Form, MarkdownInput, SubmitButton } from '../components/form'
import ActionTooltip from '../components/action-tooltip' import ActionTooltip from '../components/action-tooltip'
import TextareaAutosize from 'react-textarea-autosize' import TextareaAutosize from 'react-textarea-autosize'
import { useMe } from '../components/me'
export async function getServerSideProps ({ req, params }) { export async function getServerSideProps ({ req, params }) {
const { error, data: { user } } = await (await ApolloClient(req)).query({ const { error, data: { user } } = await (await ApolloClient(req)).query({
@ -52,7 +53,7 @@ const BioSchema = Yup.object({
bio: Yup.string().required('required').trim() bio: Yup.string().required('required').trim()
}) })
function BioForm () { export function BioForm () {
const [createBio] = useMutation( const [createBio] = useMutation(
gql` gql`
mutation createBio($bio: String!) { mutation createBio($bio: String!) {
@ -103,8 +104,7 @@ function BioForm () {
export default function User ({ user }) { export default function User ({ user }) {
const [create, setCreate] = useState(false) const [create, setCreate] = useState(false)
const [session] = useSession() const [session] = useSession()
const me = useMe()
// need to check if this is the user's page before exposing create/edit
return ( return (
<Layout noSeo containClassName={styles.contain}> <Layout noSeo containClassName={styles.contain}>
@ -112,7 +112,7 @@ export default function User ({ user }) {
<UserHeader user={user} /> <UserHeader user={user} />
{user.bio {user.bio
? <ItemFull item={user.bio} bio /> ? <ItemFull item={user.bio} bio />
: ( : (me?.name === user.name &&
<div className={styles.create}> <div className={styles.create}>
{create {create
? <BioForm /> ? <BioForm />