@@ -249,6 +249,10 @@ const DashboardApp = (() => {
249249 return api ( "POST" , "/api/rooms" , { name } ) ;
250250 }
251251
252+ async function apiRenameRoom ( roomId , name ) {
253+ return api ( "PATCH" , `/api/rooms/${ encodeURIComponent ( roomId ) } ` , { name } ) ;
254+ }
255+
252256 async function apiDeleteRoom ( roomId ) {
253257 const res = await fetch ( `/api/rooms/${ encodeURIComponent ( roomId ) } ` , { method : "DELETE" } ) ;
254258 if ( ! res . ok ) {
@@ -528,6 +532,7 @@ const DashboardApp = (() => {
528532 }
529533
530534 function showNewRoomForm ( ) {
535+ hideRenameRoomForm ( ) ;
531536 const form = document . getElementById ( "new-room-form" ) ;
532537 if ( form ) {
533538 form . classList . remove ( "new-room-form--hidden" ) ;
@@ -543,6 +548,43 @@ const DashboardApp = (() => {
543548 if ( input ) input . value = "" ;
544549 }
545550
551+ function showRenameRoomForm ( ) {
552+ hideNewRoomForm ( ) ;
553+ const form = document . getElementById ( "rename-room-form" ) ;
554+ if ( form ) {
555+ form . classList . remove ( "new-room-form--hidden" ) ;
556+ const input = document . getElementById ( "rename-room-name" ) ;
557+ if ( input ) {
558+ const current = rooms . find ( ( r ) => r . id === currentRoomId ) ;
559+ input . value = current ? current . name : "" ;
560+ input . focus ( ) ;
561+ input . select ( ) ;
562+ }
563+ }
564+ }
565+
566+ function hideRenameRoomForm ( ) {
567+ const form = document . getElementById ( "rename-room-form" ) ;
568+ if ( form ) form . classList . add ( "new-room-form--hidden" ) ;
569+ const input = document . getElementById ( "rename-room-name" ) ;
570+ if ( input ) input . value = "" ;
571+ }
572+
573+ async function renameCurrentRoom ( ) {
574+ const input = document . getElementById ( "rename-room-name" ) ;
575+ const name = input ? input . value . trim ( ) : "" ;
576+ if ( ! name ) return ;
577+ try {
578+ const updated = await apiRenameRoom ( currentRoomId , name ) ;
579+ const idx = rooms . findIndex ( ( r ) => r . id === currentRoomId ) ;
580+ if ( idx !== - 1 ) rooms [ idx ] = updated ;
581+ hideRenameRoomForm ( ) ;
582+ renderRoomSelector ( ) ;
583+ } catch ( err ) {
584+ console . error ( "Failed to rename room:" , err ) ;
585+ }
586+ }
587+
546588 // ── Edit mode ──────────────────────────────────────────────────────
547589
548590 function enterEditMode ( ) {
@@ -560,6 +602,7 @@ const DashboardApp = (() => {
560602 btnEdit . classList . remove ( "fab--hidden" ) ;
561603 grid . setStatic ( true ) ;
562604 hideNewRoomForm ( ) ;
605+ hideRenameRoomForm ( ) ;
563606
564607 try {
565608 await saveLayout ( serializeLayout ( ) , currentRoomId ) ;
@@ -931,6 +974,23 @@ const DashboardApp = (() => {
931974 } ) ;
932975 }
933976
977+ const btnRoomRename = document . getElementById ( "btn-room-rename" ) ;
978+ if ( btnRoomRename ) btnRoomRename . addEventListener ( "click" , showRenameRoomForm ) ;
979+
980+ const btnRoomRenameSave = document . getElementById ( "btn-room-rename-save" ) ;
981+ if ( btnRoomRenameSave ) btnRoomRenameSave . addEventListener ( "click" , renameCurrentRoom ) ;
982+
983+ const btnRoomCancelRename = document . getElementById ( "btn-room-cancel-rename" ) ;
984+ if ( btnRoomCancelRename ) btnRoomCancelRename . addEventListener ( "click" , hideRenameRoomForm ) ;
985+
986+ const renameRoomNameInput = document . getElementById ( "rename-room-name" ) ;
987+ if ( renameRoomNameInput ) {
988+ renameRoomNameInput . addEventListener ( "keydown" , ( e ) => {
989+ if ( e . key === "Enter" ) renameCurrentRoom ( ) ;
990+ if ( e . key === "Escape" ) hideRenameRoomForm ( ) ;
991+ } ) ;
992+ }
993+
934994 const btnRoomDelete = document . getElementById ( "btn-room-delete" ) ;
935995 if ( btnRoomDelete ) btnRoomDelete . addEventListener ( "click" , deleteCurrentRoom ) ;
936996
0 commit comments