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

View File

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