diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index fc28b362..76e4c947 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -584,22 +584,29 @@ class NoteList extends React.Component { filepaths.forEach((filepath) => { fs.readFile(filepath, (err, data) => { if (err) throw Error('File reading error: ', err) - const content = data.toString() - const newNote = { - content: content, - folder: folder.key, - title: markdown.strip(findNoteTitle(content)), - type: 'MARKDOWN_NOTE' - } - dataApi.createNote(storage.key, newNote) - .then((note) => { - dispatch({ - type: 'UPDATE_NOTE', - note: note - }) - hashHistory.push({ - pathname: location.pathname, - query: {key: getNoteKey(note)} + + fs.stat(filepath, (err, {mtime, birthtime}) => { + if (err) throw Error('File stat reading error: ', err); + + const content = data.toString() + const newNote = { + content: content, + folder: folder.key, + title: markdown.strip(findNoteTitle(content)), + type: 'MARKDOWN_NOTE', + createdAt: birthtime, + updatedAt: mtime + } + dataApi.createNote(storage.key, newNote) + .then((note) => { + dispatch({ + type: 'UPDATE_NOTE', + note: note + }) + hashHistory.push({ + pathname: location.pathname, + query: {key: getNoteKey(note)} + }) }) }) }) diff --git a/browser/main/lib/dataApi/createNote.js b/browser/main/lib/dataApi/createNote.js index 91abdb08..1bb7f42a 100644 --- a/browser/main/lib/dataApi/createNote.js +++ b/browser/main/lib/dataApi/createNote.js @@ -66,12 +66,12 @@ function createNote (storageKey, input) { } } } - const noteData = Object.assign({}, input, { + const noteData = Object.assign({}, { key, createdAt: new Date(), updatedAt: new Date(), storage: storageKey - }) + }, input) CSON.writeFileSync(path.join(storage.path, 'notes', key + '.cson'), _.omit(noteData, ['key', 'storage']))