Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to delete task and device from GUI, missed the call to the server before #166

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 @@ -89,7 +89,9 @@ class MainActivity : ComponentActivity() {
navigateToLoginPage = { appState.navHostController.navigate(Page.LoginPage.route) },
)
}
composable(Page.DeviceOverview.route) { HomePage(overviewRepository = App.appModule.overviewRepo) }
composable(Page.DeviceOverview.route) {
HomePage(overviewRepository = App.appModule.overviewRepo, deviceRepository = App.appModule.deviceRepo)
}
composable(Page.CreateDevicePage.route) {
CreateDevicePage(
deviceRepository = App.appModule.deviceRepo,
Expand All @@ -99,7 +101,7 @@ class MainActivity : ComponentActivity() {
}
composable(
Page.TaskOverview.route,
) { TaskOverviewPage(overviewRepository = App.appModule.overviewRepo) }
) { TaskOverviewPage(overviewRepository = App.appModule.overviewRepo, taskRepository = App.appModule.taskRepo) }
composable(Page.CreateTaskPage.route) {
CreateTaskPage(
deviceRepository = App.appModule.deviceRepo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.runtime.toMutableStateList
Expand All @@ -50,11 +51,13 @@ import dk.scheduling.schedulingfrontend.components.Loading
import dk.scheduling.schedulingfrontend.model.DeviceOverview
import dk.scheduling.schedulingfrontend.model.DeviceState
import dk.scheduling.schedulingfrontend.model.getDeviceState
import dk.scheduling.schedulingfrontend.repositories.device.IDeviceRepository
import dk.scheduling.schedulingfrontend.repositories.overviews.IOverviewsRepository
import dk.scheduling.schedulingfrontend.repositories.overviews.OverviewRepository
import dk.scheduling.schedulingfrontend.ui.theme.SchedulingFrontendTheme
import dk.scheduling.schedulingfrontend.ui.theme.scheduled
import dk.scheduling.schedulingfrontend.ui.theme.success
import kotlinx.coroutines.launch
import testdata.DummyDeviceRepository
import testdata.DummyEventRepository
import testdata.DummyTaskRepository
Expand All @@ -64,15 +67,27 @@ import java.time.temporal.ChronoUnit
@Composable
fun HomePagePreviewLightMode() {
SchedulingFrontendTheme(darkTheme = false, dynamicColor = false) {
HomePage(overviewRepository = OverviewRepository(DummyDeviceRepository(0), DummyTaskRepository(0), DummyEventRepository(0)))
val dummyTaskRepo = DummyTaskRepository(0)
val dummyDeviceRepo = DummyDeviceRepository(0)
val dummyEventRepo = DummyEventRepository(0)
HomePage(
overviewRepository = OverviewRepository(dummyDeviceRepo, dummyTaskRepo, dummyEventRepo),
deviceRepository = dummyDeviceRepo,
)
}
}

@Preview(showBackground = false, device = "spec:id=reference_phone,shape=Normal,width=411,height=891,unit=dp,dpi=420")
@Composable
fun HomePagePreviewDarkMode() {
SchedulingFrontendTheme(darkTheme = true, dynamicColor = false) {
HomePage(overviewRepository = OverviewRepository(DummyDeviceRepository(0), DummyTaskRepository(0), DummyEventRepository(0)))
val dummyTaskRepo = DummyTaskRepository(0)
val dummyDeviceRepo = DummyDeviceRepository(0)
val dummyEventRepo = DummyEventRepository(0)
HomePage(
overviewRepository = OverviewRepository(dummyDeviceRepo, dummyTaskRepo, dummyEventRepo),
deviceRepository = dummyDeviceRepo,
)
}
}

Expand All @@ -81,6 +96,7 @@ fun HomePagePreviewDarkMode() {
fun HomePage(
modifier: Modifier = Modifier,
overviewRepository: IOverviewsRepository,
deviceRepository: IDeviceRepository,
) {
var devices by remember { mutableStateOf(mutableListOf<DeviceOverview>()) }
val refreshState = rememberPullToRefreshState()
Expand All @@ -105,10 +121,14 @@ fun HomePage(
.fillMaxSize(),
) {
items(devices) { deviceOverview ->
val coroutineScope = rememberCoroutineScope()
DeviceCard(
deviceOverview = deviceOverview,
onRemove = {
devices.remove(it)
coroutineScope.launch {
deviceRepository.deleteDevice(it.device.id)
devices.remove(it)
}
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.Alignment
Expand All @@ -54,7 +55,9 @@ import dk.scheduling.schedulingfrontend.model.DeviceTask
import dk.scheduling.schedulingfrontend.model.TaskEvent
import dk.scheduling.schedulingfrontend.repositories.overviews.IOverviewsRepository
import dk.scheduling.schedulingfrontend.repositories.overviews.OverviewRepository
import dk.scheduling.schedulingfrontend.repositories.task.ITaskRepository
import dk.scheduling.schedulingfrontend.ui.theme.SchedulingFrontendTheme
import kotlinx.coroutines.launch
import testdata.DummyDeviceRepository
import testdata.DummyEventRepository
import testdata.DummyTaskRepository
Expand All @@ -65,6 +68,7 @@ import java.time.LocalDateTime
fun TaskOverviewPage(
modifier: Modifier = Modifier,
overviewRepository: IOverviewsRepository,
taskRepository: ITaskRepository,
) {
var deviceTasks by remember { mutableStateOf(mutableListOf<DeviceTask>()) }
val refreshState = rememberPullToRefreshState()
Expand Down Expand Up @@ -92,7 +96,9 @@ fun TaskOverviewPage(
if (deviceTask.tasks.isNotEmpty()) {
DeviceTaskCard(
deviceTask = deviceTask,
) { deviceTasks.remove(deviceTask) }
onRemoveDeviceTask = { deviceTasks.remove(deviceTask) },
taskRepository = taskRepository,
)
}
}

Expand All @@ -113,6 +119,7 @@ fun TaskOverviewPage(
fun DeviceTaskCard(
deviceTask: DeviceTask,
onRemoveDeviceTask: () -> Unit,
taskRepository: ITaskRepository,
) {
val tasks = deviceTask.tasks.toMutableStateList()

Expand All @@ -129,11 +136,16 @@ fun DeviceTaskCard(
.fillMaxWidth()
.padding(8.dp),
)

val coroutineScope = rememberCoroutineScope()
tasks.forEach {
TaskViewer(
taskEvent = it,
) { tasks.remove(it) }
) {
coroutineScope.launch {
taskRepository.deleteTask(it.task.id)
tasks.remove(it)
}
}
}

if (tasks.isEmpty()) {
Expand Down Expand Up @@ -383,14 +395,26 @@ fun CancelTaskAlertDialog(
@Composable
fun TaskOverviewPagePreviewLightMode() {
SchedulingFrontendTheme(darkTheme = false, dynamicColor = false) {
TaskOverviewPage(overviewRepository = OverviewRepository(DummyDeviceRepository(0), DummyTaskRepository(0), DummyEventRepository(0)))
val dummyTaskRepo = DummyTaskRepository(0)
val dummyDeviceRepo = DummyDeviceRepository(0)
val dummyEventRepo = DummyEventRepository(0)
TaskOverviewPage(
overviewRepository = OverviewRepository(dummyDeviceRepo, dummyTaskRepo, dummyEventRepo),
taskRepository = dummyTaskRepo,
)
}
}

@Preview(showBackground = false, device = "spec:id=reference_phone,shape=Normal,width=411,height=891,unit=dp,dpi=420")
@Composable
fun TaskOverviewPagePreviewDarkMode() {
SchedulingFrontendTheme(darkTheme = true, dynamicColor = false) {
TaskOverviewPage(overviewRepository = OverviewRepository(DummyDeviceRepository(0), DummyTaskRepository(0), DummyEventRepository(0)))
val dummyTaskRepo = DummyTaskRepository(0)
val dummyDeviceRepo = DummyDeviceRepository(0)
val dummyEventRepo = DummyEventRepository(0)
TaskOverviewPage(
overviewRepository = OverviewRepository(dummyDeviceRepo, dummyTaskRepo, dummyEventRepo),
taskRepository = dummyTaskRepo,
)
}
}
Loading