diff --git a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt index b730e48..8b50d87 100644 --- a/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt +++ b/app/src/main/java/eu/m724/vastapp/activity/dashboard/screen/Instances.kt @@ -20,14 +20,17 @@ import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight +import androidx.compose.material3.AlertDialog import androidx.compose.material3.Button import androidx.compose.material3.Card import androidx.compose.material3.Icon import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -101,9 +104,19 @@ fun RentedInstanceCard( deleteButtonClick: (RentedInstance) -> Unit, ) { val instance by remember(rentedInstance) { derivedStateOf { rentedInstance.instance } } - val label by remember(instance) { derivedStateOf { - rentedInstance.label ?: instance.machine.gpu.model - } } + + val dialogOpen = remember { mutableStateOf(false) } + + if (dialogOpen.value) { + InstanceDeleteDialog( + instance = rentedInstance, + onConfirm = { + dialogOpen.value = false + deleteButtonClick(rentedInstance) + }, + onClose = { dialogOpen.value = false } + ) + } Card(modifier = modifier) { Row( @@ -115,7 +128,7 @@ fun RentedInstanceCard( modifier = Modifier.fillMaxHeight(), verticalArrangement = Arrangement.SpaceEvenly // TODO I think the label is too low ) { - Text(label, fontSize = 22.sp) + Text(rentedInstance.getName(), fontSize = 22.sp) Text(rentedInstance.status, fontSize = 14.sp) } @@ -128,7 +141,7 @@ fun RentedInstanceCard( Button( modifier = Modifier.size(24.dp), contentPadding = PaddingValues(0.dp), - onClick = { deleteButtonClick(rentedInstance) }, + onClick = { dialogOpen.value = true }, ) { Icon( modifier = Modifier.size(16.dp), @@ -190,9 +203,30 @@ fun RentedInstanceCard( Spacer(modifier = Modifier.height(6.dp)) Icon( imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight, - contentDescription = "Details about instance $label" + contentDescription = "Details about instance ${rentedInstance.getName()}" ) } } } +} + + + +@Composable +fun InstanceDeleteDialog( + instance: RentedInstance, + onConfirm: () -> Unit, + onClose: () -> Unit, +) { + AlertDialog( + onDismissRequest = { onClose() }, + confirmButton = { + TextButton(onClick = { onConfirm() }) { Text("Confirm") } + }, + dismissButton = { + TextButton(onClick = { onClose() }) { Text("Dismiss") } + }, + title = { Text("Really delete instance?") }, + text = { Text("Instance #${instance.rentalId} (${instance.getName()})") }, + ) } \ No newline at end of file