Skip to content

Commit

Permalink
feat: mf-6146 merge lens/farcaster badges (#11931)
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask authored Nov 15, 2024
1 parent 8666a82 commit 0016e61
Show file tree
Hide file tree
Showing 37 changed files with 270 additions and 806 deletions.
3 changes: 2 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -236,5 +236,6 @@
],
"ignoreRegExpList": ["/[A-Za-z0-9]{44}/", "/[A-Za-z0-9]{46}/", "/[A-Za-z0-9]{59}/"],
"overrides": [],
"words": []
"words": ["endregion"]
}

4 changes: 1 addition & 3 deletions packages/mask/content-script/site-adaptor-infra/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ export async function activateSiteAdaptorUIInner(ui_deferred: SiteAdaptorUI.Defe
ui.injection.userAvatar?.(signal)
ui.injection.profileAvatar?.(signal)
ui.injection.tips?.(signal)
ui.injection.nameWidget?.(signal)
ui.injection.farcaster?.(signal)
ui.injection.lens?.(signal)
ui.injection.badges?.(signal)

ui.injection.enhancedProfileNFTAvatar?.(signal)
ui.injection.openNFTAvatar?.(signal)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { injectBadgesOnConversation } from './injectBadgesOnConversation.js'
import { injectBadgesOnPost } from './injectBadgesOnPost.js'
import { injectBadgesOnProfile } from './injectBadgesOnProfile.js'
import { injectBadgesOnSpaceDock } from './injectBadgesOnSpaceDock.js'
import { injectBadgesOnUserCell } from './injectBadgesOnUserCell.js'

export function injectBadges(signal: AbortSignal) {
injectBadgesOnProfile(signal)
injectBadgesOnPost(signal)
injectBadgesOnUserCell(signal)
injectBadgesOnConversation(signal)
injectBadgesOnSpaceDock(signal)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ function createRootElement() {
return span
}

const ConversationFarcasterSlot = memo(function ConversationFarcasterSlot({ userId }: Props) {
const ConversationBadgesSlot = memo(function ConversationBadgesSlot({ userId }: Props) {
const [disabled, setDisabled] = useState(true)
const { classes, cx } = useStyles()

const component = useMemo(() => {
const Component = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
(plugin) => plugin.Farcaster?.UI?.Content,
(plugin) => plugin.Badges?.UI?.Content,
undefined,
createRootElement,
)
Expand All @@ -59,7 +59,7 @@ const ConversationFarcasterSlot = memo(function ConversationFarcasterSlot({ user
return (
<Component
identity={identifier}
slot={Plugin.SiteAdaptor.FarcasterSlot.Sidebar}
slot={Plugin.SiteAdaptor.BadgesSlot.Sidebar}
onStatusUpdate={setDisabled}
/>
)
Expand All @@ -73,7 +73,7 @@ const ConversationFarcasterSlot = memo(function ConversationFarcasterSlot({ user
/**
* Inject on conversation, including both DM drawer and message page (/messages/xxx)
*/
export function injectFarcasterOnConversation(signal: AbortSignal) {
export function injectBadgesOnConversation(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(selector())
startWatch(watcher, signal)
watcher.useForeach((node, _, proxy) => {
Expand All @@ -90,7 +90,7 @@ export function injectFarcasterOnConversation(signal: AbortSignal) {
}, '')
if (!userId) return
attachReactTreeWithContainer(proxy.afterShadow, { signal, untilVisible: true }).render(
<ConversationFarcasterSlot userId={userId} />,
<ConversationBadgesSlot userId={userId} />,
)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function selector() {
}

// structure: <user-name> <user-id> <timestamp>
export function injectLensOnPost(signal: AbortSignal) {
export function injectBadgesOnPost(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(selector())
startWatch(watcher, signal)
watcher.useForeach((node, _, proxy) => {
Expand All @@ -26,7 +26,7 @@ export function injectLensOnPost(signal: AbortSignal) {
const userId = href?.split('/')[1]
if (!userId) return
attachReactTreeWithContainer(proxy.afterShadow, { signal, untilVisible: true }).render(
<PostLensSlot userId={userId} />,
<PostBadgesSlot userId={userId} />,
)
})
}
Expand Down Expand Up @@ -58,21 +58,23 @@ function createRootElement() {
})
return span
}
function PostLensSlot({ userId }: Props) {
function PostBadgesSlot({ userId }: Props) {
const [disabled, setDisabled] = useState(true)
const { classes, cx } = useStyles()

const component = useMemo(() => {
const Component = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
(plugin) => plugin.Lens?.UI?.Content,
(plugin) => plugin.Badges?.UI?.Content,
undefined,
createRootElement,
)
const identifier = ProfileIdentifier.of(EnhanceableSite.Twitter, userId).unwrap()
if (!identifier) return null

return <Component identity={identifier} slot={Plugin.SiteAdaptor.LensSlot.Post} onStatusUpdate={setDisabled} />
return (
<Component identity={identifier} slot={Plugin.SiteAdaptor.BadgesSlot.Post} onStatusUpdate={setDisabled} />
)
}, [userId])

if (!component) return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ function selector() {
return querySelector<HTMLElement>('[data-testid=UserName] div[dir]')
}

export function injectLensOnProfile(signal: AbortSignal) {
export function injectBadgesOnProfile(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(selector())
startWatch(watcher, signal)
attachReactTreeWithContainer(watcher.firstDOMProxy.afterShadow, { signal }).render(<ProfileLensSlot />)
attachReactTreeWithContainer(watcher.firstDOMProxy.afterShadow, { signal }).render(<ProfileBadgesSlot />)
}

const useStyles = makeStyles()((theme) => ({
Expand All @@ -32,21 +32,21 @@ const useStyles = makeStyles()((theme) => ({
},
}))

function ProfileLensSlot() {
function ProfileBadgesSlot() {
const visitingIdentity = useCurrentVisitingIdentity()
const [disabled, setDisabled] = useState(true)
const { classes, cx } = useStyles()

const component = useMemo(() => {
const Component = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
(plugin) => plugin.Lens?.UI?.Content,
(plugin) => plugin.Badges?.UI?.Content,
)

return (
<Component
identity={visitingIdentity.identifier}
slot={Plugin.SiteAdaptor.LensSlot.ProfileName}
slot={Plugin.SiteAdaptor.BadgesSlot.ProfileName}
onStatusUpdate={setDisabled}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function avatarSelector() {
/**
* Inject on space dock
*/
export function injectFarcasterOnSpaceDock(signal: AbortSignal) {
export function injectBadgesOnSpaceDock(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(avatarSelector())
startWatch(watcher, signal)
watcher.useForeach((node, _, proxy) => {
Expand All @@ -30,7 +30,7 @@ export function injectFarcasterOnSpaceDock(signal: AbortSignal) {
const userId = avatar.dataset.testid?.slice('UserAvatar-Container-'.length)
if (!userId) return
attachReactTreeWithContainer(proxy.afterShadow, { signal, untilVisible: true }).render(
<SpaceDockFarcasterSlot userId={userId} />,
<SpaceDockBadgesSlot userId={userId} />,
)
})
}
Expand Down Expand Up @@ -66,14 +66,14 @@ function createRootElement() {
return span
}

function SpaceDockFarcasterSlot({ userId }: Props) {
function SpaceDockBadgesSlot({ userId }: Props) {
const [disabled, setDisabled] = useState(true)
const { classes, cx } = useStyles()

const component = useMemo(() => {
const Component = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
(plugin) => plugin.Farcaster?.UI?.Content,
(plugin) => plugin.Badges?.UI?.Content,
undefined,
createRootElement,
)
Expand All @@ -83,7 +83,7 @@ function SpaceDockFarcasterSlot({ userId }: Props) {
return (
<Component
identity={identifier}
slot={Plugin.SiteAdaptor.FarcasterSlot.Sidebar}
slot={Plugin.SiteAdaptor.BadgesSlot.Sidebar}
onStatusUpdate={setDisabled}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ function selector() {
/**
* Inject on sidebar user cell
*/
export function injectFarcasterOnUserCell(signal: AbortSignal) {
export function injectBadgesOnUserCell(signal: AbortSignal) {
const watcher = new MutationObserverWatcher(selector())
startWatch(watcher, signal)
watcher.useForeach((node, _, proxy) => {
const userId = node.closest('[role=link]')?.getAttribute('href')?.slice(1)
if (!userId) return
// Intended to set `untilVisible` to true, but mostly user cells are fixed and visible
attachReactTreeWithContainer(proxy.afterShadow, { signal }).render(<UserCellFarcasterSlot userId={userId} />)
attachReactTreeWithContainer(proxy.afterShadow, { signal }).render(<UserCellBadgesSlot userId={userId} />)
})
}

Expand Down Expand Up @@ -59,14 +59,14 @@ function createRootElement() {
return span
}

function UserCellFarcasterSlot({ userId }: Props) {
function UserCellBadgesSlot({ userId }: Props) {
const [disabled, setDisabled] = useState(true)
const { classes, cx } = useStyles()

const component = useMemo(() => {
const Component = createInjectHooksRenderer(
useActivatedPluginsSiteAdaptor.visibility.useNotMinimalMode,
(plugin) => plugin.Farcaster?.UI?.Content,
(plugin) => plugin.Badges?.UI?.Content,
undefined,
createRootElement,
)
Expand All @@ -77,7 +77,7 @@ function UserCellFarcasterSlot({ userId }: Props) {
return (
<Component
identity={identifier}
slot={Plugin.SiteAdaptor.FarcasterSlot.Sidebar}
slot={Plugin.SiteAdaptor.BadgesSlot.Sidebar}
onStatusUpdate={setDisabled}
/>
)
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0016e61

Please sign in to comment.