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 <noreply@anthropic.com>
This commit is contained in:
Kgothatso Ngako
2026-07-26 03:03:10 +02:00
parent 5973ab1ca5
commit 5621493b98
2 changed files with 14 additions and 5 deletions

View File

@@ -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 = {

View File

@@ -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()
}