37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
// #region ActivityStore [C:2] [TYPE Store] [SEMANTICS activity, store, derived, task-count, badge]
|
|
// @BRIEF Derived store that counts active running tasks for navbar indicator badge.
|
|
|
|
// #region activity:Store [TYPE Function]
|
|
// @PURPOSE: Track active task count for navbar indicator
|
|
// @LAYER UI
|
|
// @RELATION DEPENDS_ON -> [EXT:frontend:taskDrawer]
|
|
|
|
import { derived } from 'svelte/store';
|
|
import { taskDrawerStore } from './taskDrawer.js';
|
|
|
|
/**
|
|
* Derived store that counts active tasks
|
|
* @UX_STATE: Idle -> No active tasks, badge hidden
|
|
* @UX_STATE: Active -> Badge shows count of running tasks
|
|
*/
|
|
export const activityStore = derived(taskDrawerStore, ($drawer) => {
|
|
const activeCount = Object.values($drawer.resourceTaskMap)
|
|
.filter(t => t.status === 'RUNNING').length;
|
|
|
|
console.log(`[EXT:frontend:activityStore][State] Active count: ${activeCount}`);
|
|
|
|
return {
|
|
activeCount,
|
|
recentTasks: Object.entries($drawer.resourceTaskMap)
|
|
.map(([resourceId, taskInfo]) => ({
|
|
taskId: taskInfo.taskId,
|
|
resourceId,
|
|
status: taskInfo.status
|
|
}))
|
|
.slice(-5) // Last 5 tasks
|
|
};
|
|
});
|
|
|
|
// #endregion activity:Store
|
|
// #endregion ActivityStore
|