package com.example.aiapp import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue /** * The app's root screen, in the full-width panel [SidePanels] slides over a session from the left. * * Not a list of its own but [MainScreen] itself, and the whole width of the screen: what a right * swipe gets is the screen Back would have got, moved over the session instead of replacing it. The * session stays composed underneath, with its stream open and its draft and scroll position where * they were, so swiping the panel back off returns to it for nothing -- where Back and a tap costs * the whole transcript over the tunnel again. * * Tapping the session already open is that same swipe back rather than a fresh screen: reopening it * would hand [SessionScreen] a new summary for the conversation it is already showing. * * [onGone] is the one thing the list can do that this panel cannot survive -- deleting the very * session it is drawn over. There is nothing left to swipe back into, so that closes the screen. */ @Composable fun MainPanel( settings: ServerSettings, sessionId: String, active: Boolean, onOpen: (SessionSummary) -> Unit, onSpawn: () -> Unit, onImported: (SessionSummary) -> Unit, onSettings: () -> Unit, onProvider: (String, String) -> Unit, onClose: () -> Unit, onGone: () -> Unit, ) { // Asked again each time the panel opens: who is working and who is waiting on an answer is // exactly what changed while the session underneath was being read. var reloadToken by remember(sessionId) { mutableIntStateOf(0) } LaunchedEffect(active) { if (active) reloadToken++ } MainScreen( settings = settings, reloadToken = reloadToken, onOpen = { if (it.id == sessionId) onClose() else onOpen(it) }, onSpawn = onSpawn, onImported = onImported, onSettings = onSettings, onProvider = onProvider, onDeleted = { if (it == sessionId) onGone() }, ) }