2024-03-15 14:55:37 +00:00
|
|
|
import { clsx } from "clsx";
|
|
|
|
import styles from "./BadgeDubscribeButton.module.scss";
|
2024-03-15 12:58:22 +00:00
|
|
|
import { CheckButton } from "../CheckButton";
|
2024-03-15 14:55:37 +00:00
|
|
|
import { createMemo, Show } from "solid-js";
|
2024-03-15 12:58:22 +00:00
|
|
|
import { Button } from "../Button";
|
|
|
|
import { Icon } from "../Icon";
|
|
|
|
import stylesButton from "../Button/Button.module.scss";
|
|
|
|
import { useLocalize } from "../../../context/localize";
|
2024-03-15 14:55:37 +00:00
|
|
|
import { useFollowing } from "../../../context/following";
|
2024-03-15 12:58:22 +00:00
|
|
|
|
|
|
|
type Props = {
|
2024-03-15 14:55:37 +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:55:37 +00:00
|
|
|
const { t } = useLocalize();
|
|
|
|
|
|
|
|
const inActionText = createMemo(() => {
|
|
|
|
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:55:37 +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:55:37 +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}
|
|
|
|
fallback={props.actionMessageType ? inActionText() : t("Subscribe")}
|
|
|
|
>
|
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:55:37 +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()
|
|
|
|
) : (
|
|
|
|
<>
|
|
|
|
<span class={styles.actionButtonLabel}>{t("Following")}</span>
|
|
|
|
<span class={styles.actionButtonLabelHovered}>{t("Unfollow")}</span>
|
|
|
|
</>
|
|
|
|
)
|
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:55:37 +00:00
|
|
|
);
|
|
|
|
};
|