Skip to content

Commit

Permalink
feat(content): allow for manual content saving
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Dec 10, 2024
1 parent 5032ca2 commit de0a111
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/composables/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,24 @@ export function useContent() {
});

/**
* Updates the form values of the current view without saving them.
* Updates the form values of the current view.
*
* @remarks
* In Kirby 5, the native `window.panel.content.update()` method immediately saves the changes to the backend storage. This can be prevented by passing `false` as the second argument.
* In Kirby 4, content changes are only stored in the Vuex store and do not need to be saved explicitly.
*/
const update = (
values?: Record<string, any>,
): Record<string, any> | undefined => {
const update = async (values?: Record<string, any>, save = true) => {
if (!_isKirby5 && values) {
for (const [key, value] of Object.entries(values)) {
store.dispatch("content/update", [key, value]);
}
}

return content.merge(values);
const viewContent = content.merge(values);

if (save) {
await content.save(viewContent);
}
};

return {
Expand Down

0 comments on commit de0a111

Please sign in to comment.