Skip to content

Commit

Permalink
Hook up prerequisite dialog to its list
Browse files Browse the repository at this point in the history
  • Loading branch information
Mabi19 committed Mar 14, 2024
1 parent c31de57 commit 42abdb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/template-editor/TemplateEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</table>
</div>

<TemplateEditorPane v-if="template" :template :reverse-deps ref="goalDialog" />
<TemplateEditorPane v-if="template" :template ref="goalDialog" />
</div>
</Teleport>
<Body class="overlay-hack-active" v-if="template != null" />
Expand Down
26 changes: 21 additions & 5 deletions components/template-editor/TemplateEditorPrerequisites.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ const type = computed(() => {
}
});
// Modify the data in-place, then pass it up
function passUpdate(idx: number, newData: Prerequisite) {
// To simplify data flow, all updates are performed on copies and propagated up,
// so that the prerequisites are only set in one place.
// This helper function allows for modifying the data easily under this paradigm.
function updateData(handler: (workCopy: Prerequisite[]) => void) {
// get the list of children
let workCopy: Prerequisite[];
if (props.value.all) {
Expand All @@ -57,8 +59,8 @@ function passUpdate(idx: number, newData: Prerequisite) {
// clone
workCopy = JSON.parse(JSON.stringify(workCopy));
// swap out the data
workCopy.splice(idx, 1, newData);
// call handler
handler(workCopy);
// wrap it again
if (props.value.all) {
Expand All @@ -68,6 +70,14 @@ function passUpdate(idx: number, newData: Prerequisite) {
}
}
// Modify the data in-place, then pass it up
function passUpdate(idx: number, newData: Prerequisite) {
updateData((workCopy) => {
// swap out the data in our copy
workCopy[idx] = newData;
});
}
function createFolder() {
const newData = JSON.parse(JSON.stringify(props.value));
if (newData.all) {
Expand All @@ -81,7 +91,13 @@ function createFolder() {
const triggerPrerequisiteDialog = inject(prerequisiteCreationFunc)!;
function createPrerequisite() {
triggerPrerequisiteDialog();
triggerPrerequisiteDialog()
.then((newVal) => {
updateData((workCopy) => {
workCopy.push(newVal);
});
})
.catch(/* do nothing */);
}
</script>
Expand Down

0 comments on commit 42abdb1

Please sign in to comment.