-
- {mostRecentCommentableBet && (
-
+
+ {mostRecentCommentableBet && (
+
+ )}
+ {!mostRecentCommentableBet && user && userPosition > 0 && !isNumeric && (
+ <>
+ {"You're"}
+
- )}
- {!mostRecentCommentableBet && user && userPosition > 0 && !isNumeric && (
- <>
- {"You're"}
-
- >
- )}
-
-
+ >
+ )}
)
}
-export function CommentInputTextArea(props: {
- user: User | undefined | null
- replyToUser?: { id: string; username: string }
- editor: Editor | null
- upload: Parameters
[0]['upload']
- submitComment: (id?: string) => void
- isSubmitting: boolean
- submitOnEnter?: boolean
- presetId?: string
-}) {
- const {
- user,
- editor,
- upload,
- submitComment,
- presetId,
- isSubmitting,
- submitOnEnter,
- replyToUser,
- } = props
- const isMobile = (useWindowSize().width ?? 0) < 768 // TODO: base off input device (keybord vs touch)
-
- useEffect(() => {
- editor?.setEditable(!isSubmitting)
- }, [isSubmitting, editor])
-
- const submit = () => {
- submitComment(presetId)
- editor?.commands?.clearContent()
- }
-
- useEffect(() => {
- if (!editor) {
- return
- }
- // submit on Enter key
- editor.setOptions({
- editorProps: {
- handleKeyDown: (view, event) => {
- if (
- submitOnEnter &&
- event.key === 'Enter' &&
- !event.shiftKey &&
- (!isMobile || event.ctrlKey || event.metaKey) &&
- // mention list is closed
- !(view.state as any).mention$.active
- ) {
- submit()
- event.preventDefault()
- return true
- }
- return false
- },
- },
- })
- // insert at mention and focus
- if (replyToUser) {
- editor
- .chain()
- .setContent({
- type: 'mention',
- attrs: { label: replyToUser.username, id: replyToUser.id },
- })
- .insertContent(' ')
- .focus()
- .run()
- }
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [editor])
-
- return (
- <>
-
- {user && !isSubmitting && (
-
- )}
-
- {isSubmitting && (
-
- )}
-
-
- {!user && (
-
- )}
-
- >
- )
-}
-
function getBettorsLargestPositionBeforeTime(
contract: Contract,
createdTime: number,
diff --git a/web/components/groups/group-chat.tsx b/web/components/groups/group-chat.tsx
index 9a60c9c7..05fe2683 100644
--- a/web/components/groups/group-chat.tsx
+++ b/web/components/groups/group-chat.tsx
@@ -6,7 +6,6 @@ import { Avatar } from 'web/components/avatar'
import { Group } from 'common/group'
import { Comment, GroupComment } from 'common/comment'
import { createCommentOnGroup } from 'web/lib/firebase/comments'
-import { CommentInputTextArea } from 'web/components/feed/feed-comments'
import { track } from 'web/lib/service/analytics'
import { firebaseLogin } from 'web/lib/firebase/users'
import { useRouter } from 'next/router'
@@ -23,6 +22,7 @@ import { ChevronDownIcon, UsersIcon } from '@heroicons/react/outline'
import { setNotificationsAsSeen } from 'web/pages/notifications'
import { usePrivateUser } from 'web/hooks/use-user'
import { UserLink } from 'web/components/user-link'
+import { CommentInputTextArea } from '../comment-input'
export function GroupChat(props: {
messages: GroupComment[]
diff --git a/web/pages/post/[...slugs]/index.tsx b/web/pages/post/[...slugs]/index.tsx
index 28d02488..a323c66f 100644
--- a/web/pages/post/[...slugs]/index.tsx
+++ b/web/pages/post/[...slugs]/index.tsx
@@ -20,7 +20,7 @@ import { listAllCommentsOnPost } from 'web/lib/firebase/comments'
import { PostComment } from 'common/comment'
import { CommentTipMap, useTipTxns } from 'web/hooks/use-tip-txns'
import { groupBy, sortBy } from 'lodash'
-import { PostCommentThread, CommentInput } from 'web/posts/post-comments'
+import { PostCommentInput, PostCommentThread } from 'web/posts/post-comments'
import { useCommentsOnPost } from 'web/hooks/use-comments'
export async function getStaticProps(props: { params: { slugs: string[] } }) {
@@ -137,11 +137,7 @@ export function PostCommentsActivity(props: {
return (
<>
-
+
{topLevelComments.map((parent) => (
}) {
- const { user, post, threadComments, commentsByUserId, tips, parentComment } =
- props
+ const { post, threadComments, tips, parentComment } = props
const [showReply, setShowReply] = useState(false)
const [replyTo, setReplyTo] = useState<{ id: string; username: string }>()
@@ -63,9 +60,8 @@ export function PostCommentThread(props: {
className="absolute -left-1 -ml-[1px] mt-[0.8rem] h-2 w-0.5 rotate-90 bg-gray-200"
aria-hidden="true"
/>
- setShowReply(false)}
@@ -76,6 +72,34 @@ export function PostCommentThread(props: {
)
}
+export function PostCommentInput(props: {
+ post: Post
+ parentCommentId?: string
+ replyToUser?: { id: string; username: string }
+ onSubmitComment?: () => void
+}) {
+ const user = useUser()
+
+ const { post, parentCommentId, replyToUser } = props
+
+ async function onSubmitComment(editor: Editor) {
+ if (!user) {
+ track('sign in to comment')
+ return await firebaseLogin()
+ }
+ await createCommentOnPost(post.id, editor.getJSON(), user, parentCommentId)
+ props.onSubmitComment?.()
+ }
+
+ return (
+
+ )
+}
+
export function PostComment(props: {
post: Post
comment: PostComment
@@ -84,7 +108,7 @@ export function PostComment(props: {
probAtCreatedTime?: number
onReplyClick?: (comment: PostComment) => void
}) {
- const { post, comment, tips, indent, probAtCreatedTime, onReplyClick } = props
+ const { post, comment, tips, indent, onReplyClick } = props
const { text, content, userUsername, userName, userAvatarUrl, createdTime } =
comment
@@ -147,70 +171,3 @@ export function PostComment(props: {
)
}
-
-export function CommentInput(props: {
- post: Post
- commentsByCurrentUser: PostComment[]
- className?: string
- replyToUser?: { id: string; username: string }
- // Reply to a free response answer
- parentAnswerOutcome?: string
- // Reply to another comment
- parentCommentId?: string
- onSubmitComment?: () => void
-}) {
- const {
- post,
- className,
- parentAnswerOutcome,
- parentCommentId,
- replyToUser,
- onSubmitComment,
- } = props
- const user = useUser()
- const { editor, upload } = useTextEditor({
- simple: true,
- max: MAX_COMMENT_LENGTH,
- placeholder:
- !!parentCommentId || !!parentAnswerOutcome
- ? 'Write a reply...'
- : 'Write a comment...',
- })
- const [isSubmitting, setIsSubmitting] = useState(false)
-
- async function submitComment(betId: string | undefined) {
- if (!user) {
- track('sign in to comment')
- return await firebaseLogin()
- }
- if (!editor || editor.isEmpty || isSubmitting) return
- setIsSubmitting(true)
- await createCommentOnPost(post.id, editor.getJSON(), user, parentCommentId)
- onSubmitComment?.()
- setIsSubmitting(false)
- }
-
- if (user?.isBannedFromPosting) return <>>
-
- return (
-
-
-
-
- )
-}