feat: Disattiva il pulsante indietro se si parte da uno step specifico

This commit is contained in:
Maicol Battistini 2023-07-19 16:55:40 +02:00
parent 4e31f90db9
commit f230f5954d
No known key found for this signature in database
2 changed files with 11 additions and 6 deletions

View File

@ -13,6 +13,7 @@ import {
RequestError
} from 'mithril-utilities';
import {match} from 'ts-pattern';
import {Class} from 'type-fest';
import {
SetupStep,
@ -27,6 +28,7 @@ export interface SetupPageAttributes extends PageAttributes<{
}
export default class SetupPage extends Page<SetupPageAttributes> {
initialStep = SetupSteps.Welcome;
currentStep = Stream<SetupSteps>(SetupSteps.Welcome);
steps: Record<SetupSteps, SetupStep<any>> = {
[SetupSteps.Welcome]: new WelcomeStep(),
@ -46,18 +48,20 @@ export default class SetupPage extends Page<SetupPageAttributes> {
.with('admin_user', () => SetupSteps.AdminUser)
.otherwise(() => SetupSteps.Welcome);
this.currentStep(setupStep);
this.initialStep = setupStep;
}
}
contents(vnode: Vnode<SetupPageAttributes>) {
// noinspection LocalVariableNamingConventionJS - Capitalized name is needed for JSX. Cast to unknown to avoid TS error about JSX element type
const Step = this.steps[this.currentStep()] as unknown as Class<SetupStep>;
return <>
<h1>{__('Configurazione iniziale')}</h1>
<div auto-animate>
{m(this.steps[this.currentStep()], {
...vnode.attrs.page.props,
onSaveInstall: this.onSaveInstall.bind(this),
onStepChange: (step: SetupSteps) => this.currentStep(step)
})}
<Step {...vnode.attrs.page.props}
disablePreviousButton={this.currentStep() === this.initialStep}
onSaveInstall={this.onSaveInstall.bind(this)}
onStepChange={this.currentStep.bind(this)}/>
</div>
</>;
}

View File

@ -24,6 +24,7 @@ export enum SetupSteps {
export interface SetupStepAttributes extends Attributes {
onStepChange: (step: SetupSteps) => void;
disablePreviousButton?: boolean;
}
export abstract class SetupStep<A extends SetupStepAttributes = SetupStepAttributes> extends Component<A> {
@ -55,7 +56,7 @@ export abstract class SetupStep<A extends SetupStepAttributes = SetupStepAttribu
}
isPreviousButtonEnabled(vnode: Vnode<A, this>): boolean {
return Boolean(this.previousStep);
return Boolean(this.previousStep) && !vnode.attrs.disablePreviousButton;
}
onPreviousButtonClicked(vnode: Vnode<A, this>): void {