Skip to content

Commit

Permalink
feat: expose present user profile modal for electron
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 25, 2024
1 parent e20bbbc commit 2290760
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
6 changes: 0 additions & 6 deletions apps/renderer/src/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions apps/renderer/src/modules/profile/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion apps/renderer/src/providers/extension-expose-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -39,6 +40,8 @@ export const ExtensionExposeProvider = () => {
}, [])

const { t } = useTranslation()

const presentUserProfile = usePresentUserProfileModal("dialog")
useEffect(() => {
registerGlobalContext({
follow(id, options) {
Expand All @@ -51,7 +54,11 @@ export const ExtensionExposeProvider = () => {
),
})
},

profile(id, variant) {
presentUserProfile(id, variant)
},
})
}, [present, t])
}, [present, presentUserProfile, t])
return null
}
1 change: 1 addition & 0 deletions packages/shared/src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2290760

Please sign in to comment.