Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ interface ActionsNewParticipant : BaseAction {
}

data object Save : ActionsNewParticipant
data object DismissSuccess : ActionsNewParticipant
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MenuAnchorType
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TopAppBar
Expand Down Expand Up @@ -115,6 +118,18 @@ fun NewParicipant(
) {

val focusManager = LocalFocusManager.current
val snackbarHostState = remember { SnackbarHostState() }
val successMessage = (state as? ResultState.Success)?.data?.successMessage

LaunchedEffect(successMessage) {
if (successMessage != null) {
snackbarHostState.showSnackbar(
message = successMessage,
duration = SnackbarDuration.Short
)
onAction(ActionsNewParticipant.DismissSuccess)
}
}

AppTheme {
Scaffold(
Expand All @@ -123,6 +138,7 @@ fun NewParicipant(
.pointerInput(Unit) {
detectTapGestures(onTap = { focusManager.clearFocus() })
},
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
topBar = {
TopAppBar(title = {
Text(text = "Teilnehmende hinzufügen")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ data class NewParticipantState(
val isNewParticipant: Boolean = true,
val allergies: List<String> = emptyList(),
val selectedGroup: String = "",
val successMessage: String? = null,
)

class ViewModelNewParticipant(
Expand Down Expand Up @@ -57,6 +58,7 @@ class ViewModelNewParticipant(
)

is ActionsNewParticipant.DeleteParticipant -> deleteParticipant(actionsNewParticipant.participantId)
is ActionsNewParticipant.DismissSuccess -> dismissSuccess()
}
}

Expand Down Expand Up @@ -112,28 +114,39 @@ class ViewModelNewParticipant(
allergies = data.allergies
selectedGroup = data.selectedGroup
}
val name = "${data.firstName} ${data.lastName}"
val isNew = data.isNewParticipant
viewModelScope.launch {
try {
if (data.isNewParticipant) {
Logger.i("Create new Participant with name ${participant.firstName} ${participant.lastName}")
if (isNew) {
Logger.i("Create new Participant with name $name")
val success = eventRepository.createNewParticipant(participant)
if (success == null) {
_state.value =
ResultState.Error("Teilnehmer konnte nicht erstellt werden: Teilnehmer mit dem Namen existiert bereits")
return@launch
}
} else {
Logger.i("Update Participant with name ${participant.firstName} ${participant.lastName}")
Logger.i("Update Participant with name $name")
eventRepository.updateParticipant(participant)
}
} catch (e: Exception) {
Logger.e("" + e.message)
ResultState.Error("Fehler beim anlegen des Teilnehmenden")
_state.value = ResultState.Error("Fehler beim Anlegen des Teilnehmenden")
return@launch
}
initializeScreenWithNewParticipant()
val currentData = state.value.getSuccessData() ?: return@launch
val message = if (isNew) "$name wurde erstellt" else "$name wurde aktualisiert"
_state.value = ResultState.Success(currentData.copy(successMessage = message))
}
}

private fun dismissSuccess() {
val data = state.value.getSuccessData() ?: return
_state.value = ResultState.Success(data.copy(successMessage = null))
}

private fun initializeWithParticipant(participant: Participant) {
_state.value = ResultState.Success(
NewParticipantState(
Expand Down
2 changes: 1 addition & 1 deletion iosApp/Configuration/Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TEAM_ID=
BUNDLE_ID=org.futterbock.app.FutterbockApp
APP_NAME=Futterbock_App
APP_NAME=Futterbock
6 changes: 3 additions & 3 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
7555FF7B242A565900829871 /* Futterbock_App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Futterbock_App.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF7B242A565900829871 /* Futterbock.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Futterbock.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A2B2A19F2CB27F14005F4BA8 /* GoogleService-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -85,7 +85,7 @@
7555FF7C242A565900829871 /* Products */ = {
isa = PBXGroup;
children = (
7555FF7B242A565900829871 /* Futterbock_App.app */,
7555FF7B242A565900829871 /* Futterbock.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -134,7 +134,7 @@
A2D424BC2CEA1D250051BAF0 /* FirebaseFirestore */,
);
productName = iosApp;
productReference = 7555FF7B242A565900829871 /* Futterbock_App.app */;
productReference = 7555FF7B242A565900829871 /* Futterbock.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand Down
Loading