Skip to content

Commit a4ad4bf

Browse files
committed
feat(desktop): enhance SharePanel with dedicated share URL generation
- Introduced a new method in UrlBuilder for generating share URLs for entries. - Updated SharePanel to utilize the new share URL method for improved clarity and maintainability. Signed-off-by: Innei <[email protected]>
1 parent c00a7bc commit a4ad4bf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

apps/desktop/layer/renderer/src/components/common/SharePanel.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { IN_ELECTRON } from "@follow/shared/constants"
2-
import { env } from "@follow/shared/env.desktop"
32
import { cn } from "@follow/utils/utils"
43
import { useCallback } from "react"
54
import { useTranslation } from "react-i18next"
65
import { toast } from "sonner"
76

87
import { ipcServices } from "~/lib/client"
8+
import { UrlBuilder } from "~/lib/url-builder"
99
import { getEntry } from "~/store/entry"
1010

1111
interface SharePanelProps {
@@ -65,6 +65,10 @@ const socialOptions: SocialShareOption[] = [
6565
},
6666
]
6767

68+
const getShareUrl = (entryId: string) => {
69+
return UrlBuilder.shareEntry(entryId)
70+
}
71+
6872
export const SharePanel = ({ entryId }: SharePanelProps) => {
6973
const { t } = useTranslation()
7074

@@ -73,8 +77,7 @@ export const SharePanel = ({ entryId }: SharePanelProps) => {
7377
if (!entry) return null
7478

7579
const { title, description } = entry.entries
76-
const url = new URL(globalThis.location.href, env.VITE_WEB_URL)
77-
const shareUrl = url.toString()
80+
const shareUrl = getShareUrl(entryId)
7881

7982
// Limit text to 50 characters with ellipsis
8083
const truncateText = (text: string, maxLength = 50) => {
@@ -129,15 +132,14 @@ export const SharePanel = ({ entryId }: SharePanelProps) => {
129132
}, [entryId, generateShareContent, t])
130133

131134
const handleCopyLink = useCallback(async () => {
132-
const url = new URL(globalThis.location.href, env.VITE_WEB_URL)
133-
const shareUrl = url.toString()
135+
const shareUrl = getShareUrl(entryId)
134136
try {
135137
await navigator.clipboard.writeText(shareUrl)
136138
toast.success(t("share.link_copied"))
137139
} catch {
138140
toast.error(t("share.copy_failed"))
139141
}
140-
}, [t])
142+
}, [entryId, t])
141143

142144
const handleSocialShare = useCallback(
143145
(shareUrlTemplate: string) => {

packages/internal/utils/src/url-builder.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export class UrlBuilder {
1717
return this.join(`share/lists/${id}`, view ? { view: view.toString() } : undefined)
1818
}
1919

20+
shareEntry(id: string) {
21+
return this.join(`timeline/view-0/all/${id}`, { share: "1" })
22+
}
23+
2024
profile(id: string) {
2125
return this.join(`share/users/${id}`)
2226
}

0 commit comments

Comments
 (0)