fix article card actions (#364)

* fix invite modal

* change FeedArticlePopup hide logic

* resolve conversation
This commit is contained in:
Ilya Y 2024-01-15 16:22:43 +03:00 committed by GitHub
parent 96166d79ad
commit ef7a24d571
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 11 deletions

View File

@ -52,6 +52,7 @@ export type ArticleCardProps = {
desktopCoverSize?: 'XS' | 'S' | 'M' | 'L' desktopCoverSize?: 'XS' | 'S' | 'M' | 'L'
article: Shout article: Shout
onShare?: (article: Shout) => void onShare?: (article: Shout) => void
onInvite?: () => void
} }
const desktopCoverImageWidths: Record<ArticleCardProps['desktopCoverSize'], number> = { const desktopCoverImageWidths: Record<ArticleCardProps['desktopCoverSize'], number> = {
@ -368,7 +369,7 @@ export const ArticleCard = (props: ArticleCardProps) => {
isOwner={canEdit()} isOwner={canEdit()}
containerCssClass={stylesHeader.control} containerCssClass={stylesHeader.control}
onShareClick={() => props.onShare(props.article)} onShareClick={() => props.onShare(props.article)}
onInviteClick={() => showModal('inviteCoAuthors')} onInviteClick={props.onInvite}
onVisibilityChange={(isVisible) => setIsActionPopupActive(isVisible)} onVisibilityChange={(isVisible) => setIsActionPopupActive(isVisible)}
trigger={ trigger={
<button> <button>
@ -385,7 +386,6 @@ export const ArticleCard = (props: ArticleCardProps) => {
</section> </section>
</Show> </Show>
</div> </div>
<InviteCoAuthorsModal title={t('Invite experts')} />
</section> </section>
) )
} }

View File

@ -1,7 +1,7 @@
import type { PopupProps } from '../../_shared/Popup' import type { PopupProps } from '../../_shared/Popup'
import { clsx } from 'clsx' import { clsx } from 'clsx'
import { Show } from 'solid-js' import { createSignal, Show } from 'solid-js'
import { useLocalize } from '../../../context/localize' import { useLocalize } from '../../../context/localize'
import { Popup } from '../../_shared/Popup' import { Popup } from '../../_shared/Popup'
@ -9,20 +9,34 @@ import { SoonChip } from '../../_shared/SoonChip'
import styles from './FeedArticlePopup.module.scss' import styles from './FeedArticlePopup.module.scss'
type FeedArticlePopupProps = { type Props = {
isOwner: boolean isOwner: boolean
onInviteClick: () => void onInviteClick: () => void
onShareClick: () => void onShareClick: () => void
} & Omit<PopupProps, 'children'> } & Omit<PopupProps, 'children'>
export const FeedArticlePopup = (props: FeedArticlePopupProps) => { export const FeedArticlePopup = (props: Props) => {
const { t } = useLocalize() const { t } = useLocalize()
const [isHidden, setHidden] = createSignal(false)
return ( return (
<> <>
<Popup {...props} horizontalAnchor={'right'} variant="tiny" popupCssClass={styles.feedArticlePopup}> <Popup
{...props}
closePopup={() => isHidden()}
horizontalAnchor={'right'}
variant="tiny"
popupCssClass={styles.feedArticlePopup}
>
<ul class={clsx('nodash', styles.actionList)}> <ul class={clsx('nodash', styles.actionList)}>
<li> <li>
<button class={styles.action} role="button" onClick={props.onShareClick}> <button
class={styles.action}
role="button"
onClick={() => {
props.onShareClick()
setHidden(true)
}}
>
{t('Share')} {t('Share')}
</button> </button>
</li> </li>
@ -33,6 +47,7 @@ export const FeedArticlePopup = (props: FeedArticlePopupProps) => {
role="button" role="button"
onClick={() => { onClick={() => {
alert('Help to edit') alert('Help to edit')
setHidden(true)
}} }}
> >
{t('Help to edit')} {t('Help to edit')}
@ -40,7 +55,14 @@ export const FeedArticlePopup = (props: FeedArticlePopupProps) => {
</li> </li>
</Show> </Show>
<li> <li>
<button class={styles.action} role="button" onClick={props.onInviteClick}> <button
class={styles.action}
role="button"
onClick={() => {
props.onInviteClick()
setHidden(true)
}}
>
{t('Invite experts')} {t('Invite experts')}
</button> </button>
</li> </li>

View File

@ -17,6 +17,7 @@ import { getImageUrl } from '../../../utils/getImageUrl'
import { getServerDate } from '../../../utils/getServerDate' import { getServerDate } from '../../../utils/getServerDate'
import { DropDown } from '../../_shared/DropDown' import { DropDown } from '../../_shared/DropDown'
import { Icon } from '../../_shared/Icon' import { Icon } from '../../_shared/Icon'
import { InviteCoAuthorsModal } from '../../_shared/InviteCoAuthorsModal'
import { Loading } from '../../_shared/Loading' import { Loading } from '../../_shared/Loading'
import { ShareModal } from '../../_shared/ShareModal' import { ShareModal } from '../../_shared/ShareModal'
import { CommentDate } from '../../Article/CommentDate' import { CommentDate } from '../../Article/CommentDate'
@ -290,6 +291,7 @@ export const Feed = (props: Props) => {
{(article) => ( {(article) => (
<ArticleCard <ArticleCard
onShare={(shared) => handleShare(shared)} onShare={(shared) => handleShare(shared)}
onInvite={() => showModal('inviteCoAuthors')}
article={article} article={article}
settings={{ isFeedMode: true }} settings={{ isFeedMode: true }}
desktopCoverSize="M" desktopCoverSize="M"
@ -416,6 +418,7 @@ export const Feed = (props: Props) => {
shareUrl={getShareUrl({ pathname: `/${shareData().slug}` })} shareUrl={getShareUrl({ pathname: `/${shareData().slug}` })}
/> />
</Show> </Show>
<InviteCoAuthorsModal title={t('Invite experts')} />
</div> </div>
) )
} }

View File

@ -15,6 +15,7 @@ export type PopupProps = {
onVisibilityChange?: (isVisible: boolean) => void onVisibilityChange?: (isVisible: boolean) => void
horizontalAnchor?: HorizontalAnchor horizontalAnchor?: HorizontalAnchor
variant?: 'bordered' | 'tiny' variant?: 'bordered' | 'tiny'
closePopup?: (isVisible: boolean) => void
} }
export const Popup = (props: PopupProps) => { export const Popup = (props: PopupProps) => {
@ -29,13 +30,19 @@ export const Popup = (props: PopupProps) => {
const containerRef: { current: HTMLElement } = { current: null } const containerRef: { current: HTMLElement } = { current: null }
const closePopup = () => {
setIsVisible(false)
if (props.closePopup) {
props.closePopup
}
}
useOutsideClickHandler({ useOutsideClickHandler({
containerRef, containerRef,
predicate: () => isVisible(), predicate: () => isVisible(),
handler: () => { handler: () => closePopup(),
setIsVisible(false)
},
}) })
const toggle = () => setIsVisible((oldVisible) => !oldVisible) const toggle = () => setIsVisible((oldVisible) => !oldVisible)
return ( return (
<span class={clsx(styles.container, props.containerCssClass)} ref={(el) => (containerRef.current = el)}> <span class={clsx(styles.container, props.containerCssClass)} ref={(el) => (containerRef.current = el)}>