feat(post tools): add functional share button

This commit is contained in:
plebeius.eth
2023-12-03 21:42:19 +01:00
parent a48962e706
commit ea1a201493
4 changed files with 49 additions and 8 deletions

View File

@@ -102,7 +102,14 @@ const AccountBar = () => {
</Link>
</span>
<span className={styles.separator}>|</span>
<Link to='/settings' className={styles.iconButton} onClick={(e) => {e.preventDefault(); setIsMailUnread(!isMailUnread)}}>
<Link
to='/settings'
className={styles.iconButton}
onClick={(e) => {
e.preventDefault();
setIsMailUnread(!isMailUnread);
}}
>
<span className={`${styles.mailIcon} ${mailClass}`} />
{isMailUnread && <span className={styles.mailUnreadCount}>1</span>}
</Link>

View File

@@ -84,4 +84,13 @@
.menuItem button {
text-transform: capitalize;
}
.text {
font-weight: normal !important;
color: var(--text) !important;
}
.text:hover {
text-decoration: none !important;
}

View File

@@ -7,6 +7,7 @@ import styles from './post-tools.module.css';
import { FailedLabel, PendingLabel, SpoilerLabel } from '../label';
import challengesStore from '../../../hooks/use-challenges';
import { alertChallengeVerificationFailed } from '../../../lib/utils/challenge-utils';
import { getShareLink } from '../../../lib/utils/url-utils';
const { addChallenge } = challengesStore.getState();
interface PostToolsProps {
@@ -16,7 +17,7 @@ interface PostToolsProps {
isReply?: boolean;
replyCount?: number;
spoiler?: boolean;
subplebbitAddress?: string;
subplebbitAddress: string;
showReplyForm?: () => void;
}
@@ -119,14 +120,28 @@ const ThreadTools = ({ cid, hasLabel, subplebbitAddress, replyCount = 0 }: PostT
const { t } = useTranslation();
const validReplyCount = isNaN(replyCount) ? 0 : replyCount;
const commentCount = validReplyCount === 0 ? t('post_no_comments') : `${validReplyCount} ${validReplyCount === 1 ? t('post_comment') : t('post_comments')}`;
const [hasShared, setHasShared] = useState(false);
useEffect(() => {
if (hasShared) {
setTimeout(() => setHasShared(false), 2000);
}
}, [hasShared]);
return (
<>
<li className={`${styles.button} ${!hasLabel ? styles.firstButton : ''}`}>
<Link to={`/p/${subplebbitAddress}/c/${cid}`}>{commentCount}</Link>
</li>
<li className={styles.button}>
<span>{t('post_share')}</span>
<li className={`${!hasShared ? styles.button : styles.text}`}>
<span
onClick={() => {
setHasShared(true);
getShareLink(subplebbitAddress, cid);
}}
>
{hasShared ? 'link copied' : t('post_share')}
</span>
</li>
<li className={styles.button}>
<span>{t('post_save')}</span>
@@ -185,13 +200,13 @@ const PostTools = ({ cid, failed, hasLabel = false, isReply, replyCount, spoiler
return (
<ul className={`${styles.buttons} ${isReply ? styles.buttonsReply : ''} ${hasLabel ? styles.buttonsLabel : ''}`}>
{hasLabel && <PostToolsLabel cid={cid} failed={failed} isReply={isReply} spoiler={spoiler} />}
{hasLabel && <PostToolsLabel cid={cid} failed={failed} isReply={isReply} spoiler={spoiler} subplebbitAddress={subplebbitAddress} />}
{isReply ? (
<ReplyTools cid={cid} hasLabel={hasLabel} showReplyForm={showReplyForm} />
<ReplyTools cid={cid} hasLabel={hasLabel} showReplyForm={showReplyForm} subplebbitAddress={subplebbitAddress} />
) : (
<ThreadTools cid={cid} hasLabel={hasLabel} subplebbitAddress={subplebbitAddress} replyCount={replyCount} />
)}
{isMod && <ModTools cid={cid} />}
{isMod && <ModTools cid={cid} subplebbitAddress={subplebbitAddress} />}
</ul>
);
};

View File

@@ -13,4 +13,14 @@ export const isValidURL = (url: string) => {
} catch {
return false;
}
};
};
export const getShareLink = (subplebbitAddress: string, cid: string) => {
const shareLink = `https://pleb.bz/p/${subplebbitAddress}/c/${cid}?redirect=seedit.eth.limo`;
if (navigator.clipboard) {
navigator.clipboard.writeText(shareLink);
} else {
alert('Your browser does not support clipboard API');
}
}