From 5621493b9812f513d98261c1dc3fb53330786153 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sun, 26 Jul 2026 03:03:10 +0200 Subject: [PATCH] Open the new artifact after adding it On a successful add-artifact, navigate to the artifact detail for the newly created artifact instead of the implementation-pending screen. The ViewModel now passes the created artifact's id (the returned inner event's id) to onSuccess, and the screen opens ArtifactDetailRoute via the pop-inclusive callback so the add form leaves the back stack. Co-Authored-By: Claude Opus 4.8 --- .../compose/ui/composable/AddArtifactScreen.kt | 14 +++++++++++--- .../compose/ui/view/model/AddArtifactViewModel.kt | 5 +++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/composable/AddArtifactScreen.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/composable/AddArtifactScreen.kt index 048be0d1..38d68b94 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/composable/AddArtifactScreen.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/composable/AddArtifactScreen.kt @@ -60,6 +60,7 @@ import press.mantra.compose.ui.theme.TorchTheme import press.mantra.compose.ui.view.state.ChatRoomMessagingUIState import com.vitorpamplona.quartz.nip01Core.core.HexKey import press.mantra.compose.repository.MantraRepository +import press.mantra.compose.ui.composable.navigation.routes.ArtifactDetailRoute import press.mantra.compose.ui.composable.navigation.routes.ImplementationPendingRoute import press.mantra.compose.ui.view.model.AddArtifactViewModel import press.mantra.compose.ui.view.state.AddArtifactUIState @@ -141,9 +142,16 @@ fun AddArtifactScreen( dialectNameField = dialectNameFieldState, dialectCountryField = dialectCountryFieldState, dialectLanguageField = dialectLanguageFieldState, - onSuccess = { - onNavigateToRoute.invoke( - ImplementationPendingRoute("Add Artifact") + onSuccess = { artifactId -> + // Open the newly created artifact, removing this + // add screen from the back stack. + onNavigateToRouteAndPopUpInclusive.invoke( + ArtifactDetailRoute( + activeUserPublicKey = activeUserPublicKey, + artifactId = artifactId, + chatRoomId = chatRoomId, + relayHint = relayHint + ) ) }, onFailure = { diff --git a/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/view/model/AddArtifactViewModel.kt b/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/view/model/AddArtifactViewModel.kt index f251f1df..47e88cea 100644 --- a/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/view/model/AddArtifactViewModel.kt +++ b/composeApp/src/commonMain/kotlin/press/mantra/compose/ui/view/model/AddArtifactViewModel.kt @@ -69,7 +69,7 @@ class AddArtifactViewModel( dialectLanguageField: TextFieldState, visibility: String = MantraRepository.DEFAULT_VISIBILITY, license: String = MantraRepository.DEFAULT_LICENSE, - onSuccess: () -> Unit, + onSuccess: (artifactId: String) -> Unit, onFailure: () -> Unit ) { val name = nameField.text.toString() @@ -130,7 +130,8 @@ class AddArtifactViewModel( dialectNameField.clearText() dialectCountryField.clearText() dialectLanguageField.clearText() - onSuccess.invoke() + // The created artifact's id is the returned inner event's id. + onSuccess.invoke(marmotInnerEvent.id) } else { onFailure.invoke() }