Skip to content

Commit

Permalink
[from now] 2024/11/30 20:44:12
Browse files Browse the repository at this point in the history
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
kawamataryo committed Nov 30, 2024
1 parent 4383913 commit cfd3827
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/lib/bskyHelpers.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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,
);
};
14 changes: 12 additions & 2 deletions src/lib/components/DetectedUserListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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}
Expand Down
18 changes: 17 additions & 1 deletion src/lib/components/DetectedUserSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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-${
Expand Down Expand Up @@ -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>
);

Expand Down
27 changes: 27 additions & 0 deletions src/lib/hooks/useBskyUserManager.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";

Expand Down Expand Up @@ -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,
Expand All @@ -253,5 +278,7 @@ export const useBskyUserManager = () => {
importList,
followAll,
blockAll,
reSearch,
reSearchResults,
};
};
9 changes: 1 addition & 8 deletions src/lib/searchBskyUsers.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
28 changes: 28 additions & 0 deletions src/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -18,6 +21,8 @@ const Option = () => {
importList,
followAll,
blockAll,
reSearch,
reSearchResults,
} = useBskyUserManager();

const {
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit cfd3827

Please sign in to comment.