From 43fc7d78d0a98a226c1baa61691824d7610f6470 Mon Sep 17 00:00:00 2001 From: oitsjustjose Date: Thu, 20 Apr 2023 23:53:56 -0500 Subject: [PATCH] New UI who dis --- frontend/.dockerignore | 5 + frontend/.eslintrc.json | 28 +++++ frontend/.gitignore | 28 +++++ frontend/.prettierrc | 6 + frontend/Dockerfile | 24 ++++ frontend/package.json | 45 +++++++ frontend/public/index.html | 22 ++++ frontend/public/manifest.json | 15 +++ frontend/src/App.css | 9 ++ frontend/src/App.jsx | 4 + frontend/src/components/Info.jsx | 52 ++++++++ frontend/src/components/OutputLog.jsx | 19 +++ frontend/src/index.js | 10 ++ frontend/src/pages/Home.jsx | 173 ++++++++++++++++++++++++++ 14 files changed, 440 insertions(+) create mode 100644 frontend/.dockerignore create mode 100644 frontend/.eslintrc.json create mode 100644 frontend/.gitignore create mode 100644 frontend/.prettierrc create mode 100644 frontend/Dockerfile create mode 100644 frontend/package.json create mode 100644 frontend/public/index.html create mode 100644 frontend/public/manifest.json create mode 100644 frontend/src/App.css create mode 100644 frontend/src/App.jsx create mode 100644 frontend/src/components/Info.jsx create mode 100644 frontend/src/components/OutputLog.jsx create mode 100644 frontend/src/index.js create mode 100644 frontend/src/pages/Home.jsx diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..f132a49 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,5 @@ +build/** +.idea/ +node_modules/ +vs_code/ +Dockerfile \ No newline at end of file diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json new file mode 100644 index 0000000..65b9ef0 --- /dev/null +++ b/frontend/.eslintrc.json @@ -0,0 +1,28 @@ +{ + "env": { + "browser": true, + "es6": true, + "jest": true + }, + "extends": ["plugin:react/recommended", "airbnb"], + "globals": { + "Atomics": "readonly", + "SharedArrayBuffer": "readonly" + }, + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 11, + "sourceType": "module" + }, + "plugins": ["react"], + "rules": { + "import/no-cycle": 0, + "no-unused-expressions": 0, + "react/jsx-props-no-spreading": 0, + "react/prop-types": 0, + "react/function-component-definition": 0, + "react/no-alert": 0 + } +} diff --git a/frontend/.gitignore b/frontend/.gitignore new file mode 100644 index 0000000..0d29aa3 --- /dev/null +++ b/frontend/.gitignore @@ -0,0 +1,28 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# production +/build + +# misc +.DS_Store +.env.local +.env.development.local +.env.test.local +.env.production.local + +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +yarn.lock + +.vscode/ +.vscode/* \ No newline at end of file diff --git a/frontend/.prettierrc b/frontend/.prettierrc new file mode 100644 index 0000000..44e874d --- /dev/null +++ b/frontend/.prettierrc @@ -0,0 +1,6 @@ +{ + "arrowParens": "avoid", + "trailingComma": "es5", + "singleQuote": true, + "semi": true +} \ No newline at end of file diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..c7fe761 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,24 @@ +FROM node:18-alpine AS builder + +RUN apk update && apk upgrade && \ + apk add --no-cache bash git openssh + +WORKDIR /app +COPY package*.json ./ +RUN npm install + +COPY . . +RUN npm run build +FROM node:18-alpine AS server + +ENV NODE_ENV=production +RUN npm install -g serve + +WORKDIR /app +COPY package*.json ./ +COPY --from=builder /app/build ./build + +ENV PORT=3000 +EXPOSE 3000 +USER node +CMD ["serve", "-s", "build"] \ No newline at end of file diff --git a/frontend/package.json b/frontend/package.json new file mode 100644 index 0000000..29edc44 --- /dev/null +++ b/frontend/package.json @@ -0,0 +1,45 @@ +{ + "name": "ctmmm-ui", + "version": "1.0.0", + "private": true, + "dependencies": { + "@popperjs/core": "^2.11.7", + "bootstrap": "^5.2.3", + "react": "18.2.0", + "react-bootstrap": "^2.7.4", + "react-dom": "18.2.0", + "react-scripts": "5.0.1", + "web-vitals": "^2.1.0" + }, + "scripts": { + "start": "react-scripts start", + "build": "react-scripts build", + "test": "react-scripts test", + "eject": "react-scripts eject" + }, + "eslintConfig": { + "extends": "react-app" + }, + "devDependencies": { + "eslint": "^8.13.0", + "eslint-config-airbnb": "^19.0.4", + "eslint-plugin-import": "^2.22.1", + "eslint-plugin-jsx-a11y": "^6.3.1", + "eslint-plugin-prefer-arrow-functions": "^3.1.4", + "eslint-plugin-react": "^7.21.4", + "eslint-plugin-react-hooks": "^4.1.2" + }, + "proxy": "http://localhost:3000", + "browserslist": { + "production": [ + ">0.2%", + "not dead", + "not op_mini all" + ], + "development": [ + "last 1 chrome version", + "last 1 firefox version", + "last 1 safari version" + ] + } +} diff --git a/frontend/public/index.html b/frontend/public/index.html new file mode 100644 index 0000000..dd885d1 --- /dev/null +++ b/frontend/public/index.html @@ -0,0 +1,22 @@ + + + + + + + + + + + + + CTMMM + + + + +
+ + + \ No newline at end of file diff --git a/frontend/public/manifest.json b/frontend/public/manifest.json new file mode 100644 index 0000000..b618772 --- /dev/null +++ b/frontend/public/manifest.json @@ -0,0 +1,15 @@ +{ + "short_name": "Curseforge to Modrinth Exporter", + "name": "A Migration Tool to Pull CF Files and Move Them to Modrinth!", + "icons": [ + { + "src": "app-icon.png", + "type": "image/png", + "sizes": "128x128" + } + ], + "start_url": ".", + "display": "standalone", + "theme_color": "#252525", + "background_color": "#252525" +} \ No newline at end of file diff --git a/frontend/src/App.css b/frontend/src/App.css new file mode 100644 index 0000000..2147503 --- /dev/null +++ b/frontend/src/App.css @@ -0,0 +1,9 @@ +.juse-form { + border: 1px solid var(--bs-border-color); + border-radius: 8px; + padding: 2rem; +} + +.output-log { + margin-top: 2rem; +} diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx new file mode 100644 index 0000000..3426d75 --- /dev/null +++ b/frontend/src/App.jsx @@ -0,0 +1,4 @@ +import React from 'react'; +import Home from './pages/Home'; + +export default () => (); diff --git a/frontend/src/components/Info.jsx b/frontend/src/components/Info.jsx new file mode 100644 index 0000000..9cdc3b5 --- /dev/null +++ b/frontend/src/components/Info.jsx @@ -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 && ( +
+

+ Welcome! + {' '} + In order to use this tool you'll need to have already created (if it's + still "Under Review", that's ok) your Modrinth Page, and a few other things: + +

    +
  • + A + {' '} + + GitHub Personal Access Token + + {' '} + 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). +
  • +
  • + The CurseForge Slug for your Mod. This can be found in the General Settings for your + project page +
  • +
  • + The Modrinth Project ID. This can be found in the side panel of your Modrinth project +
  • +
+ + This tool works on a queue-based system since I cannot afford enough computing for everyone, + so you'll be able to see your status and place in the queue down below in the + "Status & Output Log". 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! +

+ + {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} + [Hide] +
+ ); +}; diff --git a/frontend/src/components/OutputLog.jsx b/frontend/src/components/OutputLog.jsx new file mode 100644 index 0000000..a8f9748 --- /dev/null +++ b/frontend/src/components/OutputLog.jsx @@ -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 ({logs}); +}; diff --git a/frontend/src/index.js b/frontend/src/index.js new file mode 100644 index 0000000..42f131e --- /dev/null +++ b/frontend/src/index.js @@ -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()); diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx new file mode 100644 index 0000000..853e309 --- /dev/null +++ b/frontend/src/pages/Home.jsx @@ -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(( +
+

+ This is the splitter between parts of the filename. Geolosys uses format + {' '} + MODNAME-MCVER-MAJOR.MINOR.PATCH + , where + {' '} + - + {' '} + is the delimiter. +

+

+ Using this logic, it is assumed that the Minecraft version for this + {' '} + .jar + -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've got a bit of trauma + {' '} + (/s) + {' '} + from + {' '} + + this Regular Expression I wrote. + +

+
+ )); + }; + + 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 ( +
+

+ CurseForge to Modrinth Mod Migrator (CTMMM) +

+ + {!window.localStorage.getItem('info-dismissed') && ()} + + +
+ + GitHub Personal Access Token + setFormData({ + ...formData, + githubPat: x.target.value, + })} + /> + + This value is encrypted from end-to-end and even in storage + + + + + CurseForge Project Slug + setFormData({ + ...formData, + slug: x.target.value, + })} + /> + + + + Modrinth Project ID + setFormData({ + ...formData, + projId: x.target.value, + })} + /> + + + + + Delimiter (Optional) + {' '} + {/* eslint-disable-next-line jsx-a11y/anchor-is-valid */} + ❔ + + setFormData({ + ...formData, + delimiter: x.target.value, + })} + /> + + + +
+ + {jobId && ( + + + +
+ Status & Output Log for Job + {' '} + {`#${jobId}`} +
+
+ {jobId && ()} +
+
+ )} +
+ + setHelp(null)}> + {help} + +
+ ); +};