Skip to content

Commit 5d51584

Browse files
committed
Make NoteChooser component non-md/txt dependent. Fix flow errors in earlier commit.
1 parent b481ebd commit 5d51584

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎helpers/NPnote.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ export function getNoteDecorationForReact(note: TNote | NoteOption): { icon: str
238238
if (note.type === 'Calendar') {
239239
// dateTime helpers match YYYYMMDD etc. with the vault's supported extensions; also allow ISO daily filenames, should they erronesouly exist now, or are allowed in future.
240240
const basename = note.filename.split('/').pop() || ''
241-
noteTypeForIcon = dt.isDailyNote(note) || dt.isIsoDaily(basename) ? '<DAY>' : dt.isWeeklyNote(note) ? '<WEEK>' : dt.isMonthlyNote(note) ? '<MONTH>' : dt.isQuarterlyNote(note) ? '<QUARTER>' : '<YEAR>'
241+
const calendarNoteForTypeCheck: CoreNoteFields = (note: any)
242+
noteTypeForIcon = dt.isDailyNote(calendarNoteForTypeCheck) || dt.isIsoDaily(basename) ? '<DAY>' : dt.isWeeklyNote(calendarNoteForTypeCheck) ? '<WEEK>' : dt.isMonthlyNote(calendarNoteForTypeCheck) ? '<MONTH>' : dt.isQuarterlyNote(calendarNoteForTypeCheck) ? '<QUARTER>' : '<YEAR>'
242243
}
243244
const folderIconDetails = noteIconsToUse.find((details) => details.firstLevelFolder === noteTypeForIcon) ?? defaultNoteIconDetails
244245

‎helpers/dateTime.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const RE_OFFSET_DATE_CAPTURE = `{(\\^?${RE_DATE_INTERVAL})}`
100100
* @param {string} basename
101101
* @returns {boolean} true if basename is of form YYYY-MM-DD.md or YYYY-MM-DD.txt
102102
*/
103-
export const isIsoDaily = (basename) => new RegExp(`^${RE_DATE}${FILE_EXTENSIONS_GROUP}`, 'i').test(basename)
103+
export const isIsoDaily = (basename: string): boolean => new RegExp(`^${RE_DATE}${FILE_EXTENSIONS_GROUP}`, 'i').test(basename)
104104

105105
/**
106106
* WARNING: Deprecated in favour of clearer named function 'todaysDateISOString' below.

‎helpers/react/DynamicDialog/NoteChooser.jsx‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { logDebug, logError } from '@helpers/react/reactDev.js'
1515
import { unwrapPluginRequestData } from '@helpers/react/pluginRequestEnvelope'
1616
import { getNoteDecorationForReact, TEAMSPACE_ICON_COLOR } from '@helpers/NPnote.js'
1717
import { getFolderFromFilename } from '@helpers/folders.js'
18+
import { makeCalendarFilename, RE_NOTE_FILE_EXTENSION } from '@helpers/NPFileExtensions'
1819
import { parseTeamspaceFilename, getFilenameWithoutTeamspaceID } from '@helpers/teamspace.js'
1920
import './NoteChooser.css'
2021

@@ -196,7 +197,7 @@ export function NoteChooser({
196197
// Use setTimeout to ensure notes are reloaded first
197198
setTimeout(() => {
198199
// Get the note title from the filename
199-
const noteTitleFromFilename = createdFilename.split('/').pop()?.replace(/\.md$/, '') || noteTitle.trim()
200+
const noteTitleFromFilename = createdFilename.split('/').pop()?.replace(RE_NOTE_FILE_EXTENSION, '') || noteTitle.trim()
200201
onChange(noteTitleFromFilename, createdFilename)
201202
}, 100)
202203
} else {
@@ -261,19 +262,21 @@ export function NoteChooser({
261262
}
262263

263264
/**
264-
* Convert a Date object to calendar note filename (YYYYMMDD.md)
265+
* Convert a Date object to its equivalent daily calendar note filename (YYYYMMDD with user's file extension)
266+
* Note: This is local-timezone-dependent.
265267
* @param {Date} date - The date to convert
266268
* @returns {string} - Calendar note filename
267269
*/
268270
const dateToCalendarFilename = (date: Date): string => {
269271
const year = date.getFullYear()
270272
const month = String(date.getMonth() + 1).padStart(2, '0')
271273
const day = String(date.getDate()).padStart(2, '0')
272-
return `${year}${month}${day}.md`
274+
return makeCalendarFilename(`${year}${month}${day}`)
273275
}
274276

275277
/**
276-
* Convert a Date object to ISO 8601 format (YYYY-MM-DD) in local timezone
278+
* Convert a Date object to ISO 8601 format (YYYY-MM-DD)
279+
* Note: this is local-timezone-dependent.
277280
* @param {Date} date - The date to convert
278281
* @returns {string} - ISO 8601 date string
279282
*/

0 commit comments

Comments
 (0)