Work out home's sections and scoped search only once shown (#59)
This commit is contained in:
1 parent
3b1f89623e
commit
56f81d9c2e
1 file changed
+26
-12
@@ -127,19 +127,28 @@ sealed interface ListsUiState {
|
||||
val goneSources: Set<Long> = emptySet(),
|
||||
/** The view's scope names a list since deleted, so that part of it matches nothing. */
|
||||
val scopeListsGone: Boolean = false,
|
||||
/** The lists, tags and filters blocks within the view's scope. */
|
||||
val sections: HomeSections = HomeSections(emptyList(), emptyList(), emptyList()),
|
||||
/** The same for every task: a block that ignores the scope, and the lists and filters picker. */
|
||||
val unscopedSections: HomeSections = sections,
|
||||
/**
|
||||
* The lists, tags and filters blocks within the view's scope, worked out
|
||||
* only once a block shows them.
|
||||
*/
|
||||
private val scopedSections: Lazy<HomeSections> = lazyOf(HomeSections(emptyList(), emptyList(), emptyList())),
|
||||
/** The same for every task, for a block that ignores the scope and the pickers; also only once read. */
|
||||
private val everySection: Lazy<HomeSections> = scopedSections,
|
||||
/** The saved filters' names by id, which a filter source goes by. */
|
||||
val filterNames: Map<Long, String> = emptyMap(),
|
||||
/** Every list, whatever the scope: whether there are any, and the names sources show. */
|
||||
val lists: List<TaskList> = emptyList(),
|
||||
/** Every task (open and completed) — the corpus the home search filters. */
|
||||
val allTasks: List<Task> = emptyList(),
|
||||
/** [allTasks] within the view's scope, where a search in a scoped view starts. */
|
||||
val scopedTasks: List<Task> = allTasks,
|
||||
/** [allTasks] within the view's scope, where a search in a scoped view starts; filtered once searched. */
|
||||
private val scopedCorpus: Lazy<List<Task>> = lazyOf(allTasks),
|
||||
/** The list a new task goes to, so it shows in the view: the scope's one list, if it keeps tasks to one. */
|
||||
val newTaskList: Long? = null,
|
||||
) : ListsUiState {
|
||||
val sections: HomeSections get() = scopedSections.value
|
||||
val unscopedSections: HomeSections get() = everySection.value
|
||||
val scopedTasks: List<Task> get() = scopedCorpus.value
|
||||
|
||||
fun sectionsFor(block: Block): HomeSections = if (block.ignoreScope) unscopedSections else sections
|
||||
}
|
||||
}
|
||||
@@ -201,7 +210,7 @@ internal fun homeContent(
|
||||
}
|
||||
|
||||
val allTasks = openTasks + completedTasks
|
||||
val sections = homeSections(lists, openTasks, allTasks, filters, scope, clock)
|
||||
val every = lazy(LazyThreadSafetyMode.PUBLICATION) { homeSections(lists, openTasks, allTasks, filters, AppliedScope.None, clock) }
|
||||
return ListsUiState.Content(
|
||||
view = view,
|
||||
views = views,
|
||||
@@ -210,15 +219,20 @@ internal fun homeContent(
|
||||
previews = previews,
|
||||
goneSources = gone,
|
||||
scopeListsGone = scope.goneLists.isNotEmpty(),
|
||||
sections = sections,
|
||||
unscopedSections = if (scope == AppliedScope.None) {
|
||||
sections
|
||||
scopedSections = if (scope == AppliedScope.None) {
|
||||
every
|
||||
} else {
|
||||
homeSections(lists, openTasks, allTasks, filters, AppliedScope.None, clock)
|
||||
lazy(LazyThreadSafetyMode.PUBLICATION) { homeSections(lists, openTasks, allTasks, filters, scope, clock) }
|
||||
},
|
||||
everySection = every,
|
||||
filterNames = filters.associate { it.id to it.name },
|
||||
lists = lists,
|
||||
allTasks = allTasks,
|
||||
scopedTasks = if (scope == AppliedScope.None) allTasks else allTasks.filter { scope.admits(it, clock) },
|
||||
scopedCorpus = if (scope == AppliedScope.None) {
|
||||
lazyOf(allTasks)
|
||||
} else {
|
||||
lazy(LazyThreadSafetyMode.PUBLICATION) { allTasks.filter { scope.admits(it, clock) } }
|
||||
},
|
||||
newTaskList = scope.lists?.singleOrNull()?.takeIf { it in listIds },
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user