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 <tukon479@gmail.com>
This commit is contained in:
Innei 2025-06-06 17:35:16 +08:00
parent c00a7bc778
commit a4ad4bf661
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 12 additions and 6 deletions

View File

@ -1,11 +1,11 @@
import { IN_ELECTRON } from "@follow/shared/constants"
import { env } from "@follow/shared/env.desktop"
import { cn } from "@follow/utils/utils"
import { useCallback } from "react"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
import { ipcServices } from "~/lib/client"
import { UrlBuilder } from "~/lib/url-builder"
import { getEntry } from "~/store/entry"
interface SharePanelProps {
@ -65,6 +65,10 @@ const socialOptions: SocialShareOption[] = [
},
]
const getShareUrl = (entryId: string) => {
return UrlBuilder.shareEntry(entryId)
}
export const SharePanel = ({ entryId }: SharePanelProps) => {
const { t } = useTranslation()
@ -73,8 +77,7 @@ export const SharePanel = ({ entryId }: SharePanelProps) => {
if (!entry) return null
const { title, description } = entry.entries
const url = new URL(globalThis.location.href, env.VITE_WEB_URL)
const shareUrl = url.toString()
const shareUrl = getShareUrl(entryId)
// Limit text to 50 characters with ellipsis
const truncateText = (text: string, maxLength = 50) => {
@ -129,15 +132,14 @@ export const SharePanel = ({ entryId }: SharePanelProps) => {
}, [entryId, generateShareContent, t])
const handleCopyLink = useCallback(async () => {
const url = new URL(globalThis.location.href, env.VITE_WEB_URL)
const shareUrl = url.toString()
const shareUrl = getShareUrl(entryId)
try {
await navigator.clipboard.writeText(shareUrl)
toast.success(t("share.link_copied"))
} catch {
toast.error(t("share.copy_failed"))
}
}, [t])
}, [entryId, t])
const handleSocialShare = useCallback(
(shareUrlTemplate: string) => {

View File

@ -17,6 +17,10 @@ export class UrlBuilder {
return this.join(`share/lists/${id}`, view ? { view: view.toString() } : undefined)
}
shareEntry(id: string) {
return this.join(`timeline/view-0/all/${id}`, { share: "1" })
}
profile(id: string) {
return this.join(`share/users/${id}`)
}