2024-03-15 14:57:03 +00:00
|
|
|
import { clsx } from 'clsx'
|
|
|
|
import { Show, createMemo } from 'solid-js'
|
|
|
|
import { useLocalize } from '../../../context/localize'
|
|
|
|
import { Button } from '../Button'
|
|
|
|
import stylesButton from '../Button/Button.module.scss'
|
|
|
|
import { CheckButton } from '../CheckButton'
|
|
|
|
import { Icon } from '../Icon'
|
|
|
|
import styles from './BadgeDubscribeButton.module.scss'
|
2024-03-15 12:58:22 +00:00
|
|
|
|
|
|
|
type Props = {
|
2024-03-15 14:57:03 +00:00
|
|
|
class?: string
|
|
|
|
isSubscribed: boolean
|
|
|
|
minimizeSubscribeButton?: boolean
|
|
|
|
action: () => void
|
|
|
|
iconButtons?: boolean
|
|
|
|
actionMessageType?: 'subscribe' | 'unsubscribe'
|
|
|
|
}
|
2024-03-15 12:58:22 +00:00
|
|
|
|
|
|
|
export const BadgeSubscribeButton = (props: Props) => {
|
2024-03-15 14:57:03 +00:00
|
|
|
const { t } = useLocalize()
|
2024-03-15 14:55:37 +00:00
|
|
|
|
|
|
|
const inActionText = createMemo(() => {
|
2024-03-15 14:57:03 +00:00
|
|
|
return props.actionMessageType === 'subscribe' ? t('Subscribing...') : t('Unsubscribing...')
|
|
|
|
})
|
2024-03-15 12:58:22 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div class={props.class}>
|
|
|
|
<Show
|
|
|
|
when={!props.minimizeSubscribeButton}
|
2024-03-15 14:57:03 +00:00
|
|
|
fallback={<CheckButton text={t('Follow')} checked={props.isSubscribed} onClick={props.action} />}
|
2024-03-15 12:58:22 +00:00
|
|
|
>
|
|
|
|
<Show
|
|
|
|
when={props.isSubscribed}
|
|
|
|
fallback={
|
|
|
|
<Button
|
2024-03-15 14:57:03 +00:00
|
|
|
variant={props.iconButtons ? 'secondary' : 'bordered'}
|
2024-03-15 12:58:22 +00:00
|
|
|
size="S"
|
|
|
|
value={
|
2024-03-15 14:55:37 +00:00
|
|
|
<Show
|
|
|
|
when={props.iconButtons}
|
2024-03-15 14:57:03 +00:00
|
|
|
fallback={props.actionMessageType ? inActionText() : t('Subscribe')}
|
2024-03-15 14:55:37 +00:00
|
|
|
>
|
2024-03-15 12:58:22 +00:00
|
|
|
<Icon name="author-subscribe" class={stylesButton.icon} />
|
|
|
|
</Show>
|
|
|
|
}
|
|
|
|
onClick={props.action}
|
|
|
|
isSubscribeButton={true}
|
|
|
|
class={clsx(styles.actionButton, {
|
|
|
|
[styles.iconed]: props.iconButtons,
|
|
|
|
[stylesButton.subscribed]: props.isSubscribed,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<Button
|
2024-03-15 14:57:03 +00:00
|
|
|
variant={props.iconButtons ? 'secondary' : 'bordered'}
|
2024-03-15 12:58:22 +00:00
|
|
|
size="S"
|
|
|
|
value={
|
|
|
|
<Show
|
|
|
|
when={props.iconButtons}
|
|
|
|
fallback={
|
2024-03-15 14:55:37 +00:00
|
|
|
props.actionMessageType ? (
|
|
|
|
inActionText()
|
|
|
|
) : (
|
|
|
|
<>
|
2024-03-15 14:57:03 +00:00
|
|
|
<span class={styles.actionButtonLabel}>{t('Following')}</span>
|
|
|
|
<span class={styles.actionButtonLabelHovered}>{t('Unfollow')}</span>
|
2024-03-15 14:55:37 +00:00
|
|
|
</>
|
|
|
|
)
|
2024-03-15 12:58:22 +00:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<Icon name="author-unsubscribe" class={stylesButton.icon} />
|
|
|
|
</Show>
|
|
|
|
}
|
|
|
|
onClick={props.action}
|
|
|
|
isSubscribeButton={true}
|
|
|
|
class={clsx(styles.actionButton, {
|
|
|
|
[styles.iconed]: props.iconButtons,
|
|
|
|
[stylesButton.subscribed]: props.isSubscribed,
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
</Show>
|
|
|
|
</Show>
|
|
|
|
</div>
|
2024-03-15 14:57:03 +00:00
|
|
|
)
|
|
|
|
}
|