@@ -17,6 +17,15 @@ export class Database {
1717
1818 constructor ( context : vscode . ExtensionContext ) {
1919 this . context = context ;
20+ // Initialize storage if empty
21+ if ( ! this . context . globalState . get ( 'timeEntries' ) ) {
22+ this . context . globalState . update ( 'timeEntries' , [ ] ) ;
23+ }
24+
25+ // Debug logging
26+ const entries = this . getEntries ( ) ;
27+ console . log ( 'Database initialized with entries:' , entries ) ;
28+
2029 // Log the storage URI path
2130 const storagePath = this . context . storageUri ?. fsPath ;
2231 if ( storagePath ) {
@@ -28,17 +37,27 @@ export class Database {
2837 async addEntry ( date : Date , project : string , timeSpent : number ) {
2938 const dateString = date . toISOString ( ) . split ( 'T' ) [ 0 ] ;
3039 const entries = this . getEntries ( ) ;
40+
41+ console . log ( 'Adding entry:' , { date : dateString , project, timeSpent } ) ;
42+ console . log ( 'Current entries:' , entries ) ;
43+
3144 const existingEntryIndex = entries . findIndex ( entry => entry . date === dateString && entry . project === project ) ;
3245
3346 if ( existingEntryIndex !== - 1 ) {
34- // Update existing entry
3547 entries [ existingEntryIndex ] . timeSpent += timeSpent ;
48+ console . log ( 'Updated existing entry:' , entries [ existingEntryIndex ] ) ;
3649 } else {
37- // Add new entry
3850 entries . push ( { date : dateString , project, timeSpent } ) ;
51+ console . log ( 'Added new entry' ) ;
3952 }
4053
41- await this . context . globalState . update ( 'timeEntries' , entries ) ;
54+ try {
55+ await this . context . globalState . update ( 'timeEntries' , entries ) ;
56+ console . log ( 'Successfully saved entries:' , this . getEntries ( ) ) ;
57+ } catch ( error ) {
58+ console . error ( 'Error saving entry:' , error ) ;
59+ vscode . window . showErrorMessage ( 'Failed to save time entry' ) ;
60+ }
4261 }
4362
4463 getEntries ( ) : TimeEntry [ ] {
0 commit comments