Skip to content

Commit

Permalink
fix: dsearch settings (#10866)
Browse files Browse the repository at this point in the history
* refactor: code style

* refactor: code style

* fix: web3 profile should not follow dsearch settings
  • Loading branch information
guanbinrui committed Sep 26, 2023
1 parent c5b6660 commit 17f75b8
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function Content(props: ProfileTabContentProps) {

const [currentTab, onChange] = useTabs(first(tabs)?.id ?? PluginID.Collectible, ...tabs.map((tab) => tab.id))

const isWeb3ProfileDisable = useIsMinimalMode(PluginID.Web3Profile)
const isWeb3ProfileDisabled = useIsMinimalMode(PluginID.Web3Profile)

const isOnTwitter = Sniffings.is_twitter_page
const doesOwnerHaveNoAddress =
Expand All @@ -212,7 +212,7 @@ function Content(props: ProfileTabContentProps) {
const showNextID =
isOnTwitter &&
// enabled the plugin
(isWeb3ProfileDisable ||
(isWeb3ProfileDisabled ||
myPersonaNotVerifiedYet ||
// the owner persona and site verified on next ID but not verify the wallet
doesOwnerHaveNoAddress ||
Expand Down Expand Up @@ -358,7 +358,6 @@ function Content(props: ProfileTabContentProps) {
if (((isOwnerIdentity && loadPersonaStatusError) || loadSocialAccounts) && socialAccounts.length === 0) {
const handleClick = () => {
if (loadPersonaStatusError) retryLoadPersonaStatus()

if (loadSocialAccounts) retrySocialAccounts()
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
getSearchResultContentForProfileTab,
getSearchResultTabContent,
getSearchResultTabs,
useActivatedPlugin,
useActivatedPluginsSiteAdaptor,
useIsMinimalMode,
usePluginI18NField,
} from '@masknet/plugin-infra/content-script'
import { EMPTY_LIST, PluginID, type SocialIdentity, type ProfileTabs } from '@masknet/shared-base'
Expand Down Expand Up @@ -54,9 +54,9 @@ export interface SearchResultInspectorProps {
export function SearchResultInspector(props: SearchResultInspectorProps) {
const translate = usePluginI18NField()

const dSearchEnabled = useActivatedPlugin(PluginID.Handle, false)
const dSearchEnabled = useIsMinimalMode(PluginID.Handle)

const { profileTabType } = props
const { identity, profileTabType, isProfilePage } = props
const keyword_ = useSearchedKeyword()
const keyword = props.keyword || keyword_
const activatedPlugins = useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode()
Expand All @@ -83,7 +83,7 @@ export function SearchResultInspector(props: SearchResultInspectorProps) {

const currentResult = props.currentSearchResult ?? resultList.value?.[0]

const { classes } = useStyles({ isProfilePage: props.isProfilePage, searchType: currentResult?.type })
const { classes } = useStyles({ isProfilePage, searchType: currentResult?.type })
const contentComponent = useMemo(() => {
if (!currentResult || !resultList.value?.length) return null

Expand All @@ -95,11 +95,11 @@ export function SearchResultInspector(props: SearchResultInspectorProps) {
<Component
resultList={resultList.value}
currentResult={currentResult}
isProfilePage={props.isProfilePage}
identity={props.identity}
isProfilePage={isProfilePage}
identity={identity}
/>
)
}, [currentResult, resultList.value, props.isProfilePage, props.identity, profileTabType])
}, [currentResult, resultList.value, isProfilePage, identity, profileTabType])

const tabs = useMemo(() => {
if (!currentResult) return EMPTY_LIST
Expand All @@ -118,7 +118,7 @@ export function SearchResultInspector(props: SearchResultInspectorProps) {
return <Component result={currentResult} />
}, [currentTab, resultList.value])

if (!dSearchEnabled) return null
if (!dSearchEnabled && !isProfilePage) return null
if (!keyword && !currentResult) return null
if (!contentComponent) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ function injectProfileTabContentState(signal: AbortSignal) {
}

export function injectProfileTabContentAtTwitter(signal: AbortSignal) {
const contentLoseConnectionWatcher = new MutationObserverWatcher(
const lostConnectionContentWatcher = new MutationObserverWatcher(
searchProfileTabLoseConnectionPageSelector(),
).useForeach(() => MaskMessages.events.profileTabHidden.sendToLocal({ hidden: true }))

const contentContentWatcher = new MutationObserverWatcher(searchProfileTabPageSelector()).useForeach(() =>
const contentWatcher = new MutationObserverWatcher(searchProfileTabPageSelector()).useForeach(() =>
MaskMessages.events.profileTabHidden.sendToLocal({ hidden: false }),
)

const ContentForEmptyWatcher = new MutationObserverWatcher(searchProfileEmptySelector()).useForeach(() =>
const emptyContentWatcher = new MutationObserverWatcher(searchProfileEmptySelector()).useForeach(() =>
MaskMessages.events.profileTabHidden.sendToLocal({ hidden: false }),
)

startWatch(contentLoseConnectionWatcher, { signal, shadowRootDelegatesFocus: false })
startWatch(contentContentWatcher, { signal, shadowRootDelegatesFocus: false })
startWatch(ContentForEmptyWatcher, { signal, shadowRootDelegatesFocus: false })
startWatch(lostConnectionContentWatcher, { signal, shadowRootDelegatesFocus: false })
startWatch(contentWatcher, { signal, shadowRootDelegatesFocus: false })
startWatch(emptyContentWatcher, { signal, shadowRootDelegatesFocus: false })

injectProfileTabContentForEmptyState(signal)
injectProfileTabContentState(signal)
Expand Down
28 changes: 14 additions & 14 deletions packages/plugins/Handle/src/SiteAdaptor/PluginHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PluginID } from '@masknet/shared-base'
import { Icons } from '@masknet/icons'
import { makeStyles, MaskColorVar } from '@masknet/theme'
import { Box } from '@mui/system'
import { Stack, Typography, useTheme, Link } from '@mui/material'
import { Icons } from '@masknet/icons'
import { PluginID } from '@masknet/shared-base'
import { useSharedI18N } from '@masknet/shared'
import { Box } from '@mui/system'
import { makeStyles, MaskColorVar } from '@masknet/theme'
import { PluginI18NFieldRender } from '@masknet/plugin-infra/content-script'
import { base } from '../base.js'

Expand All @@ -29,9 +29,9 @@ const useStyles = makeStyles()((theme, props) => {
})

export function PluginHeader() {
const t = useSharedI18N()
const theme = useTheme()
const { classes } = useStyles()
const t = useSharedI18N()

return (
<Stack flexDirection="row" justifyContent="space-between" alignItems="center" className={classes.wrapper}>
Expand All @@ -45,16 +45,16 @@ export function PluginHeader() {
<Typography variant="body1" fontSize={14} fontWeight="400" className={classes.providerBy}>
{t.plugin_provider_by()}
</Typography>
<Typography
variant="body1"
fontSize={14}
fontWeight="500"
component="div"
color={MaskColorVar.textPluginColor}>
{base.publisher ? (
{base.publisher ? (
<Typography
variant="body1"
fontSize={14}
fontWeight="500"
component="div"
color={MaskColorVar.textPluginColor}>
<PluginI18NFieldRender pluginID={PluginID.Handle} field={base.publisher.name} />
) : undefined}
</Typography>
</Typography>
) : null}
{base.publisher?.link ? (
<Link href={base.publisher?.link} underline="none" target="_blank" rel="noopener">
<Icons.Provider size={18} style={{ marginLeft: 4 }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { MaskLightTheme, MaskThemeProvider, makeStyles } from '@masknet/theme'
import { ScopedDomainsContainer } from '@masknet/web3-hooks-base'
import { ChainId } from '@masknet/web3-shared-evm'
import { Others } from '@masknet/web3-providers'
import { SuffixToChainIconMap, SuffixToChainIdMap } from '../constants.js'
import { PluginHeader } from './PluginHeader.js'
import { SuffixToChainIconMap, SuffixToChainIdMap } from '../constants.js'
import { ENSContext, ENSProvider, type SearchResultInspectorProps } from './context.js'

const useStyles = makeStyles()((theme) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/Handle/src/SiteAdaptor/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Trans } from 'react-i18next'
import type { Plugin } from '@masknet/plugin-infra'
import { PluginID } from '@masknet/shared-base'
import { Trans } from 'react-i18next'
import type { ChainId } from '@masknet/web3-shared-evm'
import { Icons } from '@masknet/icons'
import { base } from '../base.js'
import { SearchResultInspector } from './SearchResultInspector.js'
import { type EOAResult, SearchResultType } from '@masknet/web3-shared-base'
import { SearchResultInspector } from './SearchResultInspector.js'
import { base } from '../base.js'

const site: Plugin.SiteAdaptor.Definition = {
...base,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/Tips/src/components/NetworkSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function NetworkSection() {
const { setTargetChainId } = TargetRuntimeContext.useContainer()

const { pluginID } = useNetworkContext()
const definition = useActivatedPlugin(PluginID.Tips, 'any')
const chainIdList = definition?.enableRequirement.web3?.[pluginID]?.supportedChainIds ?? EMPTY_LIST
const tipsDefinition = useActivatedPlugin(PluginID.Tips, 'any')
const chainIdList = tipsDefinition?.enableRequirement.web3?.[pluginID]?.supportedChainIds ?? EMPTY_LIST

if (!chainIdList.length) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ export function TrendingViewDeck(props: TrendingViewDeckProps) {
const openRss3Profile = useCallback(
(address: string) => {
if (!isCollectionProjectPopper) {
return CrossIsolationMessages.events.hideSearchResultInspectorEvent.sendToLocal({ hide: true })
CrossIsolationMessages.events.hideSearchResultInspectorEvent.sendToLocal({ hide: true })
return
}

if (!identity?.identifier?.userId || !anchorBounding) return
Expand All @@ -244,7 +245,6 @@ export function TrendingViewDeck(props: TrendingViewDeckProps) {
address,
external: true,
})

setActive?.(false)
},
[JSON.stringify(identity), isCollectionProjectPopper, anchorBounding, anchorEl],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { useAsyncFn } from 'react-use'
import { Icons } from '@masknet/icons'
import type { PluginID } from '@masknet/shared-base'
import { useIsMinimalMode, useSiteAdaptorContext } from '@masknet/plugin-infra/content-script'
import { makeStyles, ActionButton } from '@masknet/theme'
import { Stack, Typography } from '@mui/material'
import { makeStyles, ActionButton } from '@masknet/theme'
import { useSharedI18N } from '../../../locales/index.js'

const useStyles = makeStyles()((theme) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
getSearchResultContentForProfileTab,
getSearchResultTabContent,
getSearchResultTabs,
useActivatedPlugin,
useActivatedPluginsSiteAdaptor,
useIsMinimalMode,
usePluginI18NField,
} from '@masknet/plugin-infra/content-script'
import { EMPTY_LIST, PluginID, type SocialIdentity, type ProfileTabs } from '@masknet/shared-base'
Expand Down Expand Up @@ -54,7 +54,7 @@ export interface SearchResultInspectorProps {
export function SearchResultInspector(props: SearchResultInspectorProps) {
const translate = usePluginI18NField()

const dSearchEnabled = useActivatedPlugin(PluginID.Handle, false)
const dSearchEnabled = useIsMinimalMode(PluginID.Handle)

const { profileTabType, empty = null } = props
const keyword_ = useSearchedKeyword()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ export const ApplicationSettingPluginSwitch = memo(function ApplicationSettingPl

const onSwitch = useCallback(
async (id: string, checked: boolean) => {
if (id === PluginID.GoPlusSecurity && checked === false)
return CrossIsolationMessages.events.checkSecurityConfirmationDialogEvent.sendToAll({ open: true })
await setPluginMinimalModeEnabled?.(id, !checked)
if (id === PluginID.GoPlusSecurity && checked === false) {
CrossIsolationMessages.events.checkSecurityConfirmationDialogEvent.sendToAll({ open: true })
} else {
await setPluginMinimalModeEnabled?.(id, !checked)
}
},
[setPluginMinimalModeEnabled],
)
Expand All @@ -121,7 +123,6 @@ export const ApplicationSettingPluginSwitch = memo(function ApplicationSettingPl
targetPluginRef.current = element
}
}}
focusPluginID={focusPluginID}
/>
{availablePlugins.map((x) => (
<ListItem
Expand Down Expand Up @@ -191,11 +192,10 @@ export const ApplicationSettingPluginSwitch = memo(function ApplicationSettingPl
interface DSearchSettingsProps {
checked: boolean
onSwitch: (event: React.ChangeEvent<HTMLInputElement>) => void
focusPluginID?: string
setRef(element: HTMLLIElement | null): void
}

function DSearchSettings({ checked, onSwitch, setRef, focusPluginID }: DSearchSettingsProps) {
function DSearchSettings({ checked, onSwitch, setRef }: DSearchSettingsProps) {
const t = useSharedI18N()
const { classes } = useStyles()

Expand Down

0 comments on commit 17f75b8

Please sign in to comment.