webapp/src/components/_shared/FollowingButton/FollowingButton.tsx

88 lines
2.7 KiB
TypeScript
Raw Normal View History

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 { CheckButton } from '../CheckButton'
import { Icon } from '../Icon'
2024-05-20 11:16:54 +00:00
import stylesButton from '../Button/Button.module.scss'
import styles from './FollowingButton.module.scss'
2024-03-15 12:58:22 +00:00
type Props = {
2024-03-15 14:57:03 +00:00
class?: string
2024-05-20 11:16:54 +00:00
isFollowed: boolean
minimize?: boolean
2024-03-15 14:57:03 +00:00
action: () => void
iconButtons?: boolean
2024-05-20 11:16:54 +00:00
actionMessageType?: 'follow' | 'unfollow'
2024-03-15 14:57:03 +00:00
}
2024-03-15 12:58:22 +00:00
2024-05-20 11:16:54 +00:00
export const FollowingButton = (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-05-20 11:16:54 +00:00
return props.actionMessageType === 'follow' ? t('Following...') : t('Unfollowing...')
2024-03-15 14:57:03 +00:00
})
2024-03-15 12:58:22 +00:00
return (
<div class={props.class}>
<Show
2024-05-20 11:16:54 +00:00
when={!props.minimize}
fallback={<CheckButton text={t('Follow')} checked={props.isFollowed} onClick={props.action} />}
2024-03-15 12:58:22 +00:00
>
<Show
2024-05-20 11:16:54 +00:00
when={props.isFollowed}
2024-03-15 12:58:22 +00:00
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-05-20 11:16:54 +00:00
fallback={props.actionMessageType ? inActionText() : t('Follow')}
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,
2024-05-20 11:16:54 +00:00
[stylesButton.followed]: props.isFollowed,
2024-03-15 12:58:22 +00:00
})}
/>
}
>
<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,
2024-05-20 11:16:54 +00:00
[stylesButton.followed]: props.isFollowed,
2024-03-15 12:58:22 +00:00
})}
/>
</Show>
</Show>
</div>
2024-03-15 14:57:03 +00:00
)
}