feat: ✨ Disattiva il pulsante indietro se si parte da uno step specifico
This commit is contained in:
parent
4e31f90db9
commit
f230f5954d
|
@ -13,6 +13,7 @@ import {
|
||||||
RequestError
|
RequestError
|
||||||
} from 'mithril-utilities';
|
} from 'mithril-utilities';
|
||||||
import {match} from 'ts-pattern';
|
import {match} from 'ts-pattern';
|
||||||
|
import {Class} from 'type-fest';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
SetupStep,
|
SetupStep,
|
||||||
|
@ -27,6 +28,7 @@ export interface SetupPageAttributes extends PageAttributes<{
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class SetupPage extends Page<SetupPageAttributes> {
|
export default class SetupPage extends Page<SetupPageAttributes> {
|
||||||
|
initialStep = SetupSteps.Welcome;
|
||||||
currentStep = Stream<SetupSteps>(SetupSteps.Welcome);
|
currentStep = Stream<SetupSteps>(SetupSteps.Welcome);
|
||||||
steps: Record<SetupSteps, SetupStep<any>> = {
|
steps: Record<SetupSteps, SetupStep<any>> = {
|
||||||
[SetupSteps.Welcome]: new WelcomeStep(),
|
[SetupSteps.Welcome]: new WelcomeStep(),
|
||||||
|
@ -46,18 +48,20 @@ export default class SetupPage extends Page<SetupPageAttributes> {
|
||||||
.with('admin_user', () => SetupSteps.AdminUser)
|
.with('admin_user', () => SetupSteps.AdminUser)
|
||||||
.otherwise(() => SetupSteps.Welcome);
|
.otherwise(() => SetupSteps.Welcome);
|
||||||
this.currentStep(setupStep);
|
this.currentStep(setupStep);
|
||||||
|
this.initialStep = setupStep;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contents(vnode: Vnode<SetupPageAttributes>) {
|
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 <>
|
return <>
|
||||||
<h1>{__('Configurazione iniziale')}</h1>
|
<h1>{__('Configurazione iniziale')}</h1>
|
||||||
<div auto-animate>
|
<div auto-animate>
|
||||||
{m(this.steps[this.currentStep()], {
|
<Step {...vnode.attrs.page.props}
|
||||||
...vnode.attrs.page.props,
|
disablePreviousButton={this.currentStep() === this.initialStep}
|
||||||
onSaveInstall: this.onSaveInstall.bind(this),
|
onSaveInstall={this.onSaveInstall.bind(this)}
|
||||||
onStepChange: (step: SetupSteps) => this.currentStep(step)
|
onStepChange={this.currentStep.bind(this)}/>
|
||||||
})}
|
|
||||||
</div>
|
</div>
|
||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ export enum SetupSteps {
|
||||||
|
|
||||||
export interface SetupStepAttributes extends Attributes {
|
export interface SetupStepAttributes extends Attributes {
|
||||||
onStepChange: (step: SetupSteps) => void;
|
onStepChange: (step: SetupSteps) => void;
|
||||||
|
disablePreviousButton?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class SetupStep<A extends SetupStepAttributes = SetupStepAttributes> extends Component<A> {
|
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 {
|
isPreviousButtonEnabled(vnode: Vnode<A, this>): boolean {
|
||||||
return Boolean(this.previousStep);
|
return Boolean(this.previousStep) && !vnode.attrs.disablePreviousButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
onPreviousButtonClicked(vnode: Vnode<A, this>): void {
|
onPreviousButtonClicked(vnode: Vnode<A, this>): void {
|
||||||
|
|
Loading…
Reference in New Issue