Skip to content

Commit

Permalink
refactor: remove PostInfoProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed May 29, 2024
1 parent c5f5c4a commit f08a029
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { memo } from 'react'
import { type PostInfo, PostInfoProvider } from '@masknet/plugin-infra/content-script'
import { type PostInfo, PostInfoContext } from '@masknet/plugin-infra/content-script'
import { MutationObserverWatcher } from '@dimensiondev/holoflows-kit'
import { makeStyles } from '@masknet/theme'
import { ValueRef } from '@masknet/shared-base'
Expand Down Expand Up @@ -36,9 +36,9 @@ export function injectPostCommentsDefault<T extends string>(
const needZipF = needZip || (() => undefined)
const root = attachReactTreeWithContainer(meta.afterShadow, { signal })
root.render(
<PostInfoProvider post={current}>
<PostInfoContext value={current}>
<PostCommentDefault needZip={needZipF} comment={commentRef} />
</PostInfoProvider>,
</PostInfoContext>,
)
return {
onNodeMutation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { noop } from 'lodash-es'
import { PostInfoProvider, type PostInfo } from '@masknet/plugin-infra/content-script'
import { PostInfoContext, type PostInfo } from '@masknet/plugin-infra/content-script'
import { PostActions } from '../../../components/InjectedComponents/PostActions.js'
import { attachReactTreeWithContainer } from '../../../utils/shadow-root/renderInShadowRoot.js'

Expand All @@ -17,9 +17,9 @@ export function createPostActionsInjector() {
return function injectPostActions(postInfo: PostInfo, signal: AbortSignal) {
if (postInfo.actionsElement) {
const jsx = (
<PostInfoProvider post={postInfo}>
<PostInfoContext value={postInfo}>
<PostActions />
</PostInfoProvider>
</PostInfoContext>
)
const root = attachReactTreeWithContainer(postInfo.actionsElement.afterShadow, {
tag: createRootElement,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memo } from 'react'
import type { DOMProxy } from '@dimensiondev/holoflows-kit'
import { type PostInfo, PostInfoProvider } from '@masknet/plugin-infra/content-script'
import { type PostInfo, PostInfoContext } from '@masknet/plugin-infra/content-script'
import { attachReactTreeWithContainer } from '../../../utils/shadow-root/renderInShadowRoot.js'
import { PostInspector, type PostInspectorProps } from '../../../components/InjectedComponents/PostInspector.js'
import { noop } from 'lodash-es'
Expand All @@ -18,9 +18,9 @@ export function injectPostInspectorDefault(

return function injectPostInspector(current: PostInfo, signal: AbortSignal) {
const jsx = (
<PostInfoProvider post={current}>
<PostInfoContext value={current}>
<PostInspectorDefault {...props} zipPost={() => zipPostF(current.rootElement)} />
</PostInfoProvider>
</PostInfoContext>
)
const root = attachReactTreeWithContainer(injectionPoint?.(current) ?? current.rootElement.afterShadow, {
key: 'post-inspector',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { memo } from 'react'
import type { DOMProxy } from '@dimensiondev/holoflows-kit'
import { PostInfoProvider, type PostInfo } from '@masknet/plugin-infra/content-script'
import { PostInfoContext, type PostInfo } from '@masknet/plugin-infra/content-script'
import { attachReactTreeWithContainer } from '../../../utils/shadow-root/renderInShadowRoot.js'
import { PostReplacer, type PostReplacerProps } from '../../../components/InjectedComponents/PostReplacer.js'

Expand All @@ -25,13 +25,13 @@ export function injectPostReplacer({ zipPost, unzipPost }: InjectPostReplacerCon
untilVisible: true,
signal,
}).render(
<PostInfoProvider post={current}>
<PostInfoContext value={current}>
<PostReplacerDefault
zipPost={() => zipPost(current.rootElement)}
unZipPost={() => unzipPost(current.rootElement)}
{...current}
/>
</PostInfoProvider>,
</PostInfoContext>,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Plugin } from '@masknet/plugin-infra'
import {
createInjectHooksRenderer,
type PostInfo,
PostInfoProvider,
PostInfoContext,
useActivatedPluginsSiteAdaptor,
usePostInfoDetails,
} from '@masknet/plugin-infra/content-script'
Expand Down Expand Up @@ -50,9 +50,9 @@ function createPostActionsInjector() {
return function injectPostActions(postInfo: PostInfo, signal: AbortSignal) {
const jsx = (
<EVMWeb3ContextProvider>
<PostInfoProvider post={postInfo}>
<PostInfoContext value={postInfo}>
<PostActions />
</PostInfoProvider>
</PostInfoContext>
</EVMWeb3ContextProvider>
)
if (postInfo.actionsElement) {
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-infra/src/entry-content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export {
type PostContextActions,
type PostInfo,
PostInfoContext,
PostInfoProvider,
usePostInfoDetails,
type CompositionType,
CompositionContext,
Expand Down
4 changes: 0 additions & 4 deletions packages/plugin-infra/src/site-adaptor/PostContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ export type PostInfo = PostContext
export const PostInfoContext = createContext<PostContext | null>(null)
PostInfoContext.displayName = 'PostInfoContext'

/** @deprecated use <PostInfoContext.Provider value={post}> */
export function PostInfoProvider(props: React.PropsWithChildren<{ post: PostInfo }>) {
return <PostInfoContext value={props.post}>{props.children}</PostInfoContext>
}
export const usePostInfoDetails: {
// Change to use* when https://github.com/microsoft/TypeScript/issues/44643 fixed
[key in keyof PostInfo]: () => PostInfo[key] extends ValueRef<infer T> ? T
Expand Down

0 comments on commit f08a029

Please sign in to comment.