UI: locks user in alert dialog when model is unloading
This commit is contained in:
parent
6b341b0fbe
commit
e47e3b77ee
|
|
@ -293,21 +293,27 @@ fun AppContent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Model unload confirmation dialog
|
// Model unload confirmation dialog
|
||||||
// TODO-han.yin: show a progress indicator until the model success unloads?
|
var isUnloading by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
if (showUnloadDialog) {
|
if (showUnloadDialog) {
|
||||||
UnloadModelConfirmationDialog(
|
UnloadModelConfirmationDialog(
|
||||||
onConfirm = {
|
onConfirm = {
|
||||||
showUnloadDialog = false
|
isUnloading = true
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
viewModel.unloadModel()
|
viewModel.unloadModel()
|
||||||
|
isUnloading = false
|
||||||
|
showUnloadDialog = false
|
||||||
pendingNavigation?.invoke()
|
pendingNavigation?.invoke()
|
||||||
pendingNavigation = null
|
pendingNavigation = null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onDismiss = {
|
onDismiss = {
|
||||||
showUnloadDialog = false
|
if (!isUnloading) {
|
||||||
pendingNavigation = null
|
showUnloadDialog = false
|
||||||
}
|
pendingNavigation = null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isUnloading = isUnloading
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,21 @@
|
||||||
package com.example.llama.revamp.ui.components
|
package com.example.llama.revamp.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Confirmation dialog shown when the user attempts to navigate away from
|
* Confirmation dialog shown when the user attempts to navigate away from
|
||||||
|
|
@ -12,27 +24,55 @@ import androidx.compose.runtime.Composable
|
||||||
@Composable
|
@Composable
|
||||||
fun UnloadModelConfirmationDialog(
|
fun UnloadModelConfirmationDialog(
|
||||||
onConfirm: () -> Unit,
|
onConfirm: () -> Unit,
|
||||||
onDismiss: () -> Unit
|
onDismiss: () -> Unit,
|
||||||
|
isUnloading: Boolean = false
|
||||||
) {
|
) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = {
|
||||||
|
// Ignore dismiss requests while unloading the model
|
||||||
|
if (!isUnloading) onDismiss()
|
||||||
|
},
|
||||||
title = {
|
title = {
|
||||||
Text("Confirm Exit")
|
Text("Confirm Exit")
|
||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
Text(
|
Column {
|
||||||
"Going back will unload the current model. " +
|
Text(
|
||||||
"This operation cannot be undone. " +
|
"Going back will unload the current model. " +
|
||||||
"Any unsaved conversation will be lost."
|
"This operation cannot be undone. " +
|
||||||
)
|
"Any unsaved conversation will be lost."
|
||||||
|
)
|
||||||
|
|
||||||
|
if (isUnloading) {
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.Center,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(24.dp),
|
||||||
|
strokeWidth = 2.dp
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("Unloading model...")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton(onClick = onConfirm) {
|
TextButton(
|
||||||
|
onClick = onConfirm,
|
||||||
|
enabled = !isUnloading
|
||||||
|
) {
|
||||||
Text("Yes, Exit")
|
Text("Yes, Exit")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = onDismiss) {
|
TextButton(
|
||||||
|
onClick = onDismiss,
|
||||||
|
enabled = !isUnloading
|
||||||
|
) {
|
||||||
Text("Cancel")
|
Text("Cancel")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue