fixed import blank prompts if exprted without closing the custom prompts page
This commit is contained in:
parent
3dd89a3c1b
commit
f17dec6e65
1 changed files with 16 additions and 5 deletions
|
|
@ -150,9 +150,11 @@ const defaultPrompts = [
|
||||||
|
|
||||||
|
|
||||||
export async function getPrompts(onlyEnabled = false){
|
export async function getPrompts(onlyEnabled = false){
|
||||||
const defaultPrompts = await getDefaultPrompts_withProps();
|
const _defaultPrompts = await getDefaultPrompts_withProps();
|
||||||
|
// console.log('>>>>>>>>>>>> getPrompts _defaultPrompts: ' + JSON.stringify(_defaultPrompts));
|
||||||
const customPrompts = await getCustomPrompts();
|
const customPrompts = await getCustomPrompts();
|
||||||
let output = defaultPrompts.concat(customPrompts);
|
// console.log('>>>>>>>>>>>> getPrompts customPrompts: ' + JSON.stringify(customPrompts));
|
||||||
|
let output = _defaultPrompts.concat(customPrompts);
|
||||||
if(onlyEnabled){
|
if(onlyEnabled){
|
||||||
output = output.filter(obj => obj.enabled != 0);
|
output = output.filter(obj => obj.enabled != 0);
|
||||||
}else{ // order only if we are not filtering, the filtering is for the menus and we are ordering there after i18n
|
}else{ // order only if we are not filtering, the filtering is for the menus and we are ordering there after i18n
|
||||||
|
|
@ -161,6 +163,7 @@ export async function getPrompts(onlyEnabled = false){
|
||||||
for(let i=1; i<=output.length; i++){
|
for(let i=1; i<=output.length; i++){
|
||||||
output[i-1].idnum = i;
|
output[i-1].idnum = i;
|
||||||
}
|
}
|
||||||
|
// console.log('>>>>>>>>>>>> getPrompts output: ' + JSON.stringify(output));
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -181,7 +184,9 @@ export function preparePromptsForExport(prompts){
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function preparePromptsForImport(prompts){
|
export async function preparePromptsForImport(prompts){
|
||||||
|
// console.log(">>>>>>>>>>> preparePromptsForImport prompts: " + JSON.stringify(prompts));
|
||||||
const output = await getPrompts();
|
const output = await getPrompts();
|
||||||
|
// console.log(">>>>>>>>>>> preparePromptsForImport output: " + JSON.stringify(output));
|
||||||
prompts.forEach(prompt => {
|
prompts.forEach(prompt => {
|
||||||
if(output.some(p => p.id == prompt.id)){
|
if(output.some(p => p.id == prompt.id)){
|
||||||
Object.keys(prompt).forEach(key => {
|
Object.keys(prompt).forEach(key => {
|
||||||
|
|
@ -192,13 +197,17 @@ export async function preparePromptsForImport(prompts){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
output.sort((a, b) => a.id.localeCompare(b.id));
|
output.sort((a, b) => a.id.localeCompare(b.id));
|
||||||
//console.log(">>>>>>>>>>> preparePromptsForImport: " + JSON.stringify(output));
|
// console.log(">>>>>>>>>>> preparePromptsForImport final output: " + JSON.stringify(output));
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getDefaultPrompts_withProps() {
|
async function getDefaultPrompts_withProps() {
|
||||||
let prefs = await browser.storage.local.get({_default_prompts_properties: null}); //production
|
let prefs = await browser.storage.local.get({_default_prompts_properties: null});
|
||||||
let defaultPrompts_prop = [...defaultPrompts];
|
// console.log('>>>>>>>>>>>> getDefaultPrompts_withProps prefs: ' + JSON.stringify(prefs));
|
||||||
|
//let defaultPrompts_prop = [...defaultPrompts];
|
||||||
|
let defaultPrompts_prop = JSON.parse(JSON.stringify(defaultPrompts));
|
||||||
|
// console.log('>>>>>>>>>>>> getDefaultPrompts_withProps defaultPrompts: ' + JSON.stringify(defaultPrompts));
|
||||||
|
// console.log('>>>>>>>>>>>> getDefaultPrompts_withProps defaultPrompts_prop: ' + JSON.stringify(defaultPrompts_prop));
|
||||||
if(prefs._default_prompts_properties === null){ // no default prompts properties saved
|
if(prefs._default_prompts_properties === null){ // no default prompts properties saved
|
||||||
let pos = 1;
|
let pos = 1;
|
||||||
defaultPrompts_prop.forEach((prompt) => {
|
defaultPrompts_prop.forEach((prompt) => {
|
||||||
|
|
@ -207,6 +216,7 @@ async function getDefaultPrompts_withProps() {
|
||||||
prompt.enabled = 1;
|
prompt.enabled = 1;
|
||||||
pos++;
|
pos++;
|
||||||
})
|
})
|
||||||
|
// console.log('>>>>>>>>>>>> getDefaultPrompts_withProps [no prop saved] defaultPrompts_prop: ' + JSON.stringify(defaultPrompts_prop));
|
||||||
} else { // we have saved default prompts properties
|
} else { // we have saved default prompts properties
|
||||||
let pos = 1000;
|
let pos = 1000;
|
||||||
defaultPrompts_prop.forEach((prompt) => {
|
defaultPrompts_prop.forEach((prompt) => {
|
||||||
|
|
@ -222,6 +232,7 @@ async function getDefaultPrompts_withProps() {
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
// console.log('>>>>>>>>>>>> getDefaultPrompts_withProps [prop saved] defaultPrompts_prop: ' + JSON.stringify(defaultPrompts_prop));
|
||||||
}
|
}
|
||||||
return defaultPrompts_prop;
|
return defaultPrompts_prop;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue