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:
@@ -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) => {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user