feat: expose present user profile modal for electron

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-09-25 22:04:13 +08:00
parent e20bbbc07c
commit 2290760cbb
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
4 changed files with 13 additions and 10 deletions

View File

@ -6,8 +6,6 @@ import duration from "dayjs/plugin/duration"
import localizedFormat from "dayjs/plugin/localizedFormat"
import relativeTime from "dayjs/plugin/relativeTime"
import { enableMapSet } from "immer"
import React from "react"
import ReactDOM from "react-dom"
import { isElectronBuild } from "~/constants"
import { browserDB } from "~/database"
@ -99,10 +97,6 @@ export const initializeApp = async () => {
data_hydrated_time: dataHydratedTime,
version: APP_VERSION,
})
// expose `React` `ReactDOM` to global, it's easier for developers to make plugins
window.React = React
window.ReactDOM = ReactDOM
}
import.meta.hot?.dispose(cleanup)

View File

@ -42,18 +42,19 @@ export const useUserSubscriptionsQuery = (userId: string | undefined) => {
return subscriptions
}
export const usePresentUserProfileModal = (variant: "drawer" | "dialog" = "dialog") => {
type Variant = "drawer" | "dialog"
export const usePresentUserProfileModal = (variant: Variant = "dialog") => {
const { present } = useModalStack()
return useCallback(
(userId: string | undefined) => {
(userId: string | undefined, overrideVariant?: Variant) => {
if (!userId) return
present({
title: "User Profile",
content: () =>
createElement(UserProfileModalContent, {
userId,
variant,
variant: overrideVariant || variant,
}),
CustomModalComponent: PlainModal,
clickOutsideToDismiss: true,

View File

@ -8,6 +8,7 @@ import { getGeneralSettings } from "~/atoms/settings/general"
import { getUISettings } from "~/atoms/settings/ui"
import { useModalStack } from "~/components/ui/modal"
import { FeedForm } from "~/modules/discover/feed-form"
import { usePresentUserProfileModal } from "~/modules/profile/hooks"
import { ElectronCloseEvent, ElectronShowEvent } from "./invalidate-query-provider"
@ -39,6 +40,8 @@ export const ExtensionExposeProvider = () => {
}, [])
const { t } = useTranslation()
const presentUserProfile = usePresentUserProfileModal("dialog")
useEffect(() => {
registerGlobalContext({
follow(id, options) {
@ -51,7 +54,11 @@ export const ExtensionExposeProvider = () => {
),
})
},
profile(id, variant) {
presentUserProfile(id, variant)
},
})
}, [present, t])
}, [present, presentUserProfile, t])
return null
}

View File

@ -22,6 +22,7 @@ interface RenderGlobalContext {
/// Actions
follow: (id: string, options?: { isList: boolean }) => void
profile: (id: string, variant?: "drawer" | "dialog") => void
/// Utils
toast: typeof toast