diff --git a/frontend/apps/desktop/src/components/copy-reference-button.tsx b/frontend/apps/desktop/src/components/copy-reference-button.tsx index 5dacf555..cf3ba10d 100644 --- a/frontend/apps/desktop/src/components/copy-reference-button.tsx +++ b/frontend/apps/desktop/src/components/copy-reference-button.tsx @@ -34,11 +34,13 @@ export function useDocumentUrl({ } | null { const docEntity = useEntity(docId) if (!docId?.uid) return null - const accountEntity = useEntity(hmId('d', docId?.uid!)) + const accountId = hmId('d', docId.uid) + const accountEntity = useEntity(accountId) const gwUrl = useGatewayUrl().data || DEFAULT_GATEWAY_URL const siteHostname = accountEntity.data?.document?.metadata?.siteUrl const [copyDialogContent, onCopyReference] = useCopyReferenceUrl( siteHostname || gwUrl, + siteHostname ? accountId : undefined, ) if (!docId) return null const url = siteHostname @@ -57,7 +59,7 @@ export function useDocumentUrl({ return { url, label: siteHostname - ? 'Site' + ? 'Site' + (latest ? ' Latest' : ' Exact Version') : 'Public' + (latest ? ' Latest' : ' Exact Version'), content: copyDialogContent, onCopy: ( diff --git a/frontend/apps/desktop/src/components/copy-reference-url.tsx b/frontend/apps/desktop/src/components/copy-reference-url.tsx index f211a029..776bcc95 100644 --- a/frontend/apps/desktop/src/components/copy-reference-url.tsx +++ b/frontend/apps/desktop/src/components/copy-reference-url.tsx @@ -31,7 +31,10 @@ import {DialogTitle, useAppDialog} from './dialog' type IsPublishedState = null | boolean // null: determined checked yet -export function useCopyReferenceUrl(hostname: string) { +export function useCopyReferenceUrl( + hostname: string, + siteHomeId?: UnpackedHypermediaId | undefined, +) { const dialog = useAppDialog(PushToGatewayDialog) const pushOnCopy = usePushOnCopy() const publishToSite = usePublishToSite() @@ -43,6 +46,7 @@ export function useCopyReferenceUrl(hostname: string) { hostname, path: input.path, latest: input.latest, + siteHomeId, }) copyTextToClipboard(url) if (pushOnCopy.data === 'never') { diff --git a/frontend/apps/desktop/src/components/titlebar-common.tsx b/frontend/apps/desktop/src/components/titlebar-common.tsx index 262269ab..4bb36ace 100644 --- a/frontend/apps/desktop/src/components/titlebar-common.tsx +++ b/frontend/apps/desktop/src/components/titlebar-common.tsx @@ -73,10 +73,20 @@ export function DocOptionsButton() { const doc = useEntity(route.id) const rootEntity = useEntity(hmId('d', route.id.uid)) const siteUrl = rootEntity.data?.document?.metadata.siteUrl + const copyLatest = + route.id.latest || + !route.id.version || + doc.data?.document?.version === route.id.version const [copyGatewayContent, onCopyGateway] = useCopyReferenceUrl(gwUrl) const [copySiteUrlContent, onCopySiteUrl] = useCopyReferenceUrl( siteUrl || gwUrl, + siteUrl ? hmId('d', route.id.uid) : undefined, ) + const copyUrlId = { + ...route.id, + latest: copyLatest, + version: doc.data?.document?.version || null, + } const removeSite = useRemoveSiteDialog() const publishSite = usePublishSite() const capability = useMyCapability(route.id) @@ -85,10 +95,10 @@ export function DocOptionsButton() { const menuItems: MenuItemType[] = [ { key: 'link', - label: `Copy ${displayHostname(gwUrl)} URL`, + label: `Copy ${displayHostname(gwUrl)} Link`, icon: Link, onPress: () => { - onCopyGateway(route.id) + onCopyGateway(copyUrlId) }, }, { @@ -139,10 +149,10 @@ export function DocOptionsButton() { if (siteUrl) { menuItems.unshift({ key: 'link-site', - label: `Copy ${displayHostname(siteUrl)} URL`, + label: `Copy ${displayHostname(siteUrl)} Link`, icon: Link, onPress: () => { - onCopySiteUrl(route.id) + onCopySiteUrl(copyUrlId) }, }) }