canEdit-fix
This commit is contained in:
parent
2cbc799219
commit
98264cfce7
|
@ -38,12 +38,14 @@ export const Comment = (props: Props) => {
|
||||||
const [loading, setLoading] = createSignal(false)
|
const [loading, setLoading] = createSignal(false)
|
||||||
const [editMode, setEditMode] = createSignal(false)
|
const [editMode, setEditMode] = createSignal(false)
|
||||||
const [clearEditor, setClearEditor] = createSignal(false)
|
const [clearEditor, setClearEditor] = createSignal(false)
|
||||||
const { author } = useSession()
|
const { author, session } = useSession()
|
||||||
const { createReaction, deleteReaction, updateReaction } = useReactions()
|
const { createReaction, deleteReaction, updateReaction } = useReactions()
|
||||||
const { showConfirm } = useConfirm()
|
const { showConfirm } = useConfirm()
|
||||||
const { showSnackbar } = useSnackbar()
|
const { showSnackbar } = useSnackbar()
|
||||||
|
|
||||||
const isCommentAuthor = createMemo(() => props.comment.created_by?.slug === author()?.slug)
|
const canEdit = createMemo(
|
||||||
|
() => props.comment.created_by?.slug === author()?.slug || session()?.user?.roles.includes('editor'),
|
||||||
|
)
|
||||||
const comment = createMemo(() => props.comment)
|
const comment = createMemo(() => props.comment)
|
||||||
const body = createMemo(() => (comment().body || '').trim())
|
const body = createMemo(() => (comment().body || '').trim())
|
||||||
|
|
||||||
|
@ -108,9 +110,7 @@ export const Comment = (props: Props) => {
|
||||||
return (
|
return (
|
||||||
<li
|
<li
|
||||||
id={`comment_${comment().id}`}
|
id={`comment_${comment().id}`}
|
||||||
class={clsx(styles.comment, props.class, {
|
class={clsx(styles.comment, props.class, { [styles.isNew]: comment()?.created_at > props.lastSeen })}
|
||||||
[styles.isNew]: !isCommentAuthor() && comment()?.created_at > props.lastSeen,
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
<Show when={!!body()}>
|
<Show when={!!body()}>
|
||||||
<div class={styles.commentContent}>
|
<div class={styles.commentContent}>
|
||||||
|
@ -189,7 +189,7 @@ export const Comment = (props: Props) => {
|
||||||
{loading() ? t('Loading') : t('Reply')}
|
{loading() ? t('Loading') : t('Reply')}
|
||||||
</button>
|
</button>
|
||||||
</ShowIfAuthenticated>
|
</ShowIfAuthenticated>
|
||||||
<Show when={isCommentAuthor()}>
|
<Show when={canEdit()}>
|
||||||
<button
|
<button
|
||||||
class={clsx(styles.commentControl, styles.commentControlEdit)}
|
class={clsx(styles.commentControl, styles.commentControlEdit)}
|
||||||
onClick={toggleEditMode}
|
onClick={toggleEditMode}
|
||||||
|
|
|
@ -75,10 +75,15 @@ export const FullArticle = (props: Props) => {
|
||||||
const [isReactionsLoaded, setIsReactionsLoaded] = createSignal(false)
|
const [isReactionsLoaded, setIsReactionsLoaded] = createSignal(false)
|
||||||
const [isActionPopupActive, setIsActionPopupActive] = createSignal(false)
|
const [isActionPopupActive, setIsActionPopupActive] = createSignal(false)
|
||||||
const { t, formatDate, lang } = useLocalize()
|
const { t, formatDate, lang } = useLocalize()
|
||||||
const { author, isAuthenticated, requireAuthentication } = useSession()
|
const { author, session, isAuthenticated, requireAuthentication } = useSession()
|
||||||
|
|
||||||
const formattedDate = createMemo(() => formatDate(new Date(props.article.published_at * 1000)))
|
const formattedDate = createMemo(() => formatDate(new Date(props.article.published_at * 1000)))
|
||||||
const canEdit = () => props.article.authors?.some((a) => Boolean(a) && a?.slug === author()?.slug)
|
const canEdit = createMemo(
|
||||||
|
() =>
|
||||||
|
props.article.authors?.some((a) => Boolean(a) && a?.slug === author()?.slug) ||
|
||||||
|
props.article?.created_by.slug === author()?.slug ||
|
||||||
|
session()?.user?.roles.includes('editor'),
|
||||||
|
)
|
||||||
|
|
||||||
const mainTopic = createMemo(() => {
|
const mainTopic = createMemo(() => {
|
||||||
const mainTopicSlug = props.article.topics.length > 0 ? props.article.main_topic : null
|
const mainTopicSlug = props.article.topics.length > 0 ? props.article.main_topic : null
|
||||||
|
|
|
@ -106,7 +106,7 @@ const LAYOUT_ASPECT = {
|
||||||
|
|
||||||
export const ArticleCard = (props: ArticleCardProps) => {
|
export const ArticleCard = (props: ArticleCardProps) => {
|
||||||
const { t, lang, formatDate } = useLocalize()
|
const { t, lang, formatDate } = useLocalize()
|
||||||
const { author } = useSession()
|
const { author, session } = useSession()
|
||||||
const { changeSearchParams } = useRouter()
|
const { changeSearchParams } = useRouter()
|
||||||
const [isActionPopupActive, setIsActionPopupActive] = createSignal(false)
|
const [isActionPopupActive, setIsActionPopupActive] = createSignal(false)
|
||||||
const [isCoverImageLoadError, setIsCoverImageLoadError] = createSignal(false)
|
const [isCoverImageLoadError, setIsCoverImageLoadError] = createSignal(false)
|
||||||
|
@ -120,9 +120,12 @@ export const ArticleCard = (props: ArticleCardProps) => {
|
||||||
props.article.published_at ? formatDate(new Date(props.article.published_at * 1000)) : '',
|
props.article.published_at ? formatDate(new Date(props.article.published_at * 1000)) : '',
|
||||||
)
|
)
|
||||||
|
|
||||||
const canEdit = () =>
|
const canEdit = createMemo(
|
||||||
|
() =>
|
||||||
props.article.authors?.some((a) => a && a?.slug === author()?.slug) ||
|
props.article.authors?.some((a) => a && a?.slug === author()?.slug) ||
|
||||||
props.article.created_by?.id === author()?.id
|
props.article.created_by?.id === author()?.id ||
|
||||||
|
session()?.user?.roles.includes('editor'),
|
||||||
|
)
|
||||||
|
|
||||||
const scrollToComments = (event) => {
|
const scrollToComments = (event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user