-
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
6 changed files
with
186 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { useState } from "react"; | ||
import { Link } from "./link"; | ||
import { Dialog } from "./dialog"; | ||
|
||
type ExpandProps = { | ||
label: string; | ||
value: string; | ||
}; | ||
|
||
export const Expand: React.FC<ExpandProps> = (props: ExpandProps) => { | ||
const [open, setOpen] = useState(false); | ||
|
||
return ( | ||
<> | ||
<Link onClick={() => setOpen(true)}>{props.label}</Link> | ||
{open && ( | ||
<Dialog open={open} toggle={() => setOpen(false)}> | ||
<div className="pt-10">{props.value}</div> | ||
</Dialog> | ||
)} | ||
</> | ||
); | ||
}; |
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,139 @@ | ||
import React, { useEffect, useState } from "react"; | ||
import { Link } from "./link"; | ||
import { Dialog } from "./dialog"; | ||
|
||
type Stickyban = { | ||
id: number; | ||
identifier: string; | ||
reason: string; | ||
message: string; | ||
date: string; | ||
active: boolean; | ||
adminId?: number; | ||
adminCkey?: string; | ||
}; | ||
|
||
export const StickybansModal: React.FC<Record<string, never>> = () => { | ||
const [stickybanData, setStickybanData] = useState<Stickyban[] | null>(null); | ||
|
||
useEffect(() => { | ||
if (!stickybanData) { | ||
fetch(`${import.meta.env.VITE_API_PATH}/Stickyban`).then((value) => | ||
value.json().then((json) => setStickybanData(json)) | ||
); | ||
} | ||
}); | ||
|
||
if (!stickybanData) { | ||
return <div className="flex flex-row justify-center">Loading...</div>; | ||
} | ||
|
||
return ( | ||
<div className="pt-10"> | ||
<div className="overflow-scroll max-h-[800px]"> | ||
<table> | ||
<tbody> | ||
<tr> | ||
<th>Identifier</th> | ||
<th>Message</th> | ||
<th>Reason</th> | ||
<th>Actions</th> | ||
</tr> | ||
{stickybanData.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> | ||
); | ||
}; | ||
|
||
type StickybansMatchedCid = { | ||
id: number; | ||
cid: string; | ||
linkedStickyban: number; | ||
}; | ||
|
||
type StickybansMatchedCkey = { | ||
id: number; | ||
ckey: string; | ||
linkedStickyban: number; | ||
whitelisted: boolean; | ||
}; | ||
|
||
type StickybansMatchedIp = { | ||
id: number; | ||
ip: string; | ||
linkedStickyban: number; | ||
}; | ||
|
||
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/Cid?id=${stickyban.id}` | ||
).then((value) => | ||
value.json().then((json) => { | ||
setCids(json); | ||
}) | ||
); | ||
|
||
fetch( | ||
`${import.meta.env.VITE_API_PATH}/Stickyban/Ckey?id=${stickyban.id}` | ||
).then((value) => | ||
value.json().then((json) => { | ||
setCkeys(json); | ||
}) | ||
); | ||
|
||
fetch( | ||
`${import.meta.env.VITE_API_PATH}/Stickyban/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> | ||
)} | ||
</> | ||
); | ||
}; |
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