@@ -6,7 +6,7 @@ import {fomanticQuery} from '../modules/fomantic/base.ts';
66function updateIssueCount ( card : HTMLElement ) : void {
77 const parent = card . parentElement ;
88 const cnt = parent . querySelectorAll ( '.issue-card' ) . length ;
9- parent . querySelectorAll ( '.project-column-issue-count' ) [ 0 ] . textContent = String ( cnt ) ;
9+ parent . querySelector ( '.project-column-issue-count' ) . textContent = String ( cnt ) ;
1010}
1111
1212async function createNewColumn ( url : string , columnTitleInput : HTMLInputElement , projectColorInput : HTMLInputElement ) : Promise < void > {
@@ -48,11 +48,8 @@ async function moveIssue({item, from, to, oldIndex}: {item: HTMLElement, from: H
4848}
4949
5050async function initRepoProjectSortable ( ) : Promise < void > {
51- const els = document . querySelectorAll ( '#project-board > .board.sortable' ) ;
52- if ( ! els . length ) return ;
53-
5451 // the HTML layout is: #project-board > .board > .project-column .cards > .issue-card
55- const mainBoard = els [ 0 ] ;
52+ const mainBoard = document . querySelector ( '#project-board > .board.sortable' ) ;
5653 let boardColumns = mainBoard . querySelectorAll < HTMLDivElement > ( '.project-column' ) ;
5754 createSortable ( mainBoard , {
5855 group : 'project-column' ,
@@ -93,32 +90,30 @@ async function initRepoProjectSortable(): Promise<void> {
9390}
9491
9592export function initRepoProject ( ) : void {
96- if ( ! document . querySelector ( '.repository.projects' ) ) {
97- return ;
98- }
93+ if ( ! document . querySelector ( '#project-board[data-project-borad-writable="true"]' ) ) return ;
9994
10095 initRepoProjectSortable ( ) ; // no await
10196
10297 for ( const modal of document . querySelectorAll < HTMLDivElement > ( '.edit-project-column-modal' ) ) {
10398 const projectHeader = modal . closest < HTMLElement > ( '.project-column-header' ) ;
104- const projectTitleLabel = projectHeader ? .querySelector < HTMLElement > ( '.project-column-title-label' ) ;
99+ const projectTitleLabel = projectHeader . querySelector < HTMLElement > ( '.project-column-title-label' ) ;
105100 const projectTitleInput = modal . querySelector < HTMLInputElement > ( '.project-column-title-input' ) ;
106101 const projectColorInput = modal . querySelector < HTMLInputElement > ( '#new_project_column_color' ) ;
107102 const boardColumn = modal . closest < HTMLElement > ( '.project-column' ) ;
108- modal . querySelector ( '.edit-project-column-button' ) ? .addEventListener ( 'click' , async function ( e ) {
103+ modal . querySelector ( '.edit-project-column-button' ) . addEventListener ( 'click' , async function ( e ) {
109104 e . preventDefault ( ) ;
110105 try {
111106 await PUT ( this . getAttribute ( 'data-url' ) , {
112107 data : {
113- title : projectTitleInput ? .value ,
114- color : projectColorInput ? .value ,
108+ title : projectTitleInput . value ,
109+ color : projectColorInput . value ,
115110 } ,
116111 } ) ;
117112 } catch ( error ) {
118113 console . error ( error ) ;
119114 } finally {
120- projectTitleLabel . textContent = projectTitleInput ? .value ;
121- projectTitleInput . closest ( 'form' ) ? .classList . remove ( 'dirty' ) ;
115+ projectTitleLabel . textContent = projectTitleInput . value ;
116+ projectTitleInput . closest ( 'form' ) . classList . remove ( 'dirty' ) ;
122117 const dividers = boardColumn . querySelectorAll < HTMLElement > ( ':scope > .divider' ) ;
123118 if ( projectColorInput . value ) {
124119 const color = contrastColor ( projectColorInput . value ) ;
@@ -157,7 +152,7 @@ export function initRepoProject(): void {
157152
158153 for ( const btn of document . querySelectorAll ( '.show-delete-project-column-modal' ) ) {
159154 const okBtn = document . querySelector ( `${ btn . getAttribute ( 'data-modal' ) } .actions .ok.button` ) ;
160- okBtn ? .addEventListener ( 'click' , async ( e : MouseEvent ) => {
155+ okBtn . addEventListener ( 'click' , async ( e : MouseEvent ) => {
161156 e . preventDefault ( ) ;
162157 try {
163158 await DELETE ( btn . getAttribute ( 'data-url' ) ) ;
@@ -169,7 +164,7 @@ export function initRepoProject(): void {
169164 } ) ;
170165 }
171166
172- document . querySelector ( '#new_project_column_submit' ) ? .addEventListener ( 'click' , async ( e : MouseEvent & { target : HTMLButtonElement } ) => {
167+ document . querySelector ( '#new_project_column_submit' ) . addEventListener ( 'click' , async ( e : MouseEvent & { target : HTMLButtonElement } ) => {
173168 e . preventDefault ( ) ;
174169 const columnTitleInput = document . querySelector < HTMLInputElement > ( '#new_project_column' ) ;
175170 const projectColorInput = document . querySelector < HTMLInputElement > ( '#new_project_column_color_picker' ) ;
0 commit comments