diff --git a/src/lib/bskyHelpers.ts b/src/lib/bskyHelpers.ts index e9460d2..cea2ed2 100644 --- a/src/lib/bskyHelpers.ts +++ b/src/lib/bskyHelpers.ts @@ -1,5 +1,5 @@ import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; -import { BSKY_USER_MATCH_TYPE } from "./constants"; +import { BSKY_PROFILE_LABEL, BSKY_USER_MATCH_TYPE } from "./constants"; type xUserInfo = { bskyHandleInDescription: string; @@ -80,3 +80,9 @@ export const isSimilarUser = ( type: BSKY_USER_MATCH_TYPE.NONE, }; }; + +export const isImpersonationUser = (user: ProfileView) => { + return user.labels.some( + (label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION, + ); +}; diff --git a/src/lib/components/DetectedUserListItem.tsx b/src/lib/components/DetectedUserListItem.tsx index b5d1c92..7466377 100644 --- a/src/lib/components/DetectedUserListItem.tsx +++ b/src/lib/components/DetectedUserListItem.tsx @@ -4,13 +4,23 @@ import type { BskyUser } from "~types"; import { ACTION_MODE } from "../constants"; import DetectedUserSource from "./DetectedUserSource"; import UserCard from "./UserCard"; +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; export type Props = { user: BskyUser; actionMode: (typeof ACTION_MODE)[keyof typeof ACTION_MODE]; clickAction: (user: BskyUser) => Promise; + reSearch: (user: { + accountName: string; + displayName: string; + }) => Promise; }; -const DetectedUserListItem = ({ user, actionMode, clickAction }: Props) => { +const DetectedUserListItem = ({ + user, + actionMode, + clickAction, + reSearch, +}: Props) => { const [isBtnHovered, setIsBtnHovered] = React.useState(false); const [isJustClicked, setIsJustClicked] = React.useState(false); const actionBtnLabelAndClass = React.useMemo( @@ -83,7 +93,7 @@ const DetectedUserListItem = ({ user, actionMode, clickAction }: Props) => { return (
- + Promise; }; -const DetectedUserSource = ({ user }: DetectedUserSourceProps) => ( +const DetectedUserSource = ({ user, reSearch }: DetectedUserSourceProps) => (
( />
+
); diff --git a/src/lib/hooks/useBskyUserManager.ts b/src/lib/hooks/useBskyUserManager.ts index ff2cecc..ad43316 100644 --- a/src/lib/hooks/useBskyUserManager.ts +++ b/src/lib/hooks/useBskyUserManager.ts @@ -1,3 +1,4 @@ +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import { Storage } from "@plasmohq/storage"; import { useStorage } from "@plasmohq/storage/hook"; import React from "react"; @@ -9,6 +10,7 @@ import { MESSAGE_NAME_TO_ACTION_MODE_MAP, STORAGE_KEYS, } from "~lib/constants"; +import { reSearchBskyUser } from "~lib/reSearchBskyUsers"; import { wait } from "~lib/utils"; import type { BskyUser, MatchType } from "~types"; @@ -242,6 +244,29 @@ export const useBskyUserManager = () => { ); }, [users, matchTypeFilter]); + const [reSearchResults, setReSearchResults] = React.useState( + [], + ); + const reSearch = React.useCallback( + async ({ + accountName, + displayName, + }: { + accountName: string; + displayName: string; + }) => { + const searchResults = await reSearchBskyUser({ + client: bskyClient.current, + userData: { + accountName, + displayName, + }, + }); + setReSearchResults(searchResults); + }, + [], + ); + return { handleClickAction, users, @@ -253,5 +278,7 @@ export const useBskyUserManager = () => { importList, followAll, blockAll, + reSearch, + reSearchResults, }; }; diff --git a/src/lib/searchBskyUsers.ts b/src/lib/searchBskyUsers.ts index 55eeac0..34c2f13 100644 --- a/src/lib/searchBskyUsers.ts +++ b/src/lib/searchBskyUsers.ts @@ -1,15 +1,8 @@ -import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; import { isSimilarUser } from "~lib/bskyHelpers"; import { isOneSymbol } from "~lib/utils"; import type { CrawledUserInfo } from "~types"; import type { BskyServiceWorkerClient } from "./bskyServiceWorkerClient"; -import { BSKY_PROFILE_LABEL } from "./constants"; - -const isImpersonationUser = (user: ProfileView) => { - return user.labels.some( - (label) => label.val === BSKY_PROFILE_LABEL.IMPERSONATION, - ); -}; +import { isImpersonationUser } from "./bskyHelpers"; export const searchBskyUser = async ({ client, diff --git a/src/options.tsx b/src/options.tsx index e8ad33d..662171b 100644 --- a/src/options.tsx +++ b/src/options.tsx @@ -5,6 +5,9 @@ import useConfirm from "~lib/components/ConfirmDialog"; import Sidebar from "~lib/components/Sidebar"; import "react-toastify/dist/ReactToastify.css"; import DetectedUserListItem from "~lib/components/DetectedUserListItem"; +import Modal from "~lib/components/Modal"; +import React from "react"; +import UserCard from "~lib/components/UserCard"; const Option = () => { const { @@ -18,6 +21,8 @@ const Option = () => { importList, followAll, blockAll, + reSearch, + reSearchResults, } = useBskyUserManager(); const { @@ -98,6 +103,18 @@ const Option = () => { }); }; + const [showReSearchModal, setShowReSearchModal] = React.useState(false); + const handleReSearch = async (user: { + accountName: string; + displayName: string; + }) => { + await reSearch({ + accountName: user.accountName, + displayName: user.displayName, + }); + setShowReSearchModal(true); + }; + return ( <>
@@ -126,11 +143,22 @@ const Option = () => { user={user} clickAction={handleClickAction} actionMode={actionMode} + reSearch={handleReSearch} /> ))}
+ setShowReSearchModal(false)} + > +
+ {reSearchResults.map((user) => ( +
{user.displayName}
+ ))} +
+