Cotton code
33 lines · 1.8 KB · KotlinRaw
package com.cottondb.android.ui.locationsimport androidx.compose.runtime.*import com.cottondb.android.LocationsModelsimport com.cottondb.android.navigation.Routeimport com.cottondb.android.ui.photos.PhotoLayoutimport java.time.Clock@Composablefun 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,        ))    }}