Skip to content

Commit

Permalink
clear data when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Oct 23, 2024
1 parent c9af041 commit 58f9cdb
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/components/stickybanMatch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ export const StickybanMatch: React.FC<StickybanMatch> = (

const { ip, ckey, cid } = props;

const getPath = () => {
if (ip) return `/Stickyban/Ip?ip=${ip}`;
if (ckey) return `/Stickyban/Ckey?ckey=${ckey}`;
return `/Stickyban/Cid?cid=${cid}`;
};
const [lookedUp, setLookedUp] = useState<string>("");

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

useEffect(() => {
if (!stickyData) {
const getPath = () => {
if (ip) return `/Stickyban/Ip?ip=${ip}`;
if (ckey) return `/Stickyban/Ckey?ckey=${ckey}`;
return `/Stickyban/Cid?cid=${cid}`;
};

const to_use = ip || ckey || cid;

if (stickyData && to_use != lookedUp) {
setStickyData(null);
}

if (!stickyData && to_use != lookedUp) {
callApi(getPath()).then((value) =>
value.json().then((json) => setStickyData(json))
value.json().then((json) => {
setStickyData(json);
setLookedUp(to_use!);
})
);
}
});
}, [stickyData, cid, ckey, ip, lookedUp]);

if (!stickyData?.length) return;

Expand Down

0 comments on commit 58f9cdb

Please sign in to comment.