Skip to content

Commit 19c9af1

Browse files
guneskaanRokt33r
authored andcommitted
Preserve Note Creation and Last Updated Time when Importing from Legacy
1 parent ca2ebab commit 19c9af1

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

src/components/organisms/ImportLegacyNotesForm.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
readFileTypeFromBuffer,
2020
} from '../../lib/electronOnly'
2121
import { join } from 'path'
22-
import { NoteDocEditibleProps } from '../../lib/db/types'
22+
import { NoteDocImportableProps } from '../../lib/db/types'
2323
import { isFolderPathnameValid } from '../../lib/db/utils'
2424
import { useDb } from '../../lib/db'
2525
import { JsonObject } from 'type-fest'
@@ -112,6 +112,8 @@ const ImportLegacyNotesForm = ({ storageId }: ImportLegacyNotesFormProps) => {
112112
const title = normalizeString(note.title)
113113
const tags = normalizeTags(note.tags)
114114
const data = {}
115+
const createdAt = normalizeString(note.createdAt)
116+
const updatedAt = normalizeString(note.updatedAt)
115117
switch (note.type) {
116118
case 'MARKDOWN_NOTE': {
117119
const legacyNoteId = noteFileName.replace(/.cson$/, '')
@@ -164,12 +166,14 @@ const ImportLegacyNotesForm = ({ storageId }: ImportLegacyNotesFormProps) => {
164166
)
165167
}
166168

167-
const noteProps: NoteDocEditibleProps = {
169+
const noteProps: NoteDocImportableProps = {
168170
folderPathname,
169171
title,
170172
content,
171173
tags,
172174
data,
175+
createdAt,
176+
updatedAt,
173177
}
174178
return noteProps
175179
}
@@ -186,12 +190,14 @@ const ImportLegacyNotesForm = ({ storageId }: ImportLegacyNotesFormProps) => {
186190
.map(stringifySnippet)
187191
.join('\n\n')}`
188192

189-
const noteProps: NoteDocEditibleProps = {
193+
const noteProps: NoteDocImportableProps = {
190194
folderPathname,
191195
title,
192196
content,
193197
tags,
194198
data,
199+
createdAt,
200+
updatedAt,
195201
}
196202
return noteProps
197203
}

src/lib/db/FSNoteDb.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Attachment,
88
FolderDocEditibleProps,
99
NoteDocEditibleProps,
10+
NoteDocImportableProps,
1011
TagDocEditibleProps,
1112
TagDoc,
1213
PopulatedFolderDoc,
@@ -257,7 +258,7 @@ class FSNoteDb implements NoteDb {
257258
await unlinkFile(attachmentPathname)
258259
}
259260

260-
async createNote(noteProps: Partial<NoteDocEditibleProps>) {
261+
async createNote(noteProps: Partial<NoteDocEditibleProps | NoteDocImportableProps>) {
261262
const now = getNow()
262263
const noteDoc: NoteDoc = {
263264
_id: generateNoteId(),
@@ -266,9 +267,9 @@ class FSNoteDb implements NoteDb {
266267
tags: [],
267268
folderPathname: '/',
268269
data: {},
269-
...noteProps,
270270
createdAt: now,
271271
updatedAt: now,
272+
...noteProps,
272273
trashed: false,
273274
_rev: generateId(),
274275
}

src/lib/db/createStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ObjectMap,
55
NoteDoc,
66
NoteDocEditibleProps,
7+
NoteDocImportableProps,
78
PopulatedFolderDoc,
89
PopulatedTagDoc,
910
Attachment,
@@ -262,7 +263,7 @@ export function createDbStoreCreator(
262263
[setStorageMap, syncStorage]
263264
)
264265
const createNote = useCallback(
265-
async (storageId: string, noteProps: Partial<NoteDocEditibleProps>) => {
266+
async (storageId: string, noteProps: Partial<NoteDocEditibleProps | NoteDocImportableProps>) => {
266267
const storage = storageMap[storageId]
267268
if (storage == null) {
268269
return

src/lib/db/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ export type NoteDocEditibleProps = {
4343
data: JsonObject
4444
}
4545

46+
export type NoteDocImportableProps = {
47+
createdAt: string
48+
updatedAt: string
49+
} & NoteDocEditibleProps
50+
4651
export type NoteDoc = {
4752
_id: string
4853
createdAt: string

0 commit comments

Comments
 (0)