feat: füge DraftStore und Speichern/Resume von Wizard-Status hinzu
Signed-off-by: StefanMoCoAt <stefan.mo.co@gmail.com>
This commit is contained in:
+1
-1
@@ -42,7 +42,7 @@ fun EventWizardScreen(
|
||||
if (state.currentStep == WizardStep.ZNS_CHECK) onBack() else viewModel.previousStep()
|
||||
},
|
||||
onNext = { viewModel.nextStep() },
|
||||
onSaveDraft = null, // Wird in einem Folge-Inkrement angebunden
|
||||
onSaveDraft = { viewModel.saveDraft() },
|
||||
onFinish = onFinish,
|
||||
onNavigateToVeranstalterNeu = onNavigateToVeranstalterNeu,
|
||||
renderStep = {
|
||||
|
||||
+52
-2
@@ -14,6 +14,7 @@ import at.mocode.frontend.core.domain.zns.ZnsImportProvider
|
||||
import at.mocode.frontend.core.domain.zns.ZnsRemoteVerein
|
||||
import at.mocode.frontend.core.navigation.AppScreen
|
||||
import at.mocode.frontend.core.network.NetworkConfig
|
||||
import at.mocode.frontend.core.wizard.draft.DraftStoreMemory
|
||||
import at.mocode.frontend.core.wizard.runtime.WizardContext
|
||||
import at.mocode.frontend.core.wizard.runtime.WizardState
|
||||
import at.mocode.frontend.core.wizard.samples.DemoEventAcc
|
||||
@@ -87,6 +88,8 @@ class EventWizardViewModel(
|
||||
|
||||
// --- Orchestrator-Integration (minimal, 2 Steps) ---
|
||||
private var wizardState: WizardState<DemoEventStep, DemoEventAcc>? = null
|
||||
private val draftFlowKey = "event_wizard_v1"
|
||||
private val draftFlowVersion = 1
|
||||
|
||||
init {
|
||||
checkZnsAvailability()
|
||||
@@ -100,8 +103,19 @@ class EventWizardViewModel(
|
||||
|
||||
// Initialisiere WizardRuntime-State (hinter Feature-Flag nutzbar)
|
||||
if (WizardFeatureFlags.WizardRuntimeEnabled) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
wizardState = WizardState(current = (DemoEventStep.ZnsCheck as DemoEventStep), acc = DemoEventAcc())
|
||||
// Resume Draft, falls vorhanden
|
||||
val draft = DraftStoreMemory.load(draftFlowKey)
|
||||
if (draft != null) {
|
||||
val step = parseWizardStep(draft.second)
|
||||
// Mappe auf Runtime-Step
|
||||
val runtimeStep = mapFromWizardStep(step)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
wizardState = WizardState(current = (runtimeStep as DemoEventStep), acc = DemoEventAcc())
|
||||
state = state.copy(currentStep = step)
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
wizardState = WizardState(current = (DemoEventStep.ZnsCheck as DemoEventStep), acc = DemoEventAcc())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,6 +206,7 @@ class EventWizardViewModel(
|
||||
val mapped = mapToWizardStep(next.current)
|
||||
if (mapped != null) {
|
||||
state = state.copy(currentStep = mapped)
|
||||
saveDraftInternal(mapped)
|
||||
return
|
||||
}
|
||||
// Fallback, sollte eigentlich nicht eintreten
|
||||
@@ -215,6 +230,7 @@ class EventWizardViewModel(
|
||||
val mapped = mapToWizardStep(prev.current)
|
||||
if (mapped != null) {
|
||||
state = state.copy(currentStep = mapped)
|
||||
saveDraftInternal(mapped)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -242,6 +258,16 @@ class EventWizardViewModel(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val initial = WizardState(current = (DemoEventStep.ZnsCheck as DemoEventStep), acc = DemoEventAcc())
|
||||
wizardState = initial
|
||||
// Beim ersten Zugriff auch evtl. gespeicherten Draft berücksichtigen
|
||||
DraftStoreMemory.load(draftFlowKey)?.let { (_, stepName) ->
|
||||
val parsed = parseWizardStep(stepName)
|
||||
val runtime = mapFromWizardStep(parsed)
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val resumed = initial.copy(current = (runtime as DemoEventStep))
|
||||
wizardState = resumed
|
||||
state = state.copy(currentStep = parsed)
|
||||
return resumed
|
||||
}
|
||||
return initial
|
||||
}
|
||||
|
||||
@@ -260,6 +286,30 @@ class EventWizardViewModel(
|
||||
DemoEventStep.MetaData -> WizardStep.META_DATA
|
||||
}
|
||||
|
||||
private fun mapFromWizardStep(step: WizardStep): DemoEventStep = when (step) {
|
||||
WizardStep.ZNS_CHECK -> DemoEventStep.ZnsCheck
|
||||
WizardStep.VERANSTALTER_SELECTION -> DemoEventStep.VeranstalterSelection
|
||||
WizardStep.ANSPRECHPERSON_MAPPING -> DemoEventStep.AnsprechpersonMapping
|
||||
WizardStep.META_DATA -> DemoEventStep.MetaData
|
||||
// Noch nicht im Runtime-Flow migriert: mappe konservativ auf letzten bekannten Schritt
|
||||
WizardStep.TURNIER_ANLAGE -> DemoEventStep.MetaData
|
||||
WizardStep.SUMMARY -> DemoEventStep.MetaData
|
||||
}
|
||||
|
||||
private fun parseWizardStep(name: String): WizardStep = try {
|
||||
WizardStep.valueOf(name)
|
||||
} catch (_: Exception) {
|
||||
WizardStep.ZNS_CHECK
|
||||
}
|
||||
|
||||
private fun saveDraftInternal(step: WizardStep) {
|
||||
DraftStoreMemory.save(draftFlowKey, draftFlowVersion, step.name)
|
||||
}
|
||||
|
||||
fun saveDraft() {
|
||||
saveDraftInternal(state.currentStep)
|
||||
}
|
||||
|
||||
fun setVeranstalter(id: Uuid, nummer: String, name: String, standardOrt: String, logo: String?) {
|
||||
state = state.copy(
|
||||
veranstalterId = id,
|
||||
|
||||
Reference in New Issue
Block a user