2022-11-26 21:27:54 +00:00
|
|
|
|
import styles from './Comment.module.scss'
|
2022-11-14 17:41:05 +00:00
|
|
|
|
import { Icon } from '../_shared/Icon'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
import { AuthorCard } from '../Author/Card'
|
2022-11-26 21:27:54 +00:00
|
|
|
|
import { Show, createMemo, createSignal } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
import { clsx } from 'clsx'
|
|
|
|
|
import type { Author, Reaction as Point } from '../../graphql/types.gen'
|
|
|
|
|
import { t } from '../../utils/intl'
|
|
|
|
|
// import { createReaction, updateReaction, deleteReaction } from '../../stores/zine/reactions'
|
2022-10-07 11:02:34 +00:00
|
|
|
|
import MD from './MD'
|
2022-09-13 09:59:04 +00:00
|
|
|
|
import { deleteReaction } from '../../stores/zine/reactions'
|
2022-11-26 21:27:54 +00:00
|
|
|
|
import { formatDate } from '../../utils'
|
|
|
|
|
import { SharePopup } from './SharePopup'
|
|
|
|
|
import stylesHeader from '../Nav/Header.module.scss'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
export default (props: {
|
|
|
|
|
level?: number
|
|
|
|
|
comment: Partial<Point>
|
|
|
|
|
canEdit?: boolean
|
|
|
|
|
compact?: boolean
|
|
|
|
|
}) => {
|
2022-11-26 21:27:54 +00:00
|
|
|
|
const [isSharePopupVisible, setIsSharePopupVisible] = createSignal(false)
|
|
|
|
|
const [isReplyVisible, setIsReplyVisible] = createSignal(false)
|
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
|
const comment = createMemo(() => props.comment)
|
2022-11-26 01:46:34 +00:00
|
|
|
|
const body = createMemo(() => (comment().body || '').trim())
|
2022-09-09 11:53:35 +00:00
|
|
|
|
const remove = () => {
|
|
|
|
|
if (comment()?.id) {
|
|
|
|
|
console.log('[comment] removing', comment().id)
|
2022-09-13 09:59:04 +00:00
|
|
|
|
deleteReaction(comment().id)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-26 21:27:54 +00:00
|
|
|
|
const formattedDate = createMemo(() =>
|
|
|
|
|
formatDate(new Date(comment()?.createdAt), { hour: 'numeric', minute: 'numeric' })
|
|
|
|
|
)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
return (
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={clsx(styles.comment, { [styles[`commentLevel${props.level}`]]: Boolean(props.level) })}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<Show when={!!body()}>
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={styles.commentContent}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<Show
|
|
|
|
|
when={!props.compact}
|
|
|
|
|
fallback={
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={styles.commentDetails}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<a href={`/author/${comment()?.createdBy?.slug}`}>
|
|
|
|
|
@{(comment()?.createdBy || { name: 'anonymous' }).name}
|
|
|
|
|
</a>
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={styles.commentArticle}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<Icon name="reply-arrow" />
|
|
|
|
|
<a href={`#comment-${comment()?.id}`}>
|
|
|
|
|
#{(comment()?.shout || { title: 'Lorem ipsum titled' }).title}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
}
|
|
|
|
|
>
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={styles.commentDetails}>
|
|
|
|
|
<div class={styles.commentAuthor}>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
<AuthorCard
|
|
|
|
|
author={comment()?.createdBy as Author}
|
|
|
|
|
hideDescription={true}
|
|
|
|
|
hideFollow={true}
|
2022-11-26 21:27:54 +00:00
|
|
|
|
isComments={true}
|
|
|
|
|
hasLink={true}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={styles.commentDate}>{formattedDate()}</div>
|
|
|
|
|
<div
|
|
|
|
|
class={styles.commentRating}
|
|
|
|
|
classList={{
|
|
|
|
|
[styles.commentRatingPositive]: comment().stat?.rating > 0,
|
|
|
|
|
[styles.commentRatingNegative]: comment().stat?.rating < 0
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<button class={clsx(styles.commentRatingControl, styles.commentRatingControlUp)}></button>
|
|
|
|
|
<div class={styles.commentRatingValue}>{comment().stat?.rating || 0}</div>
|
|
|
|
|
<button class={clsx(styles.commentRatingControl, styles.commentRatingControlDown)}></button>
|
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div
|
|
|
|
|
class={styles.commentBody}
|
|
|
|
|
contenteditable={props.canEdit}
|
|
|
|
|
id={'comment-' + (comment().id || '')}
|
|
|
|
|
>
|
2022-10-07 11:02:34 +00:00
|
|
|
|
<MD body={body()} />
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<Show when={!props.compact}>
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<div class={styles.commentControls}>
|
|
|
|
|
<button
|
|
|
|
|
class={clsx(styles.commentControl, styles.commentControlReply)}
|
|
|
|
|
onClick={() => setIsReplyVisible(!isReplyVisible())}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="reply" class={styles.icon} />
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{t('Reply')}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
<Show when={props.canEdit}>
|
2022-09-13 09:59:04 +00:00
|
|
|
|
{/*FIXME implement edit comment modal*/}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{/*<button*/}
|
2022-11-26 21:27:54 +00:00
|
|
|
|
{/* class={clsx(styles.commentControl, styles.commentControlEdit)}*/}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{/* onClick={() => showModal('editComment')}*/}
|
|
|
|
|
{/*>*/}
|
2022-11-26 21:27:54 +00:00
|
|
|
|
{/* <Icon name="edit" class={styles.icon} />*/}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{/* {t('Edit')}*/}
|
|
|
|
|
{/*</button>*/}
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<button
|
|
|
|
|
class={clsx(styles.commentControl, styles.commentControlDelete)}
|
|
|
|
|
onClick={() => remove()}
|
|
|
|
|
>
|
|
|
|
|
<Icon name="delete" class={styles.icon} />
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{t('Delete')}
|
|
|
|
|
</button>
|
|
|
|
|
</Show>
|
|
|
|
|
|
2022-11-26 21:27:54 +00:00
|
|
|
|
<SharePopup
|
|
|
|
|
onVisibilityChange={(isVisible) => {
|
|
|
|
|
setIsSharePopupVisible(isVisible)
|
|
|
|
|
}}
|
|
|
|
|
containerCssClass={stylesHeader.control}
|
|
|
|
|
trigger={
|
|
|
|
|
<button class={clsx(styles.commentControl, styles.commentControlShare)}>
|
|
|
|
|
<Icon name="share" class={styles.icon} />
|
|
|
|
|
{t('Share')}
|
|
|
|
|
</button>
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{/*<button*/}
|
2022-11-26 21:27:54 +00:00
|
|
|
|
{/* class={clsx(styles.commentControl, styles.commentControlComplain)}*/}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
{/* onClick={() => showModal('reportComment')}*/}
|
|
|
|
|
{/*>*/}
|
|
|
|
|
{/* {t('Report')}*/}
|
|
|
|
|
{/*</button>*/}
|
|
|
|
|
</div>
|
2022-11-26 21:27:54 +00:00
|
|
|
|
|
|
|
|
|
<Show when={isReplyVisible()}>
|
|
|
|
|
<form class={styles.replyForm}>
|
|
|
|
|
<textarea name="reply" id="reply" rows="5"></textarea>
|
|
|
|
|
<div class={styles.replyFormControls}>
|
|
|
|
|
<button class="button button--light" onClick={() => setIsReplyVisible(false)}>
|
|
|
|
|
Отмена
|
|
|
|
|
</button>
|
|
|
|
|
<button class="button">Отправить</button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</Show>
|
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|