diff --git a/.gitignore b/.gitignore index 0caf84d..dd42adf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,7 @@ output.webm utils/ocean-tiles/ocean utils/osm-tiles/osm i18n/*.mo -test.js +test*.js logs *.log diff --git a/src/components/Admintools.jsx b/src/components/Admintools.jsx new file mode 100644 index 0000000..ff019fd --- /dev/null +++ b/src/components/Admintools.jsx @@ -0,0 +1,244 @@ +/* + * Admintools + */ + +import React, { useState, useEffect } from 'react'; +import { t } from 'ttag'; + +async function submitIPAction( + action, + callback, +) { + const data = new FormData(); + const iplist = document.getElementById('iparea').value; + data.append('ip', iplist); + data.append('ipaction', action); + const resp = await fetch('./api/modtools', { + credentials: 'include', + method: 'POST', + body: data, + }); + callback(await resp.text()); +} + +async function getModList( + callback, +) { + const data = new FormData(); + data.append('modlist', true); + const resp = await fetch('./api/modtools', { + credentials: 'include', + method: 'POST', + body: data, + }); + if (resp.ok) { + callback(await resp.json()); + } else { + callback([]); + } +} + +async function submitRemMod( + userId, + callback, +) { + const data = new FormData(); + data.append('remmod', userId); + const resp = await fetch('./api/modtools', { + credentials: 'include', + method: 'POST', + body: data, + }); + callback(resp.ok, await resp.text()); +} + +async function submitMakeMod( + userName, + callback, +) { + const data = new FormData(); + data.append('makemod', userName); + const resp = await fetch('./api/modtools', { + credentials: 'include', + method: 'POST', + body: data, + }); + if (resp.ok) { + callback(await resp.json()); + } else { + callback(await resp.text()); + } +} + + +function Admintools() { + const [iPAction, selectIPAction] = useState('ban'); + const [modName, selectModName] = useState(''); + const [resp, setResp] = useState(null); + const [modlist, setModList] = useState([]); + const [submitting, setSubmitting] = useState(false); + + useEffect(() => { + getModList((mods) => setModList(mods)); + }, []); + + return ( +
+ {resp && ( +
+ {resp.split('\n').map((line) => ( +

+ {line} +

+ ))} + setResp(null)} + > + {t`Close`} + +
+ )} +
+
+
+

{t`IP Actions`}

+

+ {t`Do stuff with IPs (one IP per line)`} +

+ +
+