diff --git a/components/comment-edit.js b/components/comment-edit.js index f261bf3f..211a0058 100644 --- a/components/comment-edit.js +++ b/components/comment-edit.js @@ -3,7 +3,6 @@ import * as Yup from 'yup' import { gql, useMutation } from '@apollo/client' import styles from './reply.module.css' import TextareaAutosize from 'react-textarea-autosize' -import Countdown from '../components/countdown' export const CommentSchema = Yup.object({ text: Yup.string().required('required').trim() @@ -53,19 +52,8 @@ export default function CommentEdit ({ comment, editThreshold, onSuccess, onCanc minRows={4} autoFocus required - groupClassName='mb-0' - hint={} /> -
- save -
- cancel -
-
+ save ) diff --git a/components/comment.js b/components/comment.js index e998a15e..3730edc3 100644 --- a/components/comment.js +++ b/components/comment.js @@ -41,9 +41,8 @@ function Parent ({ item, rootText }) { export default function Comment ({ item, children, replyOpen, includeParent, - rootText, noComments, noReply + rootText, noComments }) { - const [reply, setReply] = useState(replyOpen) const [edit, setEdit] = useState() const [collapse, setCollapse] = useState(false) const ref = useRef(null) @@ -92,28 +91,36 @@ export default function Comment ({ {timeSince(new Date(item.createdAt))} {includeParent && } + {canEdit && + <> + \ +
setEdit(!edit)} + > + {edit ? 'cancel' : 'edit'} + { + setCanEdit(false) + }} + /> +
+ } {!includeParent && (collapse ? setCollapse(false)} /> : setCollapse(true)} />)} - {edit ? ( -
- { - setEdit(!edit) - setCanEdit(mine && (Date.now() < editThreshold)) - }} - onCancel={() => { - setEdit(!edit) - setCanEdit(mine && (Date.now() < editThreshold)) - }} - editThreshold={editThreshold} - /> -
+ { + setEdit(!edit) + setCanEdit(mine && (Date.now() < editThreshold)) + }} + /> ) : (
@@ -123,40 +130,9 @@ export default function Comment ({
- {!noReply && !edit && ( -
-
setReply(!reply)} - > - {reply ? 'cancel' : 'reply'} -
- {canEdit && !reply && !edit && - <> - \ -
setEdit(!edit)} - > - edit - { - setCanEdit(false) - }} - /> -
- } -
- )} - -
- setReply(replyOpen || false)} - /> -
+ {children}
{item.comments && !noComments diff --git a/components/comment.module.css b/components/comment.module.css index d22ce425..c0b7661e 100644 --- a/components/comment.module.css +++ b/components/comment.module.css @@ -11,6 +11,11 @@ padding-right: 15px; } +.edit { + display: inline-block; + cursor: pointer; +} + .collapsed .hunk { margin-bottom: .5rem; } @@ -33,20 +38,8 @@ user-select: none; } -.reply { - font-weight: bold; - cursor: pointer; - padding-bottom: .5rem; -} - -.replyWrapper { - padding-right: 15px; - padding-bottom: .5rem; -} - .children { margin-top: 0; - padding-top: .25rem; margin-left: 24px; } diff --git a/components/countdown.js b/components/countdown.js index 3c09bff2..a02b0811 100644 --- a/components/countdown.js +++ b/components/countdown.js @@ -2,7 +2,7 @@ import Countdown from 'react-countdown' export default function SimpleCountdown ({ className, onComplete, date }) { return ( - + {props.formatted.minutes}:{props.formatted.seconds}} diff --git a/components/item-full.js b/components/item-full.js index a6cd87bf..a2e33ff9 100644 --- a/components/item-full.js +++ b/components/item-full.js @@ -10,7 +10,33 @@ import styles from '../styles/item.module.css' import { NOFOLLOW_LIMIT } from '../lib/constants' import { useRouter } from 'next/router' -export default function ItemFull ({ item: qItem, minimal }) { +function BioItem ({ item }) { + if (!item.text) { + return null + } + + return ( + <> + + + + ) +} + +function TopLevelItem ({ item }) { + return ( + + {item.text && } + + + ) +} + +function ItemText ({ item }) { + return {item.text} +} + +export default function ItemFull ({ item: qItem, bio }) { const query = gql` ${ITEM_FIELDS} ${COMMENTS} @@ -49,24 +75,9 @@ export default function ItemFull ({ item: qItem, minimal }) { <> {item.parentId ? - : (minimal - ? ( - <> - {item.text && -
- {item.text} -
} - ) - : ( - <> - - {item.text && -
- {item.text} -
} - -
- ) + : (bio + ? + : )}
diff --git a/components/reply.js b/components/reply.js index 8ba87042..0d223434 100644 --- a/components/reply.js +++ b/components/reply.js @@ -6,12 +6,14 @@ import { COMMENTS } from '../fragments/comments' import { useMe } from './me' import ActionTooltip from './action-tooltip' import TextareaAutosize from 'react-textarea-autosize' +import { useState } from 'react' export const CommentSchema = Yup.object({ text: Yup.string().required('required').trim() }) -export default function Reply ({ parentId, onSuccess, autoFocus }) { +export default function Reply ({ parentId, onSuccess, replyOpen }) { + const [reply, setReply] = useState(replyOpen) const me = useMe() const [createComment] = useMutation( @@ -47,35 +49,41 @@ export default function Reply ({ parentId, onSuccess, autoFocus }) { ) return ( -
-
{ - const { error } = await createComment({ variables: { ...values, parentId } }) - if (error) { - throw new Error({ message: error.toString() }) - } - resetForm({ text: '' }) - if (onSuccess) { - onSuccess() - } - }} +
+
setReply(!reply)} > - {me.freeComments} free comments left : null} - /> - - reply - - + {reply ? 'cancel' : 'reply'} +
+
+
{ + const { error } = await createComment({ variables: { ...values, parentId } }) + if (error) { + throw new Error({ message: error.toString() }) + } + resetForm({ text: '' }) + setReply(replyOpen || false) + }} + > + {me.freeComments} free comments left : null} + /> + + reply + + +
) } diff --git a/components/reply.module.css b/components/reply.module.css index 007ef7e4..91c9c637 100644 --- a/components/reply.module.css +++ b/components/reply.module.css @@ -1,5 +1,16 @@ .reply { max-width: 600px; + padding-right: 15px; + padding-bottom: .5rem; +} + +.replyButtons { + font-size: 70%; + color: grey; + font-weight: bold; + display: inline-block; + cursor: pointer; + padding-bottom: .5rem; } .skeleton .input { diff --git a/pages/[username].js b/pages/[username].js index bf221943..5cdc086c 100644 --- a/pages/[username].js +++ b/pages/[username].js @@ -85,12 +85,14 @@ export default function User ({ user }) { const [create, setCreate] = useState(false) const [session] = useSession() + // need to check if this is the user's page + return ( {user.bio - ? + ? : (
{create diff --git a/styles/item.module.css b/styles/item.module.css index 4d3efa70..6d487d0c 100644 --- a/styles/item.module.css +++ b/styles/item.module.css @@ -1,10 +1,10 @@ .comments { - margin-top: 3rem; + margin-top: 1rem; } @media only screen and (max-width: 600px) { .comments { - margin-top: 3rem; + margin-top: 1rem; margin-left: -15px; margin-right: -15px; }