From fbb16cacdd6fa7c4c85afc96d8a09dbb584f23cb Mon Sep 17 00:00:00 2001 From: zombieFox Date: Fri, 27 Aug 2021 13:11:33 +0100 Subject: [PATCH] add or replace bookmarks when importing data --- src/component/bookmark/index.js | 17 +++++- src/component/data/index.js | 38 ++++++++++---- src/component/importForm/index.js | 87 ++++++++++++++++++++++--------- 3 files changed, 107 insertions(+), 35 deletions(-) diff --git a/src/component/bookmark/index.js b/src/component/bookmark/index.js index 7f7eb86d..6419b767 100644 --- a/src/component/bookmark/index.js +++ b/src/component/bookmark/index.js @@ -478,8 +478,23 @@ bookmark.count = () => { }; bookmark.restore = (dataToRestore) => { + bookmark.all = dataToRestore.bookmark; - console.log('bookmark restored'); + + console.log('bookmarks restored'); + +}; + +bookmark.append = (dataToAppend) => { + + dataToAppend.bookmark.forEach((item, i) => { + + bookmark.all.push(item); + + }); + + console.log('bookmarks appended'); + }; bookmark.reset = () => { diff --git a/src/component/data/index.js b/src/component/data/index.js index b3b85bf1..83140c8e 100644 --- a/src/component/data/index.js +++ b/src/component/data/index.js @@ -24,12 +24,20 @@ data.get = (key) => { }; data.import = { - state: { setup: true, bookmark: true, theme: true }, + state: { + setup: { include: true }, + bookmark: { include: true, type: 'restore' }, + theme: { include: true } + }, reset: () => { - for (let key in data.import.state) { - data.import.state[key] = true; - }; + data.import.state.setup.include = true; + + data.import.state.bookmark.include = true; + + data.import.state.bookmark.type = 'restore'; + + data.import.state.theme.include = true; }, file: ({ @@ -104,7 +112,7 @@ data.validateFile = ({ width: 'small', successAction: () => { - if (data.import.state.setup || data.import.state.theme || data.import.state.bookmark) { + if (data.import.state.setup.include || data.import.state.theme.include || data.import.state.bookmark.include) { let dataToRestore = JSON.parse(event.target.result); @@ -255,16 +263,28 @@ data.restore = (dataToRestore) => { console.log('data found to load'); - if (data.import.state.setup) { + if (data.import.state.setup.include) { state.set.restore.setup(dataToRestore); }; - if (data.import.state.theme) { + if (data.import.state.theme.include) { state.set.restore.theme(dataToRestore); }; - if (data.import.state.bookmark) { - bookmark.restore(dataToRestore); + if (data.import.state.bookmark.include) { + + switch (data.import.state.bookmark.type) { + + case 'restore': + bookmark.restore(dataToRestore); + break; + + case 'append': + bookmark.append(dataToRestore); + break; + + }; + }; } else { diff --git a/src/component/importForm/index.js b/src/component/importForm/index.js index d9b806ae..7c99dc9f 100644 --- a/src/component/importForm/index.js +++ b/src/component/importForm/index.js @@ -50,39 +50,76 @@ export const ImportForm = function({ this.control = { import: { - bookmark: new Control_checkbox({ - object: state, - path: 'bookmark', - id: 'bookmark', - labelText: 'Bookmarks', - description: [`This includes ${this.count.bookmark()} ${this.count.bookmark() > 1 ? `Bookmarks` : `Bookmark`} in ${dataToImport.bookmark.length} ${dataToImport.bookmark.length > 1 ? `Groups` : `Group`}.`, 'Bookmarks will keep any custom Colours, Accents and Borders when imported.'] - }), - theme: new Control_checkbox({ - object: state, - path: 'theme', - id: 'theme', - labelText: 'Theme', - description: 'This includes the Colour, Accent, Fonts, Background and any saved Custom Themes.' - }), - setup: new Control_checkbox({ - object: state, - path: 'setup', - id: 'setup', - labelText: 'Settings', - description: 'This includes Layout size and position, Header area size, Bookmark area size and other user settings.' - }) + bookmark: { + include: new Control_checkbox({ + object: state, + path: 'bookmark.include', + id: 'bookmark-include', + labelText: 'Bookmarks', + description: [`This includes ${this.count.bookmark()} ${this.count.bookmark() > 1 ? `Bookmarks` : `Bookmark`} in ${dataToImport.bookmark.length} ${dataToImport.bookmark.length > 1 ? `Groups` : `Group`}.`, 'Bookmarks will keep any custom Colours, Accents and Borders when imported.'], + action: () => { + this.disable(); + } + }), + type: new Control_radio({ + object: state, + radioGroup: [ + { id: 'bookmark-type-restore', labelText: 'Replace existing bookmarks', value: 'restore' }, + { id: 'bookmark-type-append', labelText: 'Add to existing bookmarks', value: 'append' } + ], + groupName: 'bookmark-type', + path: 'bookmark.type' + }) + }, + theme: { + include: new Control_checkbox({ + object: state, + path: 'theme.include', + id: 'theme-include', + labelText: 'Theme', + description: 'This includes the Colour, Accent, Fonts, Background and any saved Custom Themes.' + }) + }, + setup: { + include: new Control_checkbox({ + object: state, + path: 'setup.include', + id: 'setup-include', + labelText: 'Settings', + description: 'This includes Layout size and position, Header area size, Bookmark area size and other user settings.' + }) + } } }; - this.disable = () => {}; + this.disable = () => { + + if (state.bookmark.include) { + this.control.import.bookmark.type.enable(); + } else { + this.control.import.bookmark.type.disable(); + }; + + }; this.assemble = () => { this.element.form.append(node('div', [ this.element.description, - this.control.import.bookmark.wrap(), - this.control.import.theme.wrap(), - this.control.import.setup.wrap() + this.control.import.bookmark.include.wrap(), + form.wrap({ + children: [ + form.indent({ + children: [ + this.control.import.bookmark.type.wrap(), + ] + }) + ] + }), + node('hr'), + this.control.import.theme.include.wrap(), + node('hr'), + this.control.import.setup.include.wrap() ])); };