From fb03c411ad24e36b0ba2eb6c93bfe32447008f9a Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 2 Nov 2020 21:06:47 -0800 Subject: [PATCH] Get EULA hook modal into working order and start server when accepted --- .../server/features/eula/EulaModalFeature.tsx | 56 +++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/resources/scripts/components/server/features/eula/EulaModalFeature.tsx b/resources/scripts/components/server/features/eula/EulaModalFeature.tsx index 79e907d7f..d48eef1fa 100644 --- a/resources/scripts/components/server/features/eula/EulaModalFeature.tsx +++ b/resources/scripts/components/server/features/eula/EulaModalFeature.tsx @@ -2,10 +2,18 @@ import React, { useEffect, useState } from 'react'; import { ServerContext } from '@/state/server'; import Modal from '@/components/elements/Modal'; import tw from 'twin.macro'; +import Button from '@/components/elements/Button'; +import saveFileContents from '@/api/server/files/saveFileContents'; +import FlashMessageRender from '@/components/FlashMessageRender'; +import useFlash from '@/plugins/useFlash'; const EulaModalFeature = () => { const [ visible, setVisible ] = useState(false); + const [ loading, setLoading ] = useState(false); + + const uuid = ServerContext.useStoreState(state => state.server.data!.uuid); const status = ServerContext.useStoreState(state => state.status.value); + const { clearFlashes, clearAndAddHttpError } = useFlash(); const { connected, instance } = ServerContext.useStoreState(state => state.socket); useEffect(() => { @@ -24,16 +32,56 @@ const EulaModalFeature = () => { }; }, [ connected, instance, status ]); + const onAcceptEULA = () => { + setLoading(true); + clearFlashes('feature:eula'); + + saveFileContents(uuid, 'eula.txt', 'eula=true') + .then(() => { + if (status === 'offline' && instance) { + instance.send('set state', 'restart'); + } + + setLoading(false); + setVisible(false); + }) + .catch(error => { + console.error(error); + clearAndAddHttpError({ key: 'feature:eula', error }); + }) + .then(() => setLoading(false)); + }; + + useEffect(() => () => { + clearFlashes('feature:eula'); + }, []); + return ( !visible ? null : - setVisible(false)}> -

EULA Not Accepted

+ setVisible(false)} closeOnBackground={false} showSpinnerOverlay={loading}> + +

Accept Minecraft® EULA

- It looks like you have not yet accepted the Minecraft EULA. In order to start this server you - must set eula=true inside the eula.txt file in the File Manager. + By pressing {'"I Accept"'} below you are indicating your agreement to the  + + Mojang EULA + .

+
+ + +
); };