mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-22 22:49:45 +01:00
core: use migrations to dedup shortcuts
This commit is contained in:
@@ -18,7 +18,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import Collection from "./collection";
|
import Collection from "./collection";
|
||||||
import { EV, EVENTS } from "../common";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
@@ -45,11 +44,6 @@ export default class Shortcuts extends Collection {
|
|||||||
await this._collection.addItem(shortcut);
|
await this._collection.addItem(shortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
|
||||||
await super.init();
|
|
||||||
await this.dedupe();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {Partial<Shortcut>} shortcut
|
* @param {Partial<Shortcut>} shortcut
|
||||||
@@ -156,20 +150,4 @@ export default class Shortcuts extends Collection {
|
|||||||
await this._collection.removeItem(id);
|
await this._collection.removeItem(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async dedupe() {
|
|
||||||
const oldShortcuts = this.all.filter(
|
|
||||||
(shortcut) => shortcut.id !== shortcut.item.id
|
|
||||||
);
|
|
||||||
|
|
||||||
for (const shortcut of oldShortcuts) {
|
|
||||||
await this._collection.addItem({ ...shortcut, id: shortcut.item.id });
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const shortcut of oldShortcuts) {
|
|
||||||
await this._collection.removeItem(shortcut.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (oldShortcuts.length > 0) EV.publish(EVENTS.appRefreshRequested);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,7 +110,12 @@ const migrations = [
|
|||||||
if (!item.data || item.data.iv) return item;
|
if (!item.data || item.data.iv) return item;
|
||||||
item.type = "tiptap";
|
item.type = "tiptap";
|
||||||
return item;
|
return item;
|
||||||
},
|
},
|
||||||
|
shortcut: (item) => {
|
||||||
|
if (item.id === item.item.id) return item;
|
||||||
|
item.id = item.item.id;
|
||||||
|
return item;
|
||||||
|
},
|
||||||
tiptap: (item) => {
|
tiptap: (item) => {
|
||||||
return changeSessionContentType(item);
|
return changeSessionContentType(item);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user