Hide edit option for non authors in feed (#161)

This commit is contained in:
Ilya Y 2023-08-11 17:12:16 +03:00 committed by GitHub
parent 133b49b183
commit c95907968c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 45 deletions

View File

@ -16,6 +16,7 @@ import { router, useRouter } from '../../stores/router'
import { imageProxy } from '../../utils/imageProxy'
import { Popover } from '../_shared/Popover'
import { AuthorCard } from '../Author/AuthorCard'
import { useSession } from '../../context/session'
interface ArticleCardProps {
settings?: {
@ -66,7 +67,7 @@ const getTitleAndSubtitle = (article: Shout): { title: string; subtitle: string
export const ArticleCard = (props: ArticleCardProps) => {
const { t, lang } = useLocalize()
const { user } = useSession()
const mainTopic =
props.article.topics.find((articleTopic) => articleTopic.slug === props.article.mainTopic) ||
props.article.topics[0]
@ -79,6 +80,8 @@ export const ArticleCard = (props: ArticleCardProps) => {
const { id, cover, layout, slug, authors, stat, body } = props.article
const canEdit = () => authors?.some((a) => a.slug === user()?.slug)
const { changeSearchParam } = useRouter()
const scrollToComments = (event) => {
event.preventDefault()
@ -238,19 +241,21 @@ export const ArticleCard = (props: ArticleCardProps) => {
</div>
<div class={styles.shoutCardDetailsContent}>
<Popover content={t('Edit')}>
{(triggerRef: (el) => void) => (
<div class={styles.shoutCardDetailsItem} ref={triggerRef}>
<a href={getPagePath(router, 'edit', { shoutId: id.toString() })}>
<Icon name="pencil-outline" class={clsx(styles.icon, styles.feedControlIcon)} />
<Icon
name="pencil-outline-hover"
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
/>
</a>
</div>
)}
</Popover>
<Show when={canEdit()}>
<Popover content={t('Edit')}>
{(triggerRef: (el) => void) => (
<div class={styles.shoutCardDetailsItem} ref={triggerRef}>
<a href={getPagePath(router, 'edit', { shoutId: id.toString() })}>
<Icon name="pencil-outline" class={clsx(styles.icon, styles.feedControlIcon)} />
<Icon
name="pencil-outline-hover"
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
/>
</a>
</div>
)}
</Popover>
</Show>
<Popover content={t('Add to bookmarks')}>
{(triggerRef: (el) => void) => (
@ -292,6 +297,7 @@ export const ArticleCard = (props: ArticleCardProps) => {
<div class={styles.shoutCardDetailsItem}>
<FeedArticlePopup
isOwner={canEdit()}
containerCssClass={stylesHeader.control}
title={title}
description={getDescription(body)}

View File

@ -2,12 +2,13 @@ import styles from './FeedArticlePopup.module.scss'
import type { PopupProps } from '../_shared/Popup'
import { Popup } from '../_shared/Popup'
import { useLocalize } from '../../context/localize'
import { createEffect, createSignal } from 'solid-js'
import { createEffect, createSignal, Show } from 'solid-js'
type FeedArticlePopupProps = {
title: string
shareUrl?: string
imageUrl: string
isOwner: boolean
description: string
isVisible?: (value: boolean) => void
} & Omit<PopupProps, 'children'>
@ -39,16 +40,18 @@ export const FeedArticlePopup = (props: FeedArticlePopupProps) => {
{t('Share')}
</button>
</li>
<li>
<button
role="button"
onClick={() => {
alert('Help to edit')
}}
>
{t('Help to edit')}
</button>
</li>
<Show when={!props.isOwner}>
<li>
<button
role="button"
onClick={() => {
alert('Help to edit')
}}
>
{t('Help to edit')}
</button>
</li>
</Show>
<li>
<button
role="button"
@ -59,16 +62,18 @@ export const FeedArticlePopup = (props: FeedArticlePopupProps) => {
{t('Invite experts')}
</button>
</li>
<li>
<button
role="button"
onClick={() => {
alert('Subscribe to comments')
}}
>
{t('Subscribe to comments')}
</button>
</li>
<Show when={!props.isOwner}>
<li>
<button
role="button"
onClick={() => {
alert('Subscribe to comments')
}}
>
{t('Subscribe to comments')}
</button>
</li>
</Show>
<li>
<button
role="button"
@ -79,16 +84,18 @@ export const FeedArticlePopup = (props: FeedArticlePopupProps) => {
{t('Add to bookmarks')}
</button>
</li>
<li>
<button
role="button"
onClick={() => {
alert('Report')
}}
>
{t('Report')}
</button>
</li>
<Show when={!props.isOwner}>
<li>
<button
role="button"
onClick={() => {
alert('Report')
}}
>
{t('Report')}
</button>
</li>
</Show>
<li>
<button
role="button"