Phase 1 — Python (klausur-service): 5 monoliths → 36 files - dsfa_corpus_ingestion.py (1,828 LOC → 5 files) - cv_ocr_engines.py (2,102 LOC → 7 files) - cv_layout.py (3,653 LOC → 10 files) - vocab_worksheet_api.py (2,783 LOC → 8 files) - grid_build_core.py (1,958 LOC → 6 files) Phase 2 — Go (edu-search-service, school-service): 8 monoliths → 19 files - staff_crawler.go (1,402 → 4), policy/store.go (1,168 → 3) - policy_handlers.go (700 → 2), repository.go (684 → 2) - search.go (592 → 2), ai_extraction_handlers.go (554 → 2) - seed_data.go (591 → 2), grade_service.go (646 → 2) Phase 3 — TypeScript (admin-lehrer): 45 monoliths → 220+ files - sdk/types.ts (2,108 → 16 domain files) - ai/rag/page.tsx (2,686 → 14 files) - 22 page.tsx files split into _components/ + _hooks/ - 11 component files split into sub-components - 10 SDK data catalogs added to loc-exceptions - Deleted dead backup index_original.ts (4,899 LOC) All original public APIs preserved via re-export facades. Zero new errors: Python imports verified, Go builds clean, TypeScript tsc --noEmit shows only pre-existing errors. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
129 lines
3.8 KiB
TypeScript
129 lines
3.8 KiB
TypeScript
'use client'
|
|
|
|
import { useState, useEffect, useCallback, useMemo } from 'react'
|
|
import type { BacklogItem, BacklogProgress, CategoryProgress } from './types'
|
|
import { initialBacklogItems } from './data'
|
|
|
|
const STORAGE_KEY = 'backlogItems-v2'
|
|
|
|
export function useBacklog() {
|
|
const [items, setItems] = useState<BacklogItem[]>(initialBacklogItems)
|
|
const [selectedCategory, setSelectedCategory] = useState<string | null>(null)
|
|
const [selectedPriority, setSelectedPriority] = useState<string | null>(null)
|
|
const [expandedItems, setExpandedItems] = useState<Set<string>>(new Set())
|
|
const [searchQuery, setSearchQuery] = useState('')
|
|
|
|
// Load saved state from localStorage
|
|
useEffect(() => {
|
|
const saved = localStorage.getItem(STORAGE_KEY)
|
|
if (saved) {
|
|
try {
|
|
setItems(JSON.parse(saved))
|
|
} catch (e) {
|
|
console.error('Failed to load backlog items:', e)
|
|
}
|
|
}
|
|
}, [])
|
|
|
|
// Save state to localStorage
|
|
useEffect(() => {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(items))
|
|
}, [items])
|
|
|
|
const filteredItems = useMemo(() => {
|
|
return items.filter((item) => {
|
|
if (selectedCategory && item.category !== selectedCategory) return false
|
|
if (selectedPriority && item.priority !== selectedPriority) return false
|
|
if (searchQuery) {
|
|
const query = searchQuery.toLowerCase()
|
|
return (
|
|
item.title.toLowerCase().includes(query) ||
|
|
item.description.toLowerCase().includes(query) ||
|
|
item.subtasks?.some((st) => st.title.toLowerCase().includes(query))
|
|
)
|
|
}
|
|
return true
|
|
})
|
|
}, [items, selectedCategory, selectedPriority, searchQuery])
|
|
|
|
const toggleExpand = useCallback((id: string) => {
|
|
setExpandedItems((prev) => {
|
|
const next = new Set(prev)
|
|
if (next.has(id)) {
|
|
next.delete(id)
|
|
} else {
|
|
next.add(id)
|
|
}
|
|
return next
|
|
})
|
|
}, [])
|
|
|
|
const updateItemStatus = useCallback((id: string, status: BacklogItem['status']) => {
|
|
setItems((prev) => prev.map((item) => (item.id === id ? { ...item, status } : item)))
|
|
}, [])
|
|
|
|
const toggleSubtask = useCallback((itemId: string, subtaskId: string) => {
|
|
setItems((prev) =>
|
|
prev.map((item) => {
|
|
if (item.id !== itemId) return item
|
|
return {
|
|
...item,
|
|
subtasks: item.subtasks?.map((st) =>
|
|
st.id === subtaskId ? { ...st, completed: !st.completed } : st
|
|
),
|
|
}
|
|
})
|
|
)
|
|
}, [])
|
|
|
|
const progress: BacklogProgress = useMemo(() => {
|
|
const total = items.length
|
|
const completed = items.filter((i) => i.status === 'completed').length
|
|
return { total, completed, percentage: Math.round((completed / total) * 100) }
|
|
}, [items])
|
|
|
|
const getCategoryProgress = useCallback(
|
|
(categoryId: string): CategoryProgress => {
|
|
const categoryItems = items.filter((i) => i.category === categoryId)
|
|
const completed = categoryItems.filter((i) => i.status === 'completed').length
|
|
return { total: categoryItems.length, completed }
|
|
},
|
|
[items]
|
|
)
|
|
|
|
const resetToDefaults = useCallback(() => {
|
|
if (confirm('Backlog auf Standardwerte zuruecksetzen? Alle lokalen Aenderungen gehen verloren.')) {
|
|
setItems(initialBacklogItems)
|
|
localStorage.removeItem(STORAGE_KEY)
|
|
}
|
|
}, [])
|
|
|
|
const clearFilters = useCallback(() => {
|
|
setSelectedCategory(null)
|
|
setSelectedPriority(null)
|
|
setSearchQuery('')
|
|
}, [])
|
|
|
|
const hasActiveFilters = !!(selectedCategory || selectedPriority || searchQuery)
|
|
|
|
return {
|
|
items,
|
|
filteredItems,
|
|
selectedCategory,
|
|
setSelectedCategory,
|
|
selectedPriority,
|
|
setSelectedPriority,
|
|
expandedItems,
|
|
searchQuery,
|
|
setSearchQuery,
|
|
toggleExpand,
|
|
updateItemStatus,
|
|
toggleSubtask,
|
|
progress,
|
|
getCategoryProgress,
|
|
resetToDefaults,
|
|
clearFilters,
|
|
hasActiveFilters,
|
|
}
|
|
}
|