1212import {
1313 TasksApi ,
1414 type CreateTaskParams ,
15+ type Task ,
1516 type TaskActionParams ,
1617} from "@repo/shared" ;
17- import { logger } from "@repo/webview-shared/logger" ;
1818import { useIpc } from "@repo/webview-shared/react" ;
1919
2020export function useTasksApi ( ) {
21- const { request, command } = useIpc ( ) ;
22-
23- function safeCommand < P > (
24- definition : { method : string ; _types ?: { params : P } } ,
25- ...args : P extends void ? [ ] : [ params : P ]
26- ) : void {
27- try {
28- command ( definition , ...args ) ;
29- } catch ( err ) {
30- logger . error ( `Command ${ definition . method } failed` , err ) ;
31- }
32- }
21+ const { request, command, onNotification } = useIpc ( ) ;
3322
3423 return {
3524 // Requests
@@ -53,8 +42,19 @@ export function useTasksApi() {
5342 request ( TasksApi . sendTaskMessage , { taskId, message } ) ,
5443
5544 // Commands
56- viewInCoder : ( taskId : string ) =>
57- safeCommand ( TasksApi . viewInCoder , { taskId } ) ,
58- viewLogs : ( taskId : string ) => safeCommand ( TasksApi . viewLogs , { taskId } ) ,
45+ viewInCoder : ( taskId : string ) => command ( TasksApi . viewInCoder , { taskId } ) ,
46+ viewLogs : ( taskId : string ) => command ( TasksApi . viewLogs , { taskId } ) ,
47+ closeWorkspaceLogs : ( ) => command ( TasksApi . closeWorkspaceLogs ) ,
48+
49+ // Notifications
50+ onTaskUpdated : ( cb : ( task : Task ) => void ) =>
51+ onNotification ( TasksApi . taskUpdated , cb ) ,
52+ onTasksUpdated : ( cb : ( tasks : Task [ ] ) => void ) =>
53+ onNotification ( TasksApi . tasksUpdated , cb ) ,
54+ onWorkspaceLogsAppend : ( cb : ( lines : string [ ] ) => void ) =>
55+ onNotification ( TasksApi . workspaceLogsAppend , cb ) ,
56+ onRefresh : ( cb : ( ) => void ) => onNotification ( TasksApi . refresh , cb ) ,
57+ onShowCreateForm : ( cb : ( ) => void ) =>
58+ onNotification ( TasksApi . showCreateForm , cb ) ,
5959 } ;
6060}
0 commit comments