diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index c5b0355d..470da1df 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -504,9 +504,20 @@ export default class MarkdownPreview extends React.Component { handlelinkClick (e) { const noteHash = e.target.href.split('/').pop() - const regexIsNoteLink = /^(.{20})-(.{20})$/ + // this will match the new uuid v4 hash and the old hash + // e.g. + // :note:1c211eb7dcb463de6490 and + // :note:7dd23275-f2b4-49cb-9e93-3454daf1af9c + const regexIsNoteLink = /^:note:([a-zA-Z0-9-]{20,36})$/ if (regexIsNoteLink.test(noteHash)) { - eventEmitter.emit('list:jump', noteHash) + eventEmitter.emit('list:jump', noteHash.replace(':note:', '')) + } + // this will match the old link format storage.key-note.key + // e.g. + // 877f99c3268608328037-1c211eb7dcb463de6490 + const regexIsLegacyNoteLink = /^(.{20})-(.{20})$/ + if (regexIsLegacyNoteLink.test(noteHash)) { + eventEmitter.emit('list:jump', noteHash.split('-')[1]) } } diff --git a/browser/components/NoteItem.js b/browser/components/NoteItem.js index 2c93dc18..72d1263a 100644 --- a/browser/components/NoteItem.js +++ b/browser/components/NoteItem.js @@ -62,9 +62,9 @@ const NoteItem = ({ ? 'item--active' : 'item' } - key={`${note.storage}-${note.key}`} - onClick={e => handleNoteClick(e, `${note.storage}-${note.key}`)} - onContextMenu={e => handleNoteContextMenu(e, `${note.storage}-${note.key}`)} + key={note.key} + onClick={e => handleNoteClick(e, note.key)} + onContextMenu={e => handleNoteContextMenu(e, note.key)} onDragStart={e => handleDragStart(e, note)} draggable='true' > diff --git a/browser/components/NoteItemSimple.js b/browser/components/NoteItemSimple.js index 0d2465e9..8262ea1d 100644 --- a/browser/components/NoteItemSimple.js +++ b/browser/components/NoteItemSimple.js @@ -28,9 +28,9 @@ const NoteItemSimple = ({ ? 'item-simple--active' : 'item-simple' } - key={`${note.storage}-${note.key}`} - onClick={e => handleNoteClick(e, `${note.storage}-${note.key}`)} - onContextMenu={e => handleNoteContextMenu(e, `${note.storage}-${note.key}`)} + key={note.key} + onClick={e => handleNoteClick(e, note.key)} + onContextMenu={e => handleNoteContextMenu(e, note.key)} onDragStart={e => handleDragStart(e, note)} draggable='true' > diff --git a/browser/lib/keygen.js b/browser/lib/keygen.js index f4937a83..8bf58a19 100644 --- a/browser/lib/keygen.js +++ b/browser/lib/keygen.js @@ -1,7 +1,5 @@ -const crypto = require('crypto') -const _ = require('lodash') +const uuidv4 = require('uuid/v4') -module.exports = function (length) { - if (!_.isFinite(length)) length = 10 - return crypto.randomBytes(length).toString('hex') +module.exports = function () { + return uuidv4() } diff --git a/browser/main/Detail/MarkdownNoteDetail.js b/browser/main/Detail/MarkdownNoteDetail.js index a543a5aa..6821bf2f 100755 --- a/browser/main/Detail/MarkdownNoteDetail.js +++ b/browser/main/Detail/MarkdownNoteDetail.js @@ -139,7 +139,7 @@ class MarkdownNoteDetail extends React.Component { hashHistory.replace({ pathname: location.pathname, query: { - key: newNote.storage + '-' + newNote.key + key: newNote.key } }) this.setState({ @@ -393,7 +393,7 @@ class MarkdownNoteDetail extends React.Component { `${note.storage}-${note.key}` === noteKey) + return notes.find((note) => note.key === noteKey) } function findNotesByKeys (notes, noteKeys) { @@ -39,7 +39,7 @@ function findNotesByKeys (notes, noteKeys) { } function getNoteKey (note) { - return `${note.storage}-${note.key}` + return note.key } class NoteList extends React.Component { @@ -114,10 +114,10 @@ class NoteList extends React.Component { componentDidUpdate (prevProps) { const { location } = this.props const { selectedNoteKeys } = this.state - const visibleNoteKeys = this.notes.map(note => `${note.storage}-${note.key}`) + const visibleNoteKeys = this.notes.map(note => note.key) const note = this.notes[0] const prevKey = prevProps.location.query.key - const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && `${note.storage}-${note.key}` + const noteKey = visibleNoteKeys.includes(prevKey) ? prevKey : note && note.key if (note && location.query.key == null) { const { router } = this.context @@ -613,19 +613,18 @@ class NoteList extends React.Component { content: firstNote.content }) .then((note) => { - const uniqueKey = note.storage + '-' + note.key dispatch({ type: 'UPDATE_NOTE', note: note }) this.setState({ - selectedNoteKeys: [uniqueKey] + selectedNoteKeys: [note.key] }) hashHistory.push({ pathname: location.pathname, - query: {key: uniqueKey} + query: {key: note.key} }) }) } diff --git a/browser/main/modals/NewNoteModal.js b/browser/main/modals/NewNoteModal.js index 8322d99f..84f510c4 100644 --- a/browser/main/modals/NewNoteModal.js +++ b/browser/main/modals/NewNoteModal.js @@ -35,7 +35,7 @@ class NewNoteModal extends React.Component { content: '' }) .then((note) => { - const noteHash = `${note.storage}-${note.key}` + const noteHash = note.key dispatch({ type: 'UPDATE_NOTE', note: note @@ -75,7 +75,7 @@ class NewNoteModal extends React.Component { }] }) .then((note) => { - const noteHash = `${note.storage}-${note.key}` + const noteHash = note.key dispatch({ type: 'UPDATE_NOTE', note: note diff --git a/browser/main/store.js b/browser/main/store.js index abd34889..1ee9fc88 100644 --- a/browser/main/store.js +++ b/browser/main/store.js @@ -27,7 +27,7 @@ function data (state = defaultDataMap(), action) { action.notes.some((note) => { if (note === undefined) return true - const uniqueKey = note.storage + '-' + note.key + const uniqueKey = note.key const folderKey = note.storage + '-' + note.folder state.noteMap.set(uniqueKey, note) @@ -66,7 +66,7 @@ function data (state = defaultDataMap(), action) { case 'UPDATE_NOTE': { const note = action.note - const uniqueKey = note.storage + '-' + note.key + const uniqueKey = note.key const folderKey = note.storage + '-' + note.folder const oldNote = state.noteMap.get(uniqueKey) @@ -162,9 +162,9 @@ function data (state = defaultDataMap(), action) { case 'MOVE_NOTE': { const originNote = action.originNote - const originKey = originNote.storage + '-' + originNote.key + const originKey = originNote.key const note = action.note - const uniqueKey = note.storage + '-' + note.key + const uniqueKey = note.key const folderKey = note.storage + '-' + note.folder const oldNote = state.noteMap.get(uniqueKey) @@ -423,7 +423,7 @@ function data (state = defaultDataMap(), action) { state.folderNoteMap = new Map(state.folderNoteMap) state.tagNoteMap = new Map(state.tagNoteMap) action.notes.forEach((note) => { - const uniqueKey = note.storage + '-' + note.key + const uniqueKey = note.key const folderKey = note.storage + '-' + note.folder state.noteMap.set(uniqueKey, note) @@ -483,7 +483,7 @@ function data (state = defaultDataMap(), action) { state.tagNoteMap = new Map(state.tagNoteMap) state.starredSet = new Set(state.starredSet) notes.forEach((note) => { - const noteKey = storage.key + '-' + note.key + const noteKey = note.key state.noteMap.delete(noteKey) state.starredSet.delete(noteKey) note.tags.forEach((tag) => { diff --git a/package.json b/package.json index db2a9733..4c258224 100644 --- a/package.json +++ b/package.json @@ -86,7 +86,8 @@ "sander": "^0.5.1", "striptags": "^2.2.1", "superagent": "^1.2.0", - "superagent-promise": "^1.0.3" + "superagent-promise": "^1.0.3", + "uuid": "^3.2.1" }, "devDependencies": { "ava": "^0.16.0", diff --git a/tests/fixtures/TestDummy.js b/tests/fixtures/TestDummy.js index 4edcc9cf..1ded274b 100644 --- a/tests/fixtures/TestDummy.js +++ b/tests/fixtures/TestDummy.js @@ -149,9 +149,9 @@ function dummyLegacyStorage (storagePath, override = {}) { var folderNotes = [] var noteCount = Math.floor((Math.random() * 5)) + 1 for (var i = 0; i < noteCount; i++) { - var key = keygen(6) + var key = keygen() while (folderNotes.some((note) => note.key === key)) { - key = keygen(6) + key = keygen() } var noteData = dummyNote({ diff --git a/yarn.lock b/yarn.lock index c1a949a4..ffd1da24 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6672,6 +6672,10 @@ uuid@^2.0.1, uuid@^2.0.2: version "2.0.3" resolved "https://registry.yarnpkg.com/uuid/-/uuid-2.0.3.tgz#67e2e863797215530dff318e5bf9dcebfd47b21a" +uuid@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.2.1.tgz#12c528bb9d58d0b9265d9a2f6f0fe8be17ff1f14" + validate-npm-package-license@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"