Skip to content

Commit

Permalink
Merge pull request #73 from neCo2/duplicate-instruct-template
Browse files Browse the repository at this point in the history
added duplicate button for instruct templates
  • Loading branch information
lmg-anon authored Jun 7, 2024
2 parents 21426b7 + 7f8383d commit b0a0a5a
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,7 @@

function InstructModal({ isOpen, closeModal, templateStorage, selectedTemplate, setSelectedTemplate, templateList, setTemplateList, templates, templatesImport, setTemplates, cancel }) {
const [addDeleteTemplate, setAddDeleteTemplate] = useState(false);
const [templateDuplicate, setTemplateDuplicate] = useState(false);
const [newTemplateName, setNewTemplateName] = useState(undefined);

function getArrObjByName(array,name,getIndex=false) {
Expand Down Expand Up @@ -2709,6 +2710,25 @@
})
setAddDeleteTemplate(true)
}
async function handleInstructTemplateDuplicate() {
const index = templateList.findIndex(obj => obj.name === selectedTemplate)
const reselectTemplate = templateList[index == -1 ? 0 : index]?.nameNew
await updateTemplateDB()
await setTemplateDuplicate(reselectTemplate + " (Duplicate)")
setTemplates((prevState) => {
var newState = {
...prevState
}
newState[reselectTemplate + " (Duplicate)"] = {
"sysPre": templates[selectedTemplate]?.sysPre,
"sysSuf": templates[selectedTemplate]?.sysSuf,
"instPre": templates[selectedTemplate]?.instPre,
"instSuf": templates[selectedTemplate]?.instSuf,
"fimTemplate": templates[selectedTemplate]?.fimTemplate,
}
return { ...newState }
})
}

async function handleInstructTemplateDelete(name) {
if (Object.keys(templates).length < 2)
Expand Down Expand Up @@ -2749,7 +2769,12 @@
setTemplateList(list)
if (reselectTemplate)
setSelectedTemplate(reselectTemplate)
if (templateDuplicate) {
setSelectedTemplate(templateDuplicate)
setTemplateDuplicate(false)
}
}, [templates,selectedTemplate,templatesImport]);

useEffect(() => {
if (!addDeleteTemplate)
return
Expand Down Expand Up @@ -2887,6 +2912,13 @@
value=${newTemplateName ?? selectedTemplate}
onValueChange=${setSelectedTemplate}
options=${templateList}/>
<button
title="Duplicate Currently Selected Instruct Template"
disabled=${!!cancel}
class="hbox-button"
onClick=${() => handleInstructTemplateDuplicate()}>
Duplicate
</button>
<button
title="Add Instruct Template"
disabled=${!!cancel}
Expand Down

0 comments on commit b0a0a5a

Please sign in to comment.