From 41ffd2f65b7561ebdd6f1663fde0c5ecf97d1121 Mon Sep 17 00:00:00 2001 From: plebeius Date: Sun, 30 Nov 2025 22:43:48 +0100 Subject: [PATCH] feat(share-link): add description and rules link types --- .../post-menu-desktop/post-menu-desktop.tsx | 16 ++++++++++----- .../post-menu-mobile/post-menu-mobile.tsx | 20 +++++++++++-------- src/lib/utils/url-utils.ts | 8 ++++++-- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/components/post-desktop/post-menu-desktop/post-menu-desktop.tsx b/src/components/post-desktop/post-menu-desktop/post-menu-desktop.tsx index 73ee6665..d4b0abcc 100644 --- a/src/components/post-desktop/post-menu-desktop/post-menu-desktop.tsx +++ b/src/components/post-desktop/post-menu-desktop/post-menu-desktop.tsx @@ -6,7 +6,9 @@ import { autoUpdate, flip, FloatingFocusManager, offset, shift, useClick, useDis import { Comment, useBlock } from '@plebbit/plebbit-react-hooks'; import styles from './post-menu-desktop.module.css'; import { getCommentMediaInfo } from '../../../lib/utils/media-utils'; -import { copyShareLinkToClipboard, isValidURL } from '../../../lib/utils/url-utils'; +import { copyShareLinkToClipboard, isValidURL, type ShareLinkType } from '../../../lib/utils/url-utils'; +import { getBoardPath } from '../../../lib/utils/route-utils'; +import { useDefaultSubplebbits } from '../../../hooks/use-default-subplebbits'; import { isAllView, isCatalogView, isPostPageView, isSubscriptionsView } from '../../../lib/utils/view-utils'; import useHide from '../../../hooks/use-hide'; import _ from 'lodash'; @@ -19,12 +21,14 @@ interface PostMenuDesktopProps { onClose: () => void; } -const CopyLinkButton = ({ cid, subplebbitAddress, onClose }: PostMenuDesktopProps) => { +const CopyLinkButton = ({ cid, subplebbitAddress, linkType, onClose }: { cid?: string; subplebbitAddress: string; linkType: ShareLinkType; onClose: () => void }) => { const { t } = useTranslation(); + const defaultSubplebbits = useDefaultSubplebbits(); + const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits); return (
{ - copyShareLinkToClipboard(subplebbitAddress, cid); + copyShareLinkToClipboard(boardIdentifier, linkType, cid); onClose(); }} > @@ -118,7 +122,7 @@ const PostMenuDesktop = ({ post }: { post: Comment }) => { const headingId = useId(); const handleMenuClick = () => { - if (cid) { + if (cid || isDescription || isRules) { setMenuBtnRotated((prev) => !prev); } }; @@ -142,7 +146,9 @@ const PostMenuDesktop = ({ post }: { post: Comment }) => { createPortal(
- {cid && subplebbitAddress && } + {cid && subplebbitAddress && } + {!cid && isDescription && subplebbitAddress && } + {!cid && isRules && subplebbitAddress && } {!(isInPostPageView && postCid === cid) && !isDescription && !isRules && (
void; } -const CopyLinkButton = ({ cid, subplebbitAddress, onClose }: PostMenuMobileProps) => { +const CopyLinkButton = ({ cid, subplebbitAddress, linkType, onClose }: { cid?: string; subplebbitAddress: string; linkType: ShareLinkType; onClose: () => void }) => { const { t } = useTranslation(); + const defaultSubplebbits = useDefaultSubplebbits(); + const boardIdentifier = getBoardPath(subplebbitAddress, defaultSubplebbits); return (
{ - if (subplebbitAddress) { - copyShareLinkToClipboard(subplebbitAddress, cid); - } - onClose && onClose(); + copyShareLinkToClipboard(boardIdentifier, linkType, cid); + onClose(); }} >
{t('copy_link')}
@@ -116,7 +118,7 @@ const PostMenuMobile = ({ post }: { post: Comment }) => { const headingId = useId(); const handleMenuClick = () => { - if (cid) { + if (cid || isDescription || isRules) { setIsMenuOpen((prev) => !prev); } }; @@ -137,7 +139,9 @@ const PostMenuMobile = ({ post }: { post: Comment }) => { createPortal(
- {cid && subplebbitAddress && } + {cid && subplebbitAddress && } + {!cid && isDescription && subplebbitAddress && } + {!cid && isRules && subplebbitAddress && } {cid && subplebbitAddress && } {cid && subplebbitAddress && !isDescription && !isRules && } {cid && subplebbitAddress && !isInBoardView && !isDescription && !isRules && } diff --git a/src/lib/utils/url-utils.ts b/src/lib/utils/url-utils.ts index 2443ac45..e0081ad2 100644 --- a/src/lib/utils/url-utils.ts +++ b/src/lib/utils/url-utils.ts @@ -17,8 +17,12 @@ export const isValidURL = (url: string) => { } }; -export const copyShareLinkToClipboard = async (subplebbitAddress: string, cid: string) => { - const shareLink = `https://pleb.bz/p/${subplebbitAddress}/c/${cid}?redirect=5chan.app`; +export type ShareLinkType = 'thread' | 'description' | 'rules'; + +// Copies a share link to clipboard for a board, thread, description, or rules page +export const copyShareLinkToClipboard = async (boardIdentifier: string, linkType: ShareLinkType, cid?: string) => { + const suffix = linkType === 'thread' ? `/thread/${cid}` : `/${linkType}`; + const shareLink = `https://5chan.app/${boardIdentifier}${suffix}`; await copyToClipboard(shareLink); };