Skip to content

Commit

Permalink
Fix TemplateStorage save
Browse files Browse the repository at this point in the history
  • Loading branch information
lmg-anon authored Jun 1, 2024
1 parent 55e9c58 commit 5a6c010
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -2631,19 +2631,31 @@
}

function handleInstructTemplateChange(templateName,key,value,back="") {
const templateListMod = templateList
const tempIndex = templateListMod.findIndex(obj => obj.name === templateName);
const index = tempIndex < 0 ? 0 : tempIndex;
if (key == "name")
setNewTemplateName(value);

if (key == "name") {
templateListMod[index].nameNew = value
setNewTemplateName(value)
} else {
templateListMod[index].affixes[key] = value
}
setTemplateList((prevState) => ([
...templateListMod
]))
setTemplateList((prevState) => {
const newState = [
...prevState
];
const tempIndex = newState.findIndex(obj => obj.name === templateName);
const index = tempIndex < 0 ? 0 : tempIndex;
if (key == "name") {
newState[index] = {
...newState[index],
'nameNew': value
}
} else {
newState[index] = {
...newState[index],
affixes: {
...newState[index].affixes,
[key]: value
}
}
}
return newState;
});
}

async function handleInstructTemplateAdd() {
Expand Down Expand Up @@ -2723,17 +2735,14 @@

if (name === undefined || nameBack === undefined)
continue

// if template has been renamed, delete old entry, make sure to reselect
// current entry after
if (name != nameBack) {
newState[name] = prevState[nameBack]
delete newState[nameBack]
}

// if no changes, skip
if (newState[name] == prevState[name])
continue

newState[name] = {
"sysPre": template.affixes.sysPre,
"sysSuf": template.affixes.sysSuf,
Expand Down

0 comments on commit 5a6c010

Please sign in to comment.