package com.cottondb.android.ui.locations import androidx.compose.runtime.* import com.cottondb.android.LocationsModels import com.cottondb.android.navigation.Route import com.cottondb.android.ui.photos.PhotoLayout import java.time.Clock @Composable fun LocationsRoute(route: Route, models: LocationsModels, clock: Clock, dataRevision: Long, onBack: () -> Unit, onOpen: (Route) -> Unit) { if (route == Route.Locations) { val model = remember(models) { models.locations() } val state by model.state.collectAsState() LaunchedEffect(model, dataRevision) { model.refresh() } LaunchedEffect(model, state.createdId) { model.consumeCreated()?.let { onOpen(Route.LocationsLocation(it)) } } PhotoLayout("locations") { postcards, change -> LocationsScreen(state, if (postcards) LocationLayout.Postcards else LocationLayout.List, clock, clock.zone, { model.refresh() }, model::beginCreate, model::cancelCreate, model::editName, model::editAddress, { model.create() }, { onOpen(Route.LocationsLocation(it)) }, { change(it == LocationLayout.Postcards) }, onBack) } } else if (route is Route.LocationsLocation) { val model = remember(models, route) { models.detail(route) } val state by model.state.collectAsState() LaunchedEffect(model, dataRevision) { model.refresh() } DisposableEffect(model) { onDispose { model.pauseEditing() } } LaunchedEffect(model, state.archived) { if (model.consumeArchived()) onBack() } LocationDetailScreen(state, clock, clock.zone, LocationDetailCallbacks( { model.refresh() }, model::edit, { model.save(it) }, model::resolveConflict, { model.setPin(it) }, { project, linked -> model.setProject(project, linked) }, { model.archive() }, onBack, )) } }