diff --git a/src/components/Admintools.jsx b/src/components/Admintools.jsx index 4904723..4b3d667 100644 --- a/src/components/Admintools.jsx +++ b/src/components/Admintools.jsx @@ -4,7 +4,7 @@ * @flow */ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { connect } from 'react-redux'; import type { State } from '../reducers'; @@ -96,10 +96,60 @@ async function submitIPAction( callback(await resp.text()); } +async function getModList( + callback, +) { + const data = new FormData(); + data.append('modlist', true); + const resp = await fetch('./admintools', { + 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('./admintools', { + 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('./admintools', { + credentials: 'include', + method: 'POST', + body: data, + }); + if (resp.ok) { + callback(await resp.json()); + } else { + callback(await resp.text()); + } +} + function Admintools({ canvasId, canvases, + userlvl, }) { const curDate = new Date(); let day = curDate.getDate(); @@ -118,7 +168,9 @@ function Admintools({ const [brcoords, selectBRCoords] = useState(keptState.brcoords); const [tlrcoords, selectTLRCoords] = useState(keptState.tlrcoords); const [brrcoords, selectBRRCoords] = useState(keptState.brrcoords); + const [modName, selectModName] = useState(null); const [resp, setResp] = useState(null); + const [modlist, setModList] = useState([]); const [submitting, setSubmitting] = useState(false); let descAction; @@ -136,6 +188,12 @@ function Admintools({ // nothing } + useEffect(() => { + if (userlvl) { + getModList((mods) => setModList(mods)); + } + }, []); + return (

{resp && ( @@ -403,52 +461,144 @@ function Admintools({ {(submitting) ? '...' : 'Submit'} -
-

-

IP Actions

-

Do stuff with IPs (one IP per line)

- { + const sel = e.target; + selectIPAction(sel.options[sel.selectedIndex].value); + }} > - {opt} - - ))} - -
-