Skip to content

Commit

Permalink
Pretty URL copying, always include version, latest
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvicenti committed Dec 6, 2024
1 parent 7f4550f commit 636ba1b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: (
Expand Down
6 changes: 5 additions & 1 deletion frontend/apps/desktop/src/components/copy-reference-url.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -43,6 +46,7 @@ export function useCopyReferenceUrl(hostname: string) {
hostname,
path: input.path,
latest: input.latest,
siteHomeId,
})
copyTextToClipboard(url)
if (pushOnCopy.data === 'never') {
Expand Down
18 changes: 14 additions & 4 deletions frontend/apps/desktop/src/components/titlebar-common.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
},
},
{
Expand Down Expand Up @@ -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)
},
})
}
Expand Down

0 comments on commit 636ba1b

Please sign in to comment.