Skip to content

Commit 58f9cdb

Browse files
committed
clear data when empty
1 parent c9af041 commit 58f9cdb

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

src/components/stickybanMatch.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ export const StickybanMatch: React.FC<StickybanMatch> = (
2020

2121
const { ip, ckey, cid } = props;
2222

23-
const getPath = () => {
24-
if (ip) return `/Stickyban/Ip?ip=${ip}`;
25-
if (ckey) return `/Stickyban/Ckey?ckey=${ckey}`;
26-
return `/Stickyban/Cid?cid=${cid}`;
27-
};
23+
const [lookedUp, setLookedUp] = useState<string>("");
2824

2925
const getText = () => {
3026
if (ip) return "IP";
@@ -33,12 +29,27 @@ export const StickybanMatch: React.FC<StickybanMatch> = (
3329
};
3430

3531
useEffect(() => {
36-
if (!stickyData) {
32+
const getPath = () => {
33+
if (ip) return `/Stickyban/Ip?ip=${ip}`;
34+
if (ckey) return `/Stickyban/Ckey?ckey=${ckey}`;
35+
return `/Stickyban/Cid?cid=${cid}`;
36+
};
37+
38+
const to_use = ip || ckey || cid;
39+
40+
if (stickyData && to_use != lookedUp) {
41+
setStickyData(null);
42+
}
43+
44+
if (!stickyData && to_use != lookedUp) {
3745
callApi(getPath()).then((value) =>
38-
value.json().then((json) => setStickyData(json))
46+
value.json().then((json) => {
47+
setStickyData(json);
48+
setLookedUp(to_use!);
49+
})
3950
);
4051
}
41-
});
52+
}, [stickyData, cid, ckey, ip, lookedUp]);
4253

4354
if (!stickyData?.length) return;
4455

0 commit comments

Comments
 (0)