This commit is contained in:
Athou
2025-05-23 15:57:53 +02:00
parent dc23126570
commit 2142e20e7d
9 changed files with 135 additions and 41 deletions

View File

@@ -1,9 +1,10 @@
import type { TreeCategory } from "app/tree/slice"
import { throttle } from "throttle-debounce"
import type { Category } from "./types"
export function visitCategoryTree(
category: Category,
visitor: (category: Category) => void,
category: TreeCategory,
visitor: (category: TreeCategory) => void,
options?: {
childrenFirst?: boolean
}
@@ -19,13 +20,13 @@ export function visitCategoryTree(
if (childrenFirst) visitor(category)
}
export function flattenCategoryTree(category: Category): Category[] {
export function flattenCategoryTree(category: TreeCategory): TreeCategory[] {
const categories: Category[] = []
visitCategoryTree(category, c => categories.push(c))
return categories
}
export function categoryUnreadCount(category?: Category): number {
export function categoryUnreadCount(category?: TreeCategory): number {
if (!category) return 0
return flattenCategoryTree(category)
@@ -34,6 +35,14 @@ export function categoryUnreadCount(category?: Category): number {
.reduce((total, current) => total + current, 0)
}
export function categoryHasNewEntries(category?: TreeCategory): boolean {
if (!category) return false
return flattenCategoryTree(category)
.flatMap(c => c.feeds)
.some(f => f.hasNewEntries)
}
export const calculatePlaceholderSize = ({ width, height, maxWidth }: { width?: number; height?: number; maxWidth: number }) => {
const placeholderWidth = width && Math.min(width, maxWidth)
const placeholderHeight = height && width && width > maxWidth ? height * (maxWidth / width) : height