Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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<void>; + reSearch: (user: { + accountName: string; + displayName: string; + }) => Promise<void>; }; -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 ( <div className="bg-base-100 w-full relative grid grid-cols-[22%_1fr] gap-5"> - <DetectedUserSource user={user} /> + <DetectedUserSource user={user} reSearch={reSearch} /> <UserCard user={user} loading={loading} diff --git a/src/lib/components/DetectedUserSource.tsx b/src/lib/components/DetectedUserSource.tsx index 62121bd..f23a3cb 100644 --- a/src/lib/components/DetectedUserSource.tsx +++ b/src/lib/components/DetectedUserSource.tsx @@ -2,12 +2,17 @@ import React from "react"; import type { BskyUser } from "~types"; import { MATCH_TYPE_LABEL_AND_COLOR } from "../constants"; import { UserInfo, UserProfile } from "./UserCard"; +import type { ProfileView } from "@atproto/api/dist/client/types/app/bsky/actor/defs"; type DetectedUserSourceProps = { user: BskyUser; + reSearch: (user: { + accountName: string; + displayName: string; + }) => Promise<void>; }; -const DetectedUserSource = ({ user }: DetectedUserSourceProps) => ( +const DetectedUserSource = ({ user, reSearch }: DetectedUserSourceProps) => ( <div className="flex flex-row gap-2 bg-slate-100 dark:bg-slate-800 justify-between pr-2"> <div className={`border-l-8 border-${ @@ -44,6 +49,17 @@ const DetectedUserSource = ({ user }: DetectedUserSourceProps) => ( /> </svg> </div> + <button + type="button" + onClick={() => + reSearch({ + accountName: user.originalHandle, + displayName: user.originalDisplayName, + }) + } + > + Re-search + </button> </div> ); 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<ProfileView[]>( + [], + ); + 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 ( <> <div className="flex h-screen"> @@ -126,11 +143,22 @@ const Option = () => { user={user} clickAction={handleClickAction} actionMode={actionMode} + reSearch={handleReSearch} /> ))} </div> </div> </div> + <Modal + open={showReSearchModal} + onClose={() => setShowReSearchModal(false)} + > + <div className="divide-y divide-gray-500"> + {reSearchResults.map((user) => ( + <div key={user.did}>{user.displayName}</div> + ))} + </div> + </Modal> <ToastContainer position="top-right" autoClose={5000}
- Loading branch information