mirror of
https://github.com/snachodog/tok-to-insta-follower-bridge.git
synced 2025-04-17 17:22:23 -06:00
chore: add abort controller
This commit is contained in:
parent
aaf28b0c95
commit
90d991b76e
@ -37,6 +37,7 @@ const App = () => {
|
|||||||
matchTypeFilter,
|
matchTypeFilter,
|
||||||
changeMatchTypeFilter,
|
changeMatchTypeFilter,
|
||||||
filteredUsers,
|
filteredUsers,
|
||||||
|
stopRetrieveLoop,
|
||||||
} = useRetrieveBskyUsers();
|
} = useRetrieveBskyUsers();
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@ -81,7 +82,7 @@ const App = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Modal anchorRef={modalRef}>
|
<Modal anchorRef={modalRef} onClose={stopRetrieveLoop}>
|
||||||
<div className="flex flex-col gap-6">
|
<div className="flex flex-col gap-6">
|
||||||
<div className="flex justify-between">
|
<div className="flex justify-between">
|
||||||
<h1 className="text-2xl font-bold">Find Bluesky Users</h1>
|
<h1 className="text-2xl font-bold">Find Bluesky Users</h1>
|
||||||
|
@ -1,12 +1,26 @@
|
|||||||
import type React from "react";
|
import type React from "react";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export type Props = {
|
export type Props = {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
anchorRef: React.RefObject<HTMLDialogElement>;
|
anchorRef: React.RefObject<HTMLDialogElement>;
|
||||||
open?: boolean;
|
open?: boolean;
|
||||||
|
onClose?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Modal = ({ children, anchorRef, open = false }: Props) => {
|
const Modal = ({ children, anchorRef, open = false, onClose }: Props) => {
|
||||||
|
useEffect(() => {
|
||||||
|
if (anchorRef.current) {
|
||||||
|
anchorRef.current.addEventListener("close", onClose);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (anchorRef.current) {
|
||||||
|
anchorRef.current.removeEventListener("close", onClose);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [anchorRef, onClose]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<dialog className="modal" ref={anchorRef} open={open}>
|
<dialog className="modal" ref={anchorRef} open={open}>
|
||||||
|
@ -151,12 +151,20 @@ export const useRetrieveBskyUsers = () => {
|
|||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const abortControllerRef = React.useRef<AbortController | null>(null);
|
||||||
const startRetrieveLoop = React.useCallback(
|
const startRetrieveLoop = React.useCallback(
|
||||||
async (queryParam: string) => {
|
async (queryParam: string) => {
|
||||||
|
abortControllerRef.current = new AbortController();
|
||||||
|
const signal = abortControllerRef.current.signal;
|
||||||
|
|
||||||
let isBottomReached = false;
|
let isBottomReached = false;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
while (!isBottomReached) {
|
while (!isBottomReached) {
|
||||||
|
if (signal.aborted) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
const data = detectXUsers(queryParam).filter((u) => {
|
const data = detectXUsers(queryParam).filter((u) => {
|
||||||
return !detectedXUsers.some(
|
return !detectedXUsers.some(
|
||||||
(t) => t.twAccountName === u.twAccountName,
|
(t) => t.twAccountName === u.twAccountName,
|
||||||
@ -191,6 +199,12 @@ export const useRetrieveBskyUsers = () => {
|
|||||||
[retrieveBskyUsers, detectedXUsers],
|
[retrieveBskyUsers, detectedXUsers],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const stopRetrieveLoop = () => {
|
||||||
|
if (abortControllerRef.current) {
|
||||||
|
abortControllerRef.current.abort();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const initialize = React.useCallback(
|
const initialize = React.useCallback(
|
||||||
async ({
|
async ({
|
||||||
identifier,
|
identifier,
|
||||||
@ -283,5 +297,6 @@ export const useRetrieveBskyUsers = () => {
|
|||||||
matchTypeFilter,
|
matchTypeFilter,
|
||||||
changeMatchTypeFilter,
|
changeMatchTypeFilter,
|
||||||
filteredUsers,
|
filteredUsers,
|
||||||
|
stopRetrieveLoop,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user