@@ -17,6 +17,7 @@ import {showErrorToast} from '../modules/toast.ts';
1717import { initRepoIssueSidebar } from './repo-issue-sidebar.ts' ;
1818import { fomanticQuery } from '../modules/fomantic/base.ts' ;
1919import { ignoreAreYouSure } from '../vendor/jquery.are-you-sure.ts' ;
20+ import { registerGlobalInitFunc } from '../modules/observer.ts' ;
2021
2122const { appSubUrl} = window . config ;
2223
@@ -416,25 +417,20 @@ export function initRepoIssueWipNewTitle() {
416417
417418export function initRepoIssueWipToggle ( ) {
418419 // Toggle WIP for existing PR
419- queryElems ( document , '.toggle-wip ', ( el ) => el . addEventListener ( 'click' , async ( e ) => {
420+ registerGlobalInitFunc ( 'initPullRequestWipToggle ', ( toggleWip ) => toggleWip . addEventListener ( 'click' , async ( e ) => {
420421 e . preventDefault ( ) ;
421- const toggleWip = el ;
422422 const title = toggleWip . getAttribute ( 'data-title' ) ;
423423 const wipPrefix = toggleWip . getAttribute ( 'data-wip-prefix' ) ;
424424 const updateUrl = toggleWip . getAttribute ( 'data-update-url' ) ;
425425
426- try {
427- const params = new URLSearchParams ( ) ;
428- params . append ( 'title' , title ?. startsWith ( wipPrefix ) ? title . slice ( wipPrefix . length ) . trim ( ) : `${ wipPrefix . trim ( ) } ${ title } ` ) ;
429-
430- const response = await POST ( updateUrl , { data : params } ) ;
431- if ( ! response . ok ) {
432- throw new Error ( 'Failed to toggle WIP status' ) ;
433- }
434- window . location . reload ( ) ;
435- } catch ( error ) {
436- console . error ( error ) ;
426+ const params = new URLSearchParams ( ) ;
427+ params . append ( 'title' , title ?. startsWith ( wipPrefix ) ? title . slice ( wipPrefix . length ) . trim ( ) : `${ wipPrefix . trim ( ) } ${ title } ` ) ;
428+ const response = await POST ( updateUrl , { data : params } ) ;
429+ if ( ! response . ok ) {
430+ showErrorToast ( 'Failed to toggle WIP status' ) ;
431+ return ;
437432 }
433+ window . location . reload ( ) ;
438434 } ) ) ;
439435}
440436
0 commit comments