New UI who dis

This commit is contained in:
oitsjustjose 2023-04-20 23:53:56 -05:00
commit 43fc7d78d0
14 changed files with 440 additions and 0 deletions

9
frontend/src/App.css Normal file
View file

@ -0,0 +1,9 @@
.juse-form {
border: 1px solid var(--bs-border-color);
border-radius: 8px;
padding: 2rem;
}
.output-log {
margin-top: 2rem;
}

4
frontend/src/App.jsx Normal file
View file

@ -0,0 +1,4 @@
import React from 'react';
import Home from './pages/Home';
export default () => (<Home />);

View file

@ -0,0 +1,52 @@
import React, { useState } from 'react';
export default () => {
const [render, setRender] = useState(true);
const hide = () => {
window.localStorage.setItem('info-dismissed', true);
setRender(false);
};
return render && (
<div>
<p>
<b>Welcome!</b>
{' '}
In order to use this tool you&apos;ll need to have already created (if it&apos;s
still &quot;Under Review&quot;, that&apos;s ok) your Modrinth Page, and a few other things:
<ul>
<li>
A
{' '}
<a href="https://docs.github.com/en/enterprise-server@3.4/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token" target="_blank" rel="noreferrer">
GitHub Personal Access Token
</a>
{' '}
for the Account you used to log into Modrinth. No
permissions need to be granted to the PAT, this token will be encrypted from end
to end (even in storage), and it will only be used for requests to Modrinth
(feel encouraged to browse this source code to verify).
</li>
<li>
The CurseForge Slug for your Mod. This can be found in the General Settings for your
project page
</li>
<li>
The Modrinth Project ID. This can be found in the side panel of your Modrinth project
</li>
</ul>
This tool works on a queue-based system since I cannot afford enough computing for everyone,
so you&apos;ll be able to see your status and place in the queue down below in the
&quot;Status &amp; Output Log&quot;. You will not lose your place in the queue if you close
this tab or leave this page, as long as you do not clear browser storage you will still be
able to track progress here, or of course on your Modrinth project page!
</p>
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a style={{ float: 'right', marginTop: '-2rem' }} href="#" role="button" onClick={hide}><sup>[Hide]</sup></a>
</div>
);
};

View file

@ -0,0 +1,19 @@
import React, { useState, useEffect } from 'react';
export default ({ id }) => {
const [logs, setLogs] = useState('');
useEffect(() => {
const handle = setInterval(async () => {
const resp = await fetch(`/jobs/status/${id}`);
if (resp.ok) {
setLogs(await resp.text());
} else {
setLogs(`${resp.status}: ${resp.statusText}`);
}
}, 500);
return () => clearInterval(handle);
}, [setLogs, id]);
return (<code>{logs}</code>);
};

10
frontend/src/index.js Normal file
View file

@ -0,0 +1,10 @@
import { createRoot } from 'react-dom/client';
import App from './App';
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';
const container = document.getElementById('root');
const root = createRoot(container);
root.render(App());

173
frontend/src/pages/Home.jsx Normal file
View file

@ -0,0 +1,173 @@
import React, { useState } from 'react';
import {
Form, Button, Container, Accordion, Modal,
} from 'react-bootstrap';
import OutputLog from '../components/OutputLog';
import Info from '../components/Info';
export default () => {
const [help, setHelp] = useState(null);
const [jobId, setJobId] = useState(window.localStorage.getItem('last-jobid'));
const [formData, setFormData] = useState({
githubPat: '',
slug: '',
projId: '',
});
// eslint-disable-next-line max-len
const isValidState = () => !!formData.githubPat.length && !!formData.slug.length && !!formData.projId.length;
const delimHelp = (evt) => {
evt.preventDefault();
setHelp((
<div>
<p>
This is the splitter between parts of the filename. Geolosys uses format
{' '}
<code>MODNAME-MCVER-MAJOR.MINOR.PATCH</code>
, where
{' '}
<code>-</code>
{' '}
is the delimiter.
</p>
<p>
Using this logic, it is assumed that the Minecraft version for this
{' '}
<code>.jar</code>
-file is between the first and second delimiter, and that the mod version is between
the second and the end of the file. Formatting aside from this is not supported,
unfortunately, as I&apos;ve got a bit of trauma
{' '}
<sup>(/s)</sup>
{' '}
from
{' '}
<a href="https://dv2ls.com/code?id=lUY-c4A2H" target="_blank" rel="noreferrer">
this Regular Expression I wrote.
</a>
</p>
</div>
));
};
const makeJob = async (evt) => {
evt.preventDefault();
if (!isValidState()) return;
const resp = await fetch('/jobs/new', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
if (resp && resp.ok) {
const data = await resp.text();
setJobId(data);
window.localStorage.setItem('last-jobid', data);
}
};
return (
<div style={{ margin: 'auto', maxWidth: '768px' }}>
<h2 className="mb-4 text-center">
CurseForge to Modrinth Mod Migrator (CTMMM)
</h2>
{!window.localStorage.getItem('info-dismissed') && (<Info />)}
<Container style={{ margin: '1rem auto', maxWidth: '512px' }}>
<Form onSubmit={makeJob} className="juse-form">
<Form.Group className="mb-3" controlId="githubPat">
<Form.Label>GitHub Personal Access Token</Form.Label>
<Form.Control
type="password"
required
placeholder="This field is required"
value={formData.githubPat}
onChange={(x) => setFormData({
...formData,
githubPat: x.target.value,
})}
/>
<Form.Text className="text-muted">
This value is encrypted from end-to-end and even in storage
</Form.Text>
</Form.Group>
<Form.Group className="mb-3" controlId="slug">
<Form.Label>CurseForge Project Slug</Form.Label>
<Form.Control
type="text"
required
placeholder="This field is required"
value={formData.slug}
onChange={(x) => setFormData({
...formData,
slug: x.target.value,
})}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="projId">
<Form.Label>Modrinth Project ID</Form.Label>
<Form.Control
type="text"
required
placeholder="This field is required"
value={formData.projId}
onChange={(x) => setFormData({
...formData,
projId: x.target.value,
})}
/>
</Form.Group>
<Form.Group className="mb-3" controlId="delimiter">
<Form.Label>
Delimiter (Optional)
{' '}
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
<a onClick={delimHelp} style={{ textDecoration: 'none' }} href="#">❔</a>
</Form.Label>
<Form.Control
placeholder="Defaults to Hyphen (-)"
type="text"
value={formData.delimiter}
onChange={(x) => setFormData({
...formData,
delimiter: x.target.value,
})}
/>
</Form.Group>
<Button
variant="success"
type="submit"
disabled={!isValidState()}
>
Submit
</Button>
</Form>
{jobId && (
<Accordion defaultActiveKey="0" className="mt-2">
<Accordion.Item eventKey="1">
<Accordion.Header>
<div>
Status &amp; Output Log for Job
{' '}
<code>{`#${jobId}`}</code>
</div>
</Accordion.Header>
<Accordion.Body>{jobId && (<OutputLog id={jobId} />)}</Accordion.Body>
</Accordion.Item>
</Accordion>
)}
</Container>
<Modal centered show={!!help} onHide={() => setHelp(null)}>
<Modal.Body>{help}</Modal.Body>
</Modal>
</div>
);
};