From 9f0686a09ec554c68770dc8aa23f18a8163ce44e Mon Sep 17 00:00:00 2001 From: Jan Naahs Date: Sun, 20 Sep 2020 20:07:15 +0200 Subject: [PATCH] wip --- package.json | 1 + ui/App/components/Button.jsx | 10 +-- ui/App/components/Input.jsx | 3 +- ui/App/components/Select.jsx | 4 +- ui/App/views/Mods/Mods.jsx | 34 +++++++-- .../views/Mods/components/AddMod/AddMod.jsx | 4 +- .../AddMod/components/AddModForm.jsx | 76 +++++++++++++++---- ui/App/views/Mods/components/LoadMods.jsx | 23 +++--- ui/App/views/Mods/components/UploadMod.jsx | 22 ++++-- .../views/Saves/components/CreateSaveForm.jsx | 35 +++++---- ui/api/resources/mods.js | 12 ++- ui/api/resources/saves.js | 6 ++ 12 files changed, 164 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index a423e77..656897b 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,7 @@ "@fortawesome/free-solid-svg-icons": "^5.14.0", "@fortawesome/react-fontawesome": "^0.1.11", "axios": "^0.19.2", + "fuse.js": "^6.4.1", "react-hook-form": "^5.7.2", "regenerator-runtime": "^0.13.7", "semver": "^6.1.1", diff --git a/ui/App/components/Button.jsx b/ui/App/components/Button.jsx index fe823e4..bdb969d 100644 --- a/ui/App/components/Button.jsx +++ b/ui/App/components/Button.jsx @@ -1,19 +1,19 @@ import React from "react"; -const Button = ({ children, type, onClick, isSubmit, className, size }) => { +const Button = ({ children, type, onClick, isSubmit, className, size, isDisabled = false }) => { let color = ''; let padding = ''; switch (type) { case 'success': - color = 'bg-green hover:glow-green hover:bg-green-light'; + color = `bg-green ${isDisabled ? null : "hover:glow-green hover:bg-green-light" }`; break; case 'danger': - color = 'bg-red hover:glow-red hover:bg-red-light'; + color = `bg-red ${isDisabled ? null : "hover:glow-red hover:bg-red-light"}`; break; default: - color = 'bg-gray-light hover:glow-orange hover:bg-orange' + color = `bg-gray-light ${isDisabled ? null : "hover:glow-orange hover:bg-orange"}` } switch (size) { @@ -25,7 +25,7 @@ const Button = ({ children, type, onClick, isSubmit, className, size }) => { } return ( - diff --git a/ui/App/components/Input.jsx b/ui/App/components/Input.jsx index e6256dc..4b7cf26 100644 --- a/ui/App/components/Input.jsx +++ b/ui/App/components/Input.jsx @@ -1,6 +1,6 @@ import React from "react"; -const Input = ({name, inputRef, placeholder = null, type="text", defaultValue=null}) => { +const Input = ({name, inputRef, placeholder = null, type="text", defaultValue=null, hasAutoComplete=true}) => { return ( ) diff --git a/ui/App/components/Select.jsx b/ui/App/components/Select.jsx index 92c7c58..f1ad16a 100644 --- a/ui/App/components/Select.jsx +++ b/ui/App/components/Select.jsx @@ -1,8 +1,8 @@ import React from "react"; -const Select = ({name, inputRef, children}) => { +const Select = ({name, inputRef, children, className}) => { return ( -
+
+ { typeof fuse !== "undefined" + ? + :
+ Loading List of Mods from +
+ } + {suggestedMods.length > 0 && +
    + {suggestedMods.map((mod, index) =>
  • selectMod(mod)} key={index}>{mod.item.title}
  • )} +
+ }
- - + + + - -) + ) } export default AddModForm; \ No newline at end of file diff --git a/ui/App/views/Mods/components/LoadMods.jsx b/ui/App/views/Mods/components/LoadMods.jsx index 025ccae..16d20e3 100644 --- a/ui/App/views/Mods/components/LoadMods.jsx +++ b/ui/App/views/Mods/components/LoadMods.jsx @@ -4,28 +4,33 @@ import Select from "../../../components/Select"; import Label from "../../../components/Label"; import {useForm} from "react-hook-form"; import Button from "../../../components/Button"; +import modsResource from "../../../../api/resources/mods"; -const LoadMods = () => { +const LoadMods = ({refreshMods}) => { const [saves, setSaves] = useState([]); const {register, handleSubmit} = useForm(); useEffect(() => { (async () => { - const res = await savesResource.list() - if (res.success) { - setSaves(res.data); - } + setSaves(await savesResource.list()); })(); - }, []) + }, []); + + const loadMods = data => { + savesResource.mods(data.save) + .then(({mods}) => { + modsResource.portal.installMultiple(mods).then(refreshMods) + }) + } return ( -
+