Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-sneh-s committed Jan 10, 2025
1 parent 944cb97 commit 597da56
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,22 @@ private fun SpaceProfileContent() {
cursorBrush = SolidColor(AppTheme.colorScheme.primary)
)
if (state.allowSave) {
Icon(
imageVector = Icons.Default.Check,
contentDescription = "",
tint = outlineColor,
modifier = Modifier
.padding(horizontal = 8.dp)
.clickable {
viewModel.saveSpace()
focusManager.clearFocus()
}
)
if (state.isNameChanging) {
CircularProgressIndicator(modifier = Modifier.size(20.dp))
} else {
Icon(
imageVector = Icons.Default.Check,
contentDescription = "",
tint = outlineColor,
modifier = Modifier
.padding(horizontal = 8.dp)
.clickable {
ripple(true)
viewModel.saveSpace()
focusManager.clearFocus()
}
)
}
}
}

Expand Down Expand Up @@ -347,22 +352,23 @@ private fun SpaceProfileContent() {

Header(title = stringResource(id = R.string.space_setting_title_your_location))

state.spaceInfo?.members?.firstOrNull { it.user.id == state.currentUserId }?.let { user ->
UserItem(
userInfo = user,
isChecked = state.locationEnabled,
enable = true,
isAdmin = state.isAdmin,
currentUser = state.currentUserId!!,
isAdminUser = state.spaceInfo?.space?.admin_id == user.user.id,
onCheckedChange = { isChecked ->
viewModel.onLocationEnabledChanged(isChecked)
},
onMemberRemove = {
viewModel.showRemoveMemberConfirmationWithId(true, "")
}
)
}
state.spaceInfo?.members?.firstOrNull { it.user.id == state.currentUserId }
?.let { user ->
UserItem(
userInfo = user,
isChecked = state.locationEnabled,
enable = true,
isAdmin = state.isAdmin,
currentUser = state.currentUserId!!,
isAdminUser = state.spaceInfo?.space?.admin_id == user.user.id,
onCheckedChange = { isChecked ->
viewModel.onLocationEnabledChanged(isChecked)
},
onMemberRemove = {
viewModel.showRemoveMemberConfirmationWithId(true, "")
}
)
}

HorizontalDivider(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,17 @@ class SpaceProfileViewModel @Inject constructor(
fun updateMemberLocation(memberId: String, enableLocation: Boolean) {
viewModelScope.launch(appDispatcher.IO) {
try {
_state.emit(_state.value.copy(userLocationUpdatingId = memberId))
spaceRepository.enableLocation(spaceID, memberId, enableLocation)
val spaceInfo = spaceRepository.getSpaceInfo(spaceID)
_state.emit(
_state.value.copy(
spaceInfo = spaceInfo,
locationEnabledChanges = _state.value.locationEnabledChanges + (memberId to enableLocation),
userLocationUpdatingId = null
locationEnabledChanges = _state.value.locationEnabledChanges + (memberId to enableLocation)
)
)
} catch (e: Exception) {
Timber.e(e, "Failed to update member location")
_state.emit(
_state.value.copy(
error = e,
userLocationUpdatingId = null
)
)
_state.emit(_state.value.copy(error = e))
}
}
}
Expand Down Expand Up @@ -185,6 +178,7 @@ class SpaceProfileViewModel @Inject constructor(
try {
_state.emit(_state.value.copy(saving = true))
if (isNameUpdated) {
_state.emit(_state.value.copy(isNameChanging = true))
spaceRepository.updateSpace(
space.copy(name = _state.value.spaceName?.trim() ?: "")
)
Expand All @@ -197,10 +191,10 @@ class SpaceProfileViewModel @Inject constructor(
)
}
val spaceInfo = spaceRepository.getSpaceInfo(spaceID)
_state.emit(_state.value.copy(saving = false, allowSave = false, spaceInfo = spaceInfo))
_state.emit(_state.value.copy(saving = false, allowSave = false, spaceInfo = spaceInfo, isNameChanging = false))
} catch (e: Exception) {
Timber.e(e, "Failed to save space")
_state.emit(_state.value.copy(saving = false, error = e, allowSave = false))
_state.emit(_state.value.copy(saving = false, error = e, allowSave = false, isNameChanging = false))
}
}

Expand Down Expand Up @@ -344,5 +338,5 @@ data class SpaceProfileState(
val isCodeLoading: Boolean = false,
val locationEnabledChanges: Map<String, Boolean> = emptyMap(),
val isLocationSettingChange: Boolean = false,
val userLocationUpdatingId: String? = null
val isNameChanging: Boolean = false
)

0 comments on commit 597da56

Please sign in to comment.