@@ -10,8 +10,7 @@ import { FileView, TFile, ItemView, WorkspaceLeaf } from "obsidian";
10
10
import { get } from "svelte/store" ;
11
11
12
12
import { TRIGGER_ON_OPEN , VIEW_TYPE_CALENDAR } from "src/constants" ;
13
- import { tryToCreateDailyNote } from "src/io/dailyNotes" ;
14
- import { tryToCreateWeeklyNote } from "src/io/weeklyNotes" ;
13
+ import { getDateForPeriodicNote , tryToCreatePeriodicNote , Period } from "src/io/periodicNotes" ;
15
14
import type { ISettings } from "src/settings" ;
16
15
17
16
import Calendar from "./ui/Calendar.svelte" ;
@@ -33,6 +32,7 @@ export default class CalendarView extends ItemView {
33
32
34
33
this . openOrCreateDailyNote = this . openOrCreateDailyNote . bind ( this ) ;
35
34
this . openOrCreateWeeklyNote = this . openOrCreateWeeklyNote . bind ( this ) ;
35
+ this . openOrCreateMonthlyNote = this . openOrCreateMonthlyNote . bind ( this ) ;
36
36
37
37
this . onNoteSettingsUpdate = this . onNoteSettingsUpdate . bind ( this ) ;
38
38
this . onFileCreated = this . onFileCreated . bind ( this ) ;
@@ -105,6 +105,7 @@ export default class CalendarView extends ItemView {
105
105
props : {
106
106
onClickDay : this . openOrCreateDailyNote ,
107
107
onClickWeek : this . openOrCreateWeeklyNote ,
108
+ onClickMonth : this . openOrCreateMonthlyNote ,
108
109
onHoverDay : this . onHoverDay ,
109
110
onHoverWeek : this . onHoverWeek ,
110
111
onContextMenuDay : this . onContextMenuDay ,
@@ -255,45 +256,21 @@ export default class CalendarView extends ItemView {
255
256
}
256
257
}
257
258
258
- async openOrCreateWeeklyNote (
259
- date : Moment ,
260
- inNewSplit : boolean
261
- ) : Promise < void > {
262
- const { workspace } = this . app ;
263
-
264
- const startOfWeek = date . clone ( ) . startOf ( "week" ) ;
265
-
266
- const existingFile = getWeeklyNote ( date , get ( weeklyNotes ) ) ;
267
-
268
- if ( ! existingFile ) {
269
- // File doesn't exist
270
- tryToCreateWeeklyNote ( startOfWeek , inNewSplit , this . settings , ( file ) => {
271
- activeFile . setFile ( file ) ;
272
- } ) ;
273
- return ;
274
- }
275
-
276
- const leaf = inNewSplit
277
- ? workspace . splitActiveLeaf ( )
278
- : workspace . getUnpinnedLeaf ( ) ;
279
- await leaf . openFile ( existingFile ) ;
280
-
281
- activeFile . setFile ( existingFile ) ;
282
- workspace . setActiveLeaf ( leaf , true , true )
283
- }
284
-
285
- async openOrCreateDailyNote (
259
+ async openOrCreatePeriodicNote (
260
+ noteType : Period ,
286
261
date : Moment ,
287
- inNewSplit : boolean
262
+ inNewSplit : boolean ,
288
263
) : Promise < void > {
289
264
const { workspace } = this . app ;
290
- const existingFile = getDailyNote ( date , get ( dailyNotes ) ) ;
265
+ const periodicNoteDate = getDateForPeriodicNote ( date , noteType ) ;
266
+ const existingFile = getDailyNote ( periodicNoteDate , get ( dailyNotes ) ) ;
291
267
if ( ! existingFile ) {
292
268
// File doesn't exist
293
- tryToCreateDailyNote (
269
+ tryToCreatePeriodicNote (
294
270
date ,
295
271
inNewSplit ,
296
272
this . settings ,
273
+ Period . Daily ,
297
274
( dailyNote : TFile ) => {
298
275
activeFile . setFile ( dailyNote ) ;
299
276
}
@@ -310,4 +287,27 @@ export default class CalendarView extends ItemView {
310
287
311
288
activeFile . setFile ( existingFile ) ;
312
289
}
290
+
291
+ async openOrCreateDailyNote (
292
+ date : Moment ,
293
+ inNewSplit : boolean
294
+ ) {
295
+ this . openOrCreatePeriodicNote ( Period . Daily , date , inNewSplit ) ;
296
+ }
297
+
298
+ async openOrCreateWeeklyNote (
299
+ date : Moment ,
300
+ inNewSplit : boolean
301
+ ) {
302
+ this . openOrCreatePeriodicNote ( Period . Weekly , date , inNewSplit ) ;
303
+ }
304
+
305
+ async openOrCreateMonthlyNote (
306
+ date : Moment ,
307
+ inNewSplit : boolean
308
+ ) {
309
+ this . openOrCreatePeriodicNote ( Period . Monthly , date , inNewSplit ) ;
310
+ }
311
+
312
+
313
313
}
0 commit comments