Skip to content

Commit

Permalink
changeset working except video sections
Browse files Browse the repository at this point in the history
  • Loading branch information
mono424 committed Aug 29, 2023
1 parent e36890d commit fcf15c2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
17 changes: 17 additions & 0 deletions web/assets/init-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ document.addEventListener("alpine:init", () => {
changeSet.listen(onChangeSetUpdateHandler);
el.addEventListener('change', changeHandler);

cleanup(() => {
changeSet.removeListener(onChangeSetUpdateHandler);
el.removeEventListener('change', changeHandler)
})
} else if (el.type === "checkbox") {
const changeHandler = (e) => {
changeSet.patch(fieldName, e.target.checked);
};

const onChangeSetUpdateHandler = (data) => {
el.checked = !!data[fieldName];
};

changeSet.listen(onChangeSetUpdateHandler);
el.addEventListener('change', changeHandler)
el.checked = changeSet.get()[fieldName];

cleanup(() => {
changeSet.removeListener(onChangeSetUpdateHandler);
el.removeEventListener('change', changeHandler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,7 @@
<div class="mt-6 flex items-center justify-between">
<section class="flex items-center py-1 px-3">
<label class="relative inline-flex items-center cursor-pointer">
<input type="checkbox" value="" class="sr-only peer" @change="updateIsDirty()"
x-model="lectureData.newIsChatEnabled">
<input type="checkbox" name="isChatEnabled" class="sr-only peer" x-bind-change-set="changeSet" />
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-600
dark:peer-focus:ring-indigo-600 rounded-full peer dark:bg-gray-600 peer-checked:after:translate-x-full
peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px]
Expand All @@ -392,15 +391,15 @@
</label>
</section>
<div>
<button :disabled="lectureData.isSaving" @click="discardEdit();"
<button :disabled="isSaving" @click="discardEdit();"
class="px-8 py-3 text-2 text-white rounded bg-indigo-500/70 hover:bg-indigo-500/90 dark:bg-indigo-500/10 disabled:opacity-20 dark:hover:bg-indigo-500/20 mr-4">
Discard Changes
</button>
<button
@click="saveEdit();"
:disabled="!lectureData.isDirty || lectureData.isSaving"
:disabled="!isDirty || isSaving"
class="px-8 py-3 text-2 rounded text-white bg-indigo-500 hover:bg-indigo-600 disabled:opacity-20 disabled:hover:bg-indigo-500"
x-text="lectureData.isSaving ? 'loading ...' : (uiEditMode === admin.UIEditMode.single ? 'Save Lecture' : 'Save Series')"
x-text="isSaving ? 'loading ...' : (uiEditMode === admin.UIEditMode.single ? 'Save Lecture' : 'Save Series')"
></button>
</div>
</div>
Expand Down
8 changes: 7 additions & 1 deletion web/ts/edit-course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export function lectureEditor(lecture: Lecture): AlpineComponent {
lastErrors: [] as string[],
uiEditMode: UIEditMode.none,
isDirty: false,
isSaving: false,

// Lecture Data
changeSet: null,
Expand Down Expand Up @@ -163,7 +164,7 @@ export function lectureEditor(lecture: Lecture): AlpineComponent {

getVideoFile(key: string): File {
return this.lectureData[key];
}
},

/**
* Opens the series lecture editor UI
Expand All @@ -183,6 +184,11 @@ export function lectureEditor(lecture: Lecture): AlpineComponent {
this.uiEditMode = UIEditMode.single;
},

discardEdit() {
this.changeSet.reset();
this.uiEditMode = UIEditMode.none;
}

} as AlpineComponent;
}

Expand Down

0 comments on commit fcf15c2

Please sign in to comment.