Feature/comments fixies (#261)

Comments fix pack
This commit is contained in:
Ilya Y 2023-10-16 10:40:34 +03:00 committed by GitHub
parent 6de5590223
commit 99642e71ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 16 deletions

View File

@ -31,6 +31,8 @@ type Props = {
lastSeen?: Date lastSeen?: Date
class?: string class?: string
showArticleLink?: boolean showArticleLink?: boolean
clickedReply?: (id: number) => void
clickedReplyId?: number
} }
export const Comment = (props: Props) => { export const Comment = (props: Props) => {
@ -178,12 +180,11 @@ export const Comment = (props: Props) => {
<SimplifiedEditor <SimplifiedEditor
initialContent={comment().body} initialContent={comment().body}
submitButtonText={t('Save')} submitButtonText={t('Save')}
submitByEnter={true}
quoteEnabled={true} quoteEnabled={true}
imageEnabled={true} imageEnabled={true}
placeholder={t('Write a comment...')} placeholder={t('Write a comment...')}
onSubmit={(value) => handleUpdate(value)} onSubmit={(value) => handleUpdate(value)}
submitByShiftEnter={true} submitByCtrlEnter={true}
setClear={clearEditor()} setClear={clearEditor()}
/> />
</Suspense> </Suspense>
@ -195,7 +196,10 @@ export const Comment = (props: Props) => {
<ShowIfAuthenticated> <ShowIfAuthenticated>
<button <button
disabled={loading()} disabled={loading()}
onClick={() => setIsReplyVisible(!isReplyVisible())} onClick={() => {
setIsReplyVisible(!isReplyVisible())
props.clickedReply(props.comment.id)
}}
class={clsx(styles.commentControl, styles.commentControlReply)} class={clsx(styles.commentControl, styles.commentControlReply)}
> >
<Icon name="reply" class={styles.icon} /> <Icon name="reply" class={styles.icon} />
@ -239,14 +243,14 @@ export const Comment = (props: Props) => {
{/*</button>*/} {/*</button>*/}
</div> </div>
<Show when={isReplyVisible()}> <Show when={isReplyVisible() && props.clickedReplyId === props.comment.id}>
<Suspense fallback={<p>{t('Loading')}</p>}> <Suspense fallback={<p>{t('Loading')}</p>}>
<SimplifiedEditor <SimplifiedEditor
quoteEnabled={true} quoteEnabled={true}
imageEnabled={true} imageEnabled={true}
placeholder={t('Write a comment...')} placeholder={t('Write a comment...')}
onSubmit={(value) => handleCreate(value)} onSubmit={(value) => handleCreate(value)}
submitByShiftEnter={true} submitByCtrlEnter={true}
/> />
</Suspense> </Suspense>
</Show> </Show>
@ -262,6 +266,8 @@ export const Comment = (props: Props) => {
isArticleAuthor={props.isArticleAuthor} isArticleAuthor={props.isArticleAuthor}
comment={c} comment={c}
lastSeen={props.lastSeen} lastSeen={props.lastSeen}
clickedReply={props.clickedReply}
clickedReplyId={props.clickedReplyId}
/> />
)} )}
</For> </For>

View File

@ -1,4 +1,4 @@
import { Show, createMemo, createSignal, onMount, For } from 'solid-js' import { Show, createMemo, createSignal, onMount, For, createEffect } from 'solid-js'
import { Comment } from './Comment' import { Comment } from './Comment'
import styles from './Article.module.scss' import styles from './Article.module.scss'
import { clsx } from 'clsx' import { clsx } from 'clsx'
@ -43,6 +43,9 @@ export const CommentsTree = (props: Props) => {
const { t } = useLocalize() const { t } = useLocalize()
const [commentsOrder, setCommentsOrder] = createSignal<CommentsOrder>('createdAt') const [commentsOrder, setCommentsOrder] = createSignal<CommentsOrder>('createdAt')
const [newReactions, setNewReactions] = createSignal<Reaction[]>([]) const [newReactions, setNewReactions] = createSignal<Reaction[]>([])
const [clearEditor, setClearEditor] = createSignal(false)
const [clickedReplyId, setClickedReplyId] = createSignal<number>()
const { const {
reactionEntities, reactionEntities,
actions: { createReaction } actions: { createReaction }
@ -88,7 +91,6 @@ export const CommentsTree = (props: Props) => {
setCookie() setCookie()
} }
}) })
const handleSubmitComment = async (value) => { const handleSubmitComment = async (value) => {
try { try {
await createReaction({ await createReaction({
@ -96,9 +98,11 @@ export const CommentsTree = (props: Props) => {
body: value, body: value,
shout: props.shoutId shout: props.shoutId
}) })
setClearEditor(true)
} catch (error) { } catch (error) {
console.error('[handleCreate reaction]:', error) console.error('[handleCreate reaction]:', error)
} }
setClearEditor(false)
} }
return ( return (
@ -153,6 +157,8 @@ export const CommentsTree = (props: Props) => {
props.articleAuthors.some((a) => a.slug === reaction.createdBy.slug) props.articleAuthors.some((a) => a.slug === reaction.createdBy.slug)
)} )}
comment={reaction} comment={reaction}
clickedReply={(id) => setClickedReplyId(id)}
clickedReplyId={clickedReplyId()}
lastSeen={dateFromLocalStorage} lastSeen={dateFromLocalStorage}
/> />
)} )}
@ -175,9 +181,11 @@ export const CommentsTree = (props: Props) => {
<SimplifiedEditor <SimplifiedEditor
quoteEnabled={true} quoteEnabled={true}
imageEnabled={true} imageEnabled={true}
autoFocus={true}
submitByCtrlEnter={true}
placeholder={t('Write a comment...')} placeholder={t('Write a comment...')}
onSubmit={(value) => handleSubmitComment(value)} onSubmit={(value) => handleSubmitComment(value)}
submitByShiftEnter={true} setClear={clearEditor()}
/> />
</ShowIfAuthenticated> </ShowIfAuthenticated>
</> </>

View File

@ -50,10 +50,10 @@ type Props = {
imageEnabled?: boolean imageEnabled?: boolean
setClear?: boolean setClear?: boolean
smallHeight?: boolean smallHeight?: boolean
submitByEnter?: boolean submitByCtrlEnter?: boolean
submitByShiftEnter?: boolean
onlyBubbleControls?: boolean onlyBubbleControls?: boolean
controlsAlwaysVisible?: boolean controlsAlwaysVisible?: boolean
autoFocus?: boolean
} }
export const MAX_DESCRIPTION_LIMIT = 400 export const MAX_DESCRIPTION_LIMIT = 400
@ -133,6 +133,7 @@ const SimplifiedEditor = (props: Props) => {
placeholder: props.placeholder placeholder: props.placeholder
}) })
], ],
autofocus: props.autoFocus,
content: content ?? null content: content ?? null
})) }))
@ -200,10 +201,7 @@ const SimplifiedEditor = (props: Props) => {
return return
} }
if ( if (event.code === 'Enter' && props.submitByCtrlEnter && (event.metaKey || event.ctrlKey)) {
event.code === 'Enter' &&
((props.submitByEnter && !event.shiftKey) || (props.submitByShiftEnter && event.shiftKey))
) {
event.preventDefault() event.preventDefault()
props.onSubmit(html()) props.onSubmit(html())
handleClear() handleClear()

View File

@ -39,7 +39,6 @@ export const Modal = (props: Props) => {
useEscKeyDownHandler(handleHide) useEscKeyDownHandler(handleHide)
createEffect(() => { createEffect(() => {
console.log('!!! modal:', modal())
setVisible(modal() === props.name) setVisible(modal() === props.name)
}) })

View File

@ -269,7 +269,7 @@ export const InboxView = () => {
placeholder={t('Write message')} placeholder={t('Write message')}
setClear={isClear()} setClear={isClear()}
onSubmit={(message) => handleSubmit(message)} onSubmit={(message) => handleSubmit(message)}
submitByEnter={true} submitByCtrlEnter={true}
/> />
</div> </div>
</div> </div>