Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat remove extra settings when setup #328

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
required login only when setup
an-lee committed Feb 19, 2024
commit 5994c7ff0862ebf0c2d8aa30ba31e8e89dedcb49
105 changes: 10 additions & 95 deletions enjoy/src/renderer/pages/landing.tsx
Original file line number Diff line number Diff line change
@@ -1,115 +1,30 @@
import { t } from "i18next";
import { useState, useContext, useEffect } from "react";
import { Button, Progress } from "@renderer/components/ui";
import { useContext } from "react";
import { Button } from "@renderer/components/ui";
import { Link } from "react-router-dom";
import { LoginForm, ChooseLibraryPathInput } from "@renderer/components";
import {
AppSettingsProviderContext,
AISettingsProviderContext,
} from "@renderer/context";
import { CheckCircle2Icon } from "lucide-react";
import { LoginForm } from "@renderer/components";
import { AppSettingsProviderContext } from "@renderer/context";

export default () => {
const [currentStep, setCurrentStep] = useState<number>(1);
const [currentStepValid, setCurrentStepValid] = useState<boolean>(false);

const { user, libraryPath, initialized } = useContext(
AppSettingsProviderContext
);
const { whisperConfig } = useContext(AISettingsProviderContext);
const totalSteps = 3;

useEffect(() => {
validateCurrentStep();
}, [currentStep, user, whisperConfig]);

const validateCurrentStep = async () => {
switch (currentStep) {
case 1:
setCurrentStepValid(!!user);
break;
case 2:
setCurrentStepValid(!!libraryPath);
break;
case 3:
setCurrentStepValid(initialized);
break;
default:
setCurrentStepValid(false);
}
};

const nextStep = () => {
if (currentStepValid && currentStep < totalSteps) {
setCurrentStep(currentStep + 1);
}
};

const prevStep = () => {
if (currentStep > 1) {
setCurrentStep(currentStep - 1);
}
};

const stepTitles: any = {
1: {
title: t("login"),
subtitle: t("loginBeforeYouStart"),
},
2: {
title: t("libraryPath"),
subtitle: t("whereYourResourcesAreStored"),
},
3: {
title: t("finish"),
subtitle: t("youAreReadyToGo"),
},
};
const { initialized } = useContext(AppSettingsProviderContext);

return (
<div className="h-screen w-full px-4 py-6 lg:px-8 flex flex-col">
<div className="text-center">
<div className="text-lg font-mono py-6">
{t("nthStep", { current: currentStep, totalSteps })}:{" "}
{stepTitles[currentStep].title}
</div>
<div className="text-sm opacity-70">
{stepTitles[currentStep].subtitle}
</div>
<div className="text-lg font-mono py-6">{t("login")}</div>
<div className="text-sm opacity-70">{t("loginBeforeYouStart")}</div>
</div>
<div className="flex-1 flex justify-center items-center">
{currentStep == 1 && <LoginForm />}
{currentStep == 2 && <ChooseLibraryPathInput />}
{currentStep == 3 && (
<div className="flex justify-center items-center">
<CheckCircle2Icon className="text-green-500 w-24 h-24" />
</div>
)}
<LoginForm />
</div>
<div className="mt-auto">
<div className="flex mb-4 justify-end space-x-4">
{currentStep > 1 && (
<Button className="w-24" variant="ghost" onClick={prevStep}>
{t("previousStep")}
</Button>
)}
{totalSteps == currentStep ? (
{initialized && (
<Link to="/" replace>
<Button className="w-24">{t("finish")}</Button>
<Button className="w-24">{t("startToUse")}</Button>
</Link>
) : (
<Button
disabled={!currentStepValid}
className="w-24"
onClick={nextStep}
>
{t("nextStep")}
</Button>
)}
</div>
<div className="mb-4">
<Progress value={(currentStep / totalSteps) * 100} />
</div>
</div>
</div>
);