package com.sp365.calendar.components import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.remember import androidx.compose.runtime.snapshotFlow import com.sp365.calendar.model.EventNative import com.sp365.calendar.utils.* import java.time.LocalDate @Composable fun TaskList(currentDate: LocalDate, jobs: List, onDateChange: (LocalDate) -> Unit) { val listState = rememberLazyListState() val daysList = remember { generateDaysList(currentDate, yearsBefore = 10, yearsAfter = 10) } LaunchedEffect(currentDate) { val index = daysList.indexOf(currentDate) if (index != -1) { listState.scrollToItem(index) } } LaunchedEffect(listState) { snapshotFlow { listState.firstVisibleItemIndex } .collect { index -> val newDate = daysList.getOrNull(index) if (newDate != null && newDate != currentDate) { onDateChange(newDate) } } } LazyColumn(state = listState) { items(daysList.size) { index -> val date = daysList[index] DayTaskItem(date, jobs) } } }