Hotfix/can edit fix (#421)

Fix canEdit() in Commetns
This commit is contained in:
Ilya Y 2024-02-27 14:41:49 +03:00 committed by GitHub
parent 0d1aaebfa5
commit 8b066104e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 25 deletions

View File

@ -46,14 +46,13 @@ export const Comment = (props: Props) => {
const canEdit = createMemo( const canEdit = createMemo(
() => () =>
Boolean(author()?.id) && Boolean(author()?.id) &&
(props.comment?.created_by?.id === author().id || session()?.user?.roles.includes('editor')), (props.comment?.created_by?.slug === author().slug || session()?.user?.roles.includes('editor')),
) )
const comment = createMemo(() => props.comment) const body = createMemo(() => (props.comment.body || '').trim())
const body = createMemo(() => (comment().body || '').trim())
const remove = async () => { const remove = async () => {
if (comment()?.id) { if (props.comment?.id) {
try { try {
const isConfirmed = await showConfirm({ const isConfirmed = await showConfirm({
confirmBody: t('Are you sure you want to delete this comment?'), confirmBody: t('Are you sure you want to delete this comment?'),
@ -63,7 +62,7 @@ export const Comment = (props: Props) => {
}) })
if (isConfirmed) { if (isConfirmed) {
await deleteReaction(comment().id) await deleteReaction(props.comment.id)
await showSnackbar({ body: t('Comment successfully deleted') }) await showSnackbar({ body: t('Comment successfully deleted') })
} }
@ -113,8 +112,10 @@ export const Comment = (props: Props) => {
return ( return (
<li <li
id={`comment_${comment().id}`} id={`comment_${props.comment.id}`}
class={clsx(styles.comment, props.class, { [styles.isNew]: comment()?.created_at > props.lastSeen })} class={clsx(styles.comment, props.class, {
[styles.isNew]: props.comment?.created_at > props.lastSeen,
})}
> >
<Show when={!!body()}> <Show when={!!body()}>
<div class={styles.commentContent}> <div class={styles.commentContent}>
@ -123,21 +124,21 @@ export const Comment = (props: Props) => {
fallback={ fallback={
<div> <div>
<Userpic <Userpic
name={comment().created_by.name} name={props.comment.created_by.name}
userpic={comment().created_by.pic} userpic={props.comment.created_by.pic}
class={clsx({ class={clsx({
[styles.compactUserpic]: props.compact, [styles.compactUserpic]: props.compact,
})} })}
/> />
<small> <small>
<a href={`#comment_${comment()?.id}`}>{comment()?.shout.title || ''}</a> <a href={`#comment_${props.comment?.id}`}>{props.comment?.shout.title || ''}</a>
</small> </small>
</div> </div>
} }
> >
<div class={styles.commentDetails}> <div class={styles.commentDetails}>
<div class={styles.commentAuthor}> <div class={styles.commentAuthor}>
<AuthorLink author={comment()?.created_by as Author} /> <AuthorLink author={props.comment?.created_by as Author} />
</div> </div>
<Show when={props.isArticleAuthor}> <Show when={props.isArticleAuthor}>
@ -148,23 +149,23 @@ export const Comment = (props: Props) => {
<div class={styles.articleLink}> <div class={styles.articleLink}>
<Icon name="arrow-right" class={styles.articleLinkIcon} /> <Icon name="arrow-right" class={styles.articleLinkIcon} />
<a <a
href={`${getPagePath(router, 'article', { slug: comment().shout.slug })}?commentId=${ href={`${getPagePath(router, 'article', {
comment().id slug: props.comment.shout.slug,
}`} })}?commentId=${props.comment.id}`}
> >
{comment().shout.title} {props.comment.shout.title}
</a> </a>
</div> </div>
</Show> </Show>
<CommentDate showOnHover={true} comment={comment()} isShort={true} /> <CommentDate showOnHover={true} comment={props.comment} isShort={true} />
<CommentRatingControl comment={comment()} /> <CommentRatingControl comment={props.comment} />
</div> </div>
</Show> </Show>
<div class={styles.commentBody}> <div class={styles.commentBody}>
<Show when={editMode()} fallback={<div innerHTML={body()} />}> <Show when={editMode()} fallback={<div innerHTML={body()} />}>
<Suspense fallback={<p>{t('Loading')}</p>}> <Suspense fallback={<p>{t('Loading')}</p>}>
<SimplifiedEditor <SimplifiedEditor
initialContent={comment().body} initialContent={props.comment.body}
submitButtonText={t('Save')} submitButtonText={t('Save')}
quoteEnabled={true} quoteEnabled={true}
imageEnabled={true} imageEnabled={true}

View File

@ -3,12 +3,12 @@ import { For, Show, createEffect, createSignal, on, onMount } from 'solid-js'
import { useFollowing } from '../../context/following' import { useFollowing } from '../../context/following'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
import { apiClient } from '../../graphql/client/core' import { apiClient } from '../../graphql/client/core'
import { Author } from '../../graphql/schema/core.gen'
import { setAuthorsByFollowers, setAuthorsByShouts, useAuthorsStore } from '../../stores/zine/authors' import { setAuthorsByFollowers, setAuthorsByShouts, useAuthorsStore } from '../../stores/zine/authors'
import { AuthorBadge } from '../Author/AuthorBadge' import { AuthorBadge } from '../Author/AuthorBadge'
import { InlineLoader } from '../InlineLoader' import { InlineLoader } from '../InlineLoader'
import { Button } from '../_shared/Button' import { Button } from '../_shared/Button'
import styles from './AuthorsList.module.scss' import styles from './AuthorsList.module.scss'
import { Author } from "../../graphql/schema/core.gen";
type Props = { type Props = {
class?: string class?: string
@ -21,8 +21,9 @@ const PAGE_SIZE = 20
// TODO: проверить нет ли дубликатов в базе данных, если нет - то не использовать addUniqueAuthors() // TODO: проверить нет ли дубликатов в базе данных, если нет - то не использовать addUniqueAuthors()
const addUniqueAuthors = (prevAuthors: Author[], newAuthors: Author[]) => { const addUniqueAuthors = (prevAuthors: Author[], newAuthors: Author[]) => {
const uniqueNewAuthors = newAuthors.filter(newAuthor => const uniqueNewAuthors = newAuthors.filter(
!prevAuthors.some(prevAuthor => prevAuthor.id === newAuthor.id)); (newAuthor) => !prevAuthors.some((prevAuthor) => prevAuthor.id === newAuthor.id),
)
return [...prevAuthors, ...uniqueNewAuthors] return [...prevAuthors, ...uniqueNewAuthors]
} }
export const AuthorsList = (props: Props) => { export const AuthorsList = (props: Props) => {
@ -43,9 +44,9 @@ export const AuthorsList = (props: Props) => {
}) })
if (queryType === 'shouts') { if (queryType === 'shouts') {
setAuthorsByShouts(prev => addUniqueAuthors(prev, result)); setAuthorsByShouts((prev) => addUniqueAuthors(prev, result))
} else { } else {
setAuthorsByFollowers(prev => addUniqueAuthors(prev, result)); setAuthorsByFollowers((prev) => addUniqueAuthors(prev, result))
} }
setLoading(false) setLoading(false)
} }
@ -106,7 +107,7 @@ export const AuthorsList = (props: Props) => {
<Show when={!loading() && authorsList().length > 0 && !allLoaded()}> <Show when={!loading() && authorsList().length > 0 && !allLoaded()}>
<Button value={t('Load more')} onClick={loadMoreAuthors} /> <Button value={t('Load more')} onClick={loadMoreAuthors} />
</Show> </Show>
<Show when={loading() && !allLoaded()}> <Show when={loading() && !allLoaded()}>
<InlineLoader /> <InlineLoader />
</Show> </Show>
</div> </div>

View File

@ -48,7 +48,9 @@ export const MODALS: Record<ModalType, ModalType> = {
const [modal, setModal] = createSignal<ModalType>(null) const [modal, setModal] = createSignal<ModalType>(null)
const { changeSearchParams, clearSearchParams } = useRouter<AuthModalSearchParams & ConfirmEmailSearchParams & RootSearchParams>() const { changeSearchParams, clearSearchParams } = useRouter<
AuthModalSearchParams & ConfirmEmailSearchParams & RootSearchParams
>()
export const showModal = (modalType: ModalType, modalSource?: AuthModalSource) => { export const showModal = (modalType: ModalType, modalSource?: AuthModalSource) => {
if (modalSource) { if (modalSource) {