Fix linked device list not refreshing after unlinking a device.

This commit is contained in:
Cody Henthorne
2026-08-11 14:19:28 -04:00
parent 5608e72171
commit 7de0955142
@@ -87,11 +87,13 @@ class LinkDeviceViewModel : ViewModel() {
val success = LinkDeviceRepository.removeDevice(device.id)
if (success) {
loadDevices()
_state.value = _state.value.copy(
oneTimeEvent = OneTimeEvent.ToastUnlinked(device.name ?: ""),
dialogState = DialogState.None,
deviceToRemove = null
)
_state.update {
it.copy(
oneTimeEvent = OneTimeEvent.ToastUnlinked(device.name ?: ""),
dialogState = DialogState.None,
deviceToRemove = null
)
}
} else {
_state.update {
it.copy(
@@ -104,24 +106,23 @@ class LinkDeviceViewModel : ViewModel() {
}
private fun loadDevices(initialLoad: Boolean = false) {
_state.value = _state.value.copy(
deviceListLoading = true
)
_state.update { it.copy(deviceListLoading = true) }
viewModelScope.launch(Dispatchers.IO) {
val devices = LinkDeviceRepository.loadDevices()
if (devices == null) {
_state.value = _state.value.copy(
oneTimeEvent = OneTimeEvent.ToastNetworkFailed,
deviceListLoading = false
)
_state.update {
it.copy(
oneTimeEvent = OneTimeEvent.ToastNetworkFailed,
deviceListLoading = false
)
}
} else {
if (initialLoad) {
checkForNewDevice(devices)
}
_state.update {
it.copy(
oneTimeEvent = OneTimeEvent.None,
devices = devices,
deviceListLoading = false
)
@@ -140,9 +141,7 @@ class LinkDeviceViewModel : ViewModel() {
delay(5.seconds)
val devices = LinkDeviceRepository.loadDevices()
if (devices != null) {
_state.value = _state.value.copy(
devices = devices
)
_state.update { it.copy(devices = devices) }
}
}
}