diff --git a/src/components/features/task/view/BulkOperationsMenu.ts b/src/components/features/task/view/BulkOperationsMenu.ts index 9c6e6af4..38373af0 100644 --- a/src/components/features/task/view/BulkOperationsMenu.ts +++ b/src/components/features/task/view/BulkOperationsMenu.ts @@ -15,17 +15,18 @@ import type { UpdateTaskArgs } from "@/dataflow/api/WriteAPI"; import { BulkDatePickerModal } from "@/components/ui/date-picker/BulkDatePickerModal"; import { BulkDateOffsetModal } from "@/components/ui/date-picker/BulkDateOffsetModal"; import { addDays } from "date-fns"; +import { getCachedData } from "@/components/ui/inputs/AutoComplete"; /** * Create and show bulk operations menu */ -export function showBulkOperationsMenu( +export async function showBulkOperationsMenu( event: MouseEvent, app: App, plugin: TaskProgressBarPlugin, selectionManager: TaskSelectionManager, onOperationComplete: () => void, -): void { +): Promise { const menu = new Menu(); const selectedCount = selectionManager.getSelectedCount(); @@ -58,7 +59,7 @@ export function showBulkOperationsMenu( addBulkSetPriorityMenu(menu, plugin, selectionManager, onOperationComplete); // Bulk move to project - addBulkMoveToProjectMenu( + await addBulkMoveToProjectMenu( menu, plugin, selectionManager, @@ -337,20 +338,20 @@ function addBulkSetPriorityMenu( /** * Add bulk move to project submenu */ -function addBulkMoveToProjectMenu( +async function addBulkMoveToProjectMenu( menu: Menu, plugin: TaskProgressBarPlugin, selectionManager: TaskSelectionManager, onOperationComplete: () => void, -): void { +): Promise { + // Get all projects from cached data + const projects = await getProjectList(plugin); + menu.addItem((item) => { item.setIcon("folder"); item.setTitle(t("Bulk move to project")); const submenu = item.setSubmenu(); - // Get all projects from settings - const projects = getProjectList(plugin); - if (projects.length === 0) { submenu.addItem((subItem) => { subItem.setTitle(t("No projects available")); @@ -410,9 +411,11 @@ function addBulkDeleteMenu( new ConfirmModal(plugin, { title: t("Confirm bulk delete"), message: t( - "Are you sure you want to delete {count} tasks?", + "Are you sure you want to delete {{count}} tasks?", { - count: count.toString(), + interpolation: { + count: count.toString(), + }, }, ), confirmText: t("Delete"), @@ -902,34 +905,17 @@ function showOperationResult( } /** - * Get list of all projects from dataflow orchestrator + * Get list of all projects using cached data */ -function getProjectList(plugin: TaskProgressBarPlugin): string[] { - // Get projects from dataflow orchestrator - const projects = new Set(); - - // Try to access task data through dataflow orchestrator - if (plugin.dataflowOrchestrator) { - try { - // Access the taskStore from dataflow orchestrator - const taskStore = (plugin.dataflowOrchestrator as any).taskStore; - if (taskStore && taskStore.getAllTasks) { - const allTasks = taskStore.getAllTasks(); - for (const task of allTasks) { - if (task.metadata?.project) { - projects.add(task.metadata.project); - } - } - } - } catch (error) { - console.warn("Could not access tasks for project list:", error); - } - } - - // Fallback: Return common project names if no tasks found - if (projects.size === 0) { +async function getProjectList( + plugin: TaskProgressBarPlugin, +): Promise { + try { + // Load fresh data to ensure newly added projects appear + const cachedData = await getCachedData(plugin, true); + return cachedData.projects; + } catch (error) { + console.warn("Could not get projects from cached data:", error); return []; } - - return Array.from(projects).sort(); } diff --git a/src/components/features/task/view/listItem.ts b/src/components/features/task/view/listItem.ts index 1cc913bd..251abde9 100644 --- a/src/components/features/task/view/listItem.ts +++ b/src/components/features/task/view/listItem.ts @@ -198,7 +198,9 @@ export class TaskListItemComponent extends Component { // Refresh view after operation // The parent view should handle this via task updates }, - ); + ).catch((error) => { + console.error("Failed to show bulk operations menu:", error); + }); return; } diff --git a/src/components/features/task/view/treeItem.ts b/src/components/features/task/view/treeItem.ts index 40c30d4b..9eab4b77 100644 --- a/src/components/features/task/view/treeItem.ts +++ b/src/components/features/task/view/treeItem.ts @@ -209,7 +209,9 @@ export class TaskTreeItemComponent extends Component { () => { // Optionally refresh the view after bulk operation }, - ); + ).catch((error) => { + console.error("Failed to show bulk operations menu:", error); + }); return; } diff --git a/src/components/ui/inputs/AutoComplete.ts b/src/components/ui/inputs/AutoComplete.ts index e2d126cc..0f8b2c92 100644 --- a/src/components/ui/inputs/AutoComplete.ts +++ b/src/components/ui/inputs/AutoComplete.ts @@ -20,7 +20,7 @@ let globalCache: GlobalAutoCompleteCache | null = null; const CACHE_DURATION = 30000; // 30 seconds // Helper function to get cached data -async function getCachedData( +export async function getCachedData( plugin: TaskProgressBarPlugin, forceRefresh: boolean = false ): Promise { diff --git a/src/components/ui/modals/ConfirmModal.ts b/src/components/ui/modals/ConfirmModal.ts index e3484f5a..eb638ed5 100644 --- a/src/components/ui/modals/ConfirmModal.ts +++ b/src/components/ui/modals/ConfirmModal.ts @@ -42,18 +42,17 @@ export class ConfirmModal extends Modal { }); new ButtonComponent(buttonsContainer) - .setButtonText(this.params.confirmText) - .setCta() + .setButtonText(this.params.cancelText) .onClick(() => { - this.params.onConfirm(true); + this.params.onConfirm(false); this.close(); }); new ButtonComponent(buttonsContainer) - .setButtonText(this.params.cancelText) + .setButtonText(this.params.confirmText) .setCta() .onClick(() => { - this.params.onConfirm(false); + this.params.onConfirm(true); this.close(); }); }