From 269f0d9b784f15a061190a87eff950141f978bf2 Mon Sep 17 00:00:00 2001 From: LynithDev <61880709+LynithDev@users.noreply.github.com> Date: Sun, 15 Dec 2024 19:18:42 +0100 Subject: [PATCH] feat: Add forced login page to Onboarding --- apps/frontend/src/assets/logos/microsoft.svg | 6 ++ .../src/ui/pages/onboarding/Onboarding.tsx | 7 ++ .../pages/onboarding/OnboardingComplete.tsx | 9 +++ .../ui/pages/onboarding/OnboardingLogin.tsx | 69 +++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 apps/frontend/src/assets/logos/microsoft.svg create mode 100644 apps/frontend/src/ui/pages/onboarding/OnboardingLogin.tsx diff --git a/apps/frontend/src/assets/logos/microsoft.svg b/apps/frontend/src/assets/logos/microsoft.svg new file mode 100644 index 00000000..dc4e8c6e --- /dev/null +++ b/apps/frontend/src/assets/logos/microsoft.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/apps/frontend/src/ui/pages/onboarding/Onboarding.tsx b/apps/frontend/src/ui/pages/onboarding/Onboarding.tsx index 094c292e..2baf6bf3 100644 --- a/apps/frontend/src/ui/pages/onboarding/Onboarding.tsx +++ b/apps/frontend/src/ui/pages/onboarding/Onboarding.tsx @@ -10,6 +10,7 @@ import { type Accessor, type Context, createContext, createEffect, createSignal, import OnboardingComplete from './OnboardingComplete'; import OnboardingImport from './OnboardingImport'; import OnboardingLanguage, { type Language, LanguagesList } from './OnboardingLanguage'; +import OnboardingLogin from './OnboardingLogin'; import OnboardingSummary from './OnboardingSummary'; import OnboardingWelcome from './OnboardingWelcome'; @@ -18,6 +19,7 @@ const OnboardingSteps = [ ['/', OnboardingWelcome], ['/language', OnboardingLanguage], + ['/login', OnboardingLogin], ['/import', OnboardingImport], ['/summary', OnboardingSummary], // Second to last will always be the summary (which is basically a confirmation for all the tasks that are about to be done) @@ -45,6 +47,8 @@ interface OnboardingContextType { setImportInstances: (type: ImportType, basePath: string, instances: string[]) => void; importInstances: (type: ImportType) => ImportInstancesType | undefined; + setForwardButtonEnabled: (enabled: boolean) => void; + getTasks: () => string[]; tasksStage: Accessor; @@ -74,6 +78,7 @@ function Onboarding(props: ParentProps) { createEffect(on(() => location.pathname, () => { setBackButtonEnabled(step() > 0 && !tasksCompleted()); + setForwardButtonEnabled(step() < OnboardingSteps.length - 1 && !tasksCompleted()); })); useBeforeLeave((e) => { @@ -188,6 +193,8 @@ function Onboarding(props: ParentProps) { getTasks, + setForwardButtonEnabled, + tasksStage, tasksMessage, }; diff --git a/apps/frontend/src/ui/pages/onboarding/OnboardingComplete.tsx b/apps/frontend/src/ui/pages/onboarding/OnboardingComplete.tsx index f4d7f542..3080d34b 100644 --- a/apps/frontend/src/ui/pages/onboarding/OnboardingComplete.tsx +++ b/apps/frontend/src/ui/pages/onboarding/OnboardingComplete.tsx @@ -1,4 +1,13 @@ +import { onMount } from 'solid-js'; +import Onboarding from './Onboarding'; + function OnboardingComplete() { + const context = Onboarding.useContext(); + + onMount(() => { + context.setForwardButtonEnabled(true); + }); + return (

diff --git a/apps/frontend/src/ui/pages/onboarding/OnboardingLogin.tsx b/apps/frontend/src/ui/pages/onboarding/OnboardingLogin.tsx new file mode 100644 index 00000000..cd0acdc9 --- /dev/null +++ b/apps/frontend/src/ui/pages/onboarding/OnboardingLogin.tsx @@ -0,0 +1,69 @@ +import type { MinecraftCredentials } from '@onelauncher/client/bindings'; +import MicrosoftLogo from '~assets/logos/microsoft.svg?component-solid'; +import { bridge } from '~imports'; +import Button from '~ui/components/base/Button'; +import PlayerHead from '~ui/components/game/PlayerHead'; +import useAccountController from '~ui/components/overlay/account/AddAccountModal'; +import { createSignal, onMount, Show } from 'solid-js'; +import Onboarding from './Onboarding'; + +function OnboardingLogin() { + const context = Onboarding.useContext(); + const accountController = useAccountController(); + + const [errorMessage, setErrorMessage] = createSignal(''); + const [profile, setProfile] = createSignal(); + + onMount(() => { + context.setForwardButtonEnabled(false); + }); + + async function requestLogin() { + const result = await bridge.commands.authLogin(); + + if (result.status === 'error') { + setErrorMessage(result.error); + return; + } + + if (!result.data) { + setErrorMessage('No account was found. Please try again.'); + return; + } + + setProfile(result.data); + accountController.refetch(); + + context.setForwardButtonEnabled(true); + } + + return ( +
+

Login

+ +

Before you continue, we require you to own a copy of Minecraft: Java Edition.

+ + +
+ +
+

{profile()?.username}

+

{profile()?.id}

+
+
+
+ +
+ ); +} + +export default OnboardingLogin;