@@ -1637,28 +1637,57 @@ export class NavigationManager {
16371637 if ( ! window . sessionManager || ! sessionId ) return ;
16381638
16391639 try {
1640+ let sessionFound = false ;
1641+
16401642 // Find and delete the session
16411643 for ( const [ dateString , sessions ] of Object . entries ( window . sessionManager . sessions ) ) {
16421644 const sessionIndex = sessions . findIndex ( s => s . id === sessionId ) ;
16431645 if ( sessionIndex !== - 1 ) {
16441646 sessions . splice ( sessionIndex , 1 ) ;
1645- await window . sessionManager . saveSessionsToStorage ( ) ;
1646-
1647- // Refresh the table
1648- const filterSelect = document . getElementById ( 'sessions-filter-period' ) ;
1649- const currentPeriod = filterSelect ? filterSelect . value : 'today' ;
1650- await this . populateSessionsTable ( currentPeriod ) ;
1651-
1652- // Refresh other views
1653- await this . updateDailyChart ( ) ;
1654- await this . updateFocusSummary ( ) ;
1655- await this . updateWeeklySessionsChart ( ) ;
1656- await this . updateTimelineForDate ( new Date ( ) ) ;
1657-
1647+ sessionFound = true ;
16581648 console . log ( 'Session deleted successfully:' , sessionId ) ;
16591649 break ;
16601650 }
16611651 }
1652+
1653+ if ( ! sessionFound ) {
1654+ console . warn ( 'Session not found for deletion:' , sessionId ) ;
1655+ return ;
1656+ }
1657+
1658+ // Save the updated sessions
1659+ await window . sessionManager . saveSessionsToStorage ( ) ;
1660+
1661+ // Refresh the table
1662+ const filterSelect = document . getElementById ( 'sessions-filter-period' ) ;
1663+ const currentPeriod = filterSelect ? filterSelect . value : 'today' ;
1664+ await this . populateSessionsTable ( currentPeriod ) ;
1665+
1666+ // Refresh other views (with error handling for each)
1667+ try {
1668+ await this . updateDailyChart ( ) ;
1669+ } catch ( e ) {
1670+ console . warn ( 'Failed to update daily chart after deletion:' , e ) ;
1671+ }
1672+
1673+ try {
1674+ await this . updateFocusSummary ( ) ;
1675+ } catch ( e ) {
1676+ console . warn ( 'Failed to update focus summary after deletion:' , e ) ;
1677+ }
1678+
1679+ try {
1680+ await this . updateWeeklySessionsChart ( ) ;
1681+ } catch ( e ) {
1682+ console . warn ( 'Failed to update weekly chart after deletion:' , e ) ;
1683+ }
1684+
1685+ try {
1686+ await this . updateTimelineForDate ( new Date ( ) ) ;
1687+ } catch ( e ) {
1688+ console . warn ( 'Failed to update timeline after deletion:' , e ) ;
1689+ }
1690+
16621691 } catch ( error ) {
16631692 console . error ( 'Error deleting session:' , error ) ;
16641693 alert ( 'Failed to delete session. Please try again.' ) ;
0 commit comments