-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
223 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Stickyban } from "../types/stickyban"; | ||
import { Link } from "./link"; | ||
import { Dialog } from "./dialog"; | ||
import { StickybanModal } from "./stickybanModal"; | ||
|
||
export const StickybanMatch: React.FC<StickybanMatch> = ( | ||
props: StickybanMatch | ||
) => { | ||
const [stickyData, setStickyData] = useState<Stickyban[] | null>(null); | ||
const [open, setOpen] = useState(false); | ||
|
||
const { ip, ckey, cid } = props; | ||
|
||
const getPath = () => { | ||
if (ip) return `/Stickyban/Ip?ip=${ip}`; | ||
if (ckey) return `/Stickyban/Ckey?ckey=${ckey}`; | ||
if (cid) return `/Stickyban/Cid?cid=${cid}`; | ||
}; | ||
|
||
const getText = () => { | ||
if (ip) return "IP"; | ||
if (ckey) return "CKEY"; | ||
if (cid) return "CID"; | ||
}; | ||
|
||
useEffect(() => { | ||
if (!stickyData) { | ||
fetch(`${import.meta.env.VITE_API_PATH}${getPath()}`).then((value) => | ||
value.json().then((json) => setStickyData(json)) | ||
); | ||
} | ||
}); | ||
|
||
if (!stickyData?.length) return; | ||
|
||
return ( | ||
<> | ||
<div className="red-alert-bg p-3 mt-3"> | ||
<div className="foreground p-3"> | ||
<Link onClick={() => setOpen(true)}> | ||
{getText()} has active stickybans. | ||
</Link> | ||
</div> | ||
</div> | ||
{open && ( | ||
<Dialog toggle={() => setOpen(false)} open={open}> | ||
<StickybanModal stickybans={stickyData} /> | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
type StickybanMatch = { | ||
ip?: string; | ||
ckey?: string; | ||
cid?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { useState } from "react"; | ||
import { | ||
Stickyban, | ||
StickybansMatchedCid, | ||
StickybansMatchedCkey, | ||
StickybansMatchedIp, | ||
} from "../types/stickyban"; | ||
import { Link } from "./link"; | ||
import { Dialog } from "./dialog"; | ||
|
||
type StickybanModalProps = { | ||
stickybans: Stickyban[]; | ||
}; | ||
|
||
export const StickybanModal: React.FC<StickybanModalProps> = ( | ||
props: StickybanModalProps | ||
) => { | ||
const { stickybans } = props; | ||
|
||
return ( | ||
<div className="pt-10"> | ||
<div className="overflow-scroll max-h-[800px]"> | ||
<table className="w-full"> | ||
<tbody> | ||
<tr> | ||
<th>Identifier</th> | ||
<th>Message</th> | ||
<th>Reason</th> | ||
<th>Actions</th> | ||
</tr> | ||
{stickybans.map((stickyban) => ( | ||
<StickybanEntry stickyban={stickyban} key={stickyban.id} /> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const StickybanEntry = (props: { stickyban: Stickyban }) => { | ||
const { stickyban } = props; | ||
|
||
return ( | ||
<tr> | ||
<td className="border p-2">{stickyban.identifier}</td> | ||
<td className="border p-2">{stickyban.message}</td> | ||
<td className="border p-2">{stickyban.reason.trim()}</td> | ||
<td className="border p-2"> | ||
<ExpandDetails stickyban={stickyban} /> | ||
</td> | ||
</tr> | ||
); | ||
}; | ||
|
||
const ExpandDetails = (props: { stickyban: Stickyban }) => { | ||
const { stickyban } = props; | ||
|
||
const [cids, setCids] = useState<StickybansMatchedCid[] | null>(null); | ||
const [ckeys, setCkeys] = useState<StickybansMatchedCkey[] | null>(null); | ||
const [ips, setIps] = useState<StickybansMatchedIp[] | null>(null); | ||
|
||
const [open, setOpen] = useState(false); | ||
|
||
const check = () => { | ||
setOpen(true); | ||
|
||
fetch( | ||
`${import.meta.env.VITE_API_PATH}/Stickyban/Match/Cid?id=${stickyban.id}` | ||
).then((value) => | ||
value.json().then((json) => { | ||
setCids(json); | ||
}) | ||
); | ||
|
||
fetch( | ||
`${import.meta.env.VITE_API_PATH}/Stickyban/Match/Ckey?id=${stickyban.id}` | ||
).then((value) => | ||
value.json().then((json) => { | ||
setCkeys(json); | ||
}) | ||
); | ||
|
||
fetch( | ||
`${import.meta.env.VITE_API_PATH}/Stickyban/Match/Ip?id=${stickyban.id}` | ||
).then((value) => | ||
value.json().then((json) => { | ||
setIps(json); | ||
}) | ||
); | ||
}; | ||
|
||
return ( | ||
<> | ||
<Link onClick={() => check()}>Details</Link> | ||
{open && ( | ||
<Dialog open={!!cids} toggle={() => setOpen(false)}> | ||
<div className="flex flex-col pt-10"> | ||
<div>CIDs: {cids && cids.map((cid) => cid.cid).join(", ")}</div> | ||
<div> | ||
CKEYs: {ckeys && ckeys.map((ckey) => ckey.ckey).join(", ")} | ||
</div> | ||
<div>IPs: {ips && ips.map((ip) => ip.ip).join(", ")}</div> | ||
</div> | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.