From 027ba6a04863d73e3ac4c4d01e5861f5866b129b Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 23 Sep 2021 17:18:48 -0500 Subject: [PATCH] WIP user bio --- api/resolvers/item.js | 1 - api/resolvers/user.js | 1 - components/item-full.js | 7 +++++++ pages/[username].js | 8 ++++---- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 812ddd59..68272b1b 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -22,7 +22,6 @@ async function comments (models, id) { } export async function getItem (parent, { id }, { models }) { - console.log(id) const [item] = await models.$queryRaw(` ${SELECT} FROM "Item" diff --git a/api/resolvers/user.js b/api/resolvers/user.js index c62357e5..63da54a1 100644 --- a/api/resolvers/user.js +++ b/api/resolvers/user.js @@ -73,7 +73,6 @@ export default { return Math.floor(user.msats / 1000) }, bio: async (user, args, { models }) => { - console.log(user) return getItem(user, { id: user.bioId }, { models }) }, hasNewNotes: async (user, args, { models }) => { diff --git a/components/item-full.js b/components/item-full.js index a2e33ff9..0aec76ce 100644 --- a/components/item-full.js +++ b/components/item-full.js @@ -9,8 +9,11 @@ import { gql, useQuery } from '@apollo/client' import styles from '../styles/item.module.css' import { NOFOLLOW_LIMIT } from '../lib/constants' import { useRouter } from 'next/router' +import Link from 'next/link' +import { useMe } from './me' function BioItem ({ item }) { + const me = useMe() if (!item.text) { return null } @@ -18,6 +21,10 @@ function BioItem ({ item }) { return ( <> + {me?.name === item.user.name && + + edit bio + } ) diff --git a/pages/[username].js b/pages/[username].js index a974878c..df8dd71d 100644 --- a/pages/[username].js +++ b/pages/[username].js @@ -13,6 +13,7 @@ import * as Yup from 'yup' import { Form, MarkdownInput, SubmitButton } from '../components/form' import ActionTooltip from '../components/action-tooltip' import TextareaAutosize from 'react-textarea-autosize' +import { useMe } from '../components/me' export async function getServerSideProps ({ req, params }) { const { error, data: { user } } = await (await ApolloClient(req)).query({ @@ -52,7 +53,7 @@ const BioSchema = Yup.object({ bio: Yup.string().required('required').trim() }) -function BioForm () { +export function BioForm () { const [createBio] = useMutation( gql` mutation createBio($bio: String!) { @@ -103,8 +104,7 @@ function BioForm () { export default function User ({ user }) { const [create, setCreate] = useState(false) const [session] = useSession() - - // need to check if this is the user's page before exposing create/edit + const me = useMe() return ( @@ -112,7 +112,7 @@ export default function User ({ user }) { {user.bio ? - : ( + : (me?.name === user.name &&
{create ?