refactor(desktop): update SharePanel and UrlBuilder for improved share URL handling

- Refactored SharePanel to retrieve the share URL directly from the entry data.
- Enhanced UrlBuilder with a new method for generating share URLs that includes view and subscription parameters.
- Updated the shareEntry method to utilize the new structure for better flexibility.

Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
Innei 2025-06-06 18:43:45 +08:00
parent 56677aaddc
commit 059ab9d996
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
3 changed files with 42 additions and 8 deletions

View File

@ -5,7 +5,6 @@ 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 {
@ -66,7 +65,27 @@ const socialOptions: SocialShareOption[] = [
]
const getShareUrl = (entryId: string) => {
return UrlBuilder.shareEntry(entryId)
const entry = getEntry(entryId)
if (!entry) return ""
// Temporarily use the original link
return entry.entries.url!
// const params = getRouteParams()
// let subscriptionId = "all"
// if (params.feedId) {
// subscriptionId = params.feedId
// } else if (params.inboxId) {
// subscriptionId = params.inboxId
// } else if (params.listId) {
// subscriptionId = params.listId
// }
// return UrlBuilder.shareEntry(entryId, {
// view: params.view,
// subscriptionId,
// })
}
export const SharePanel = ({ entryId }: SharePanelProps) => {

View File

@ -1,5 +1,24 @@
import { FeedViewType } from "@follow/constants"
import { UrlBuilder as UrlBuilderClass } from "@follow/utils/url-builder"
import { WEB_URL } from "~/constants/env"
export const UrlBuilder = new UrlBuilderClass(WEB_URL)
class WebUrlBuilder extends UrlBuilderClass {
constructor() {
super(WEB_URL)
}
shareEntry(
id: string,
options?: {
view?: FeedViewType
subscriptionId?: string
},
) {
const { view = FeedViewType.Articles, subscriptionId = "all" } = options || {}
return super.join(`timeline/view-${view}/${subscriptionId}/${id}`, { share: "1" })
}
}
export const UrlBuilder = new WebUrlBuilder()

View File

@ -1,6 +1,6 @@
export class UrlBuilder {
constructor(private readonly webUrl: string) {}
private join(path: string, query?: Record<string, string>) {
protected join(path: string, query?: Record<string, string>) {
const nextUrl = new URL(this.webUrl)
nextUrl.pathname = path
if (query) {
@ -17,10 +17,6 @@ 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}`)
}