Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcantondahmen committed Dec 21, 2024
1 parent 8685fbf commit da6c00e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions automad/src/client/admin/components/Forms/SharedComponentsForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,20 @@ export class SharedComponentsFormComponent extends FormComponent {
return true;
}

/**
* This is false until the first request was made and the store components are rendered
* in order to prevent submitting an empty form and therefore deleting the components store.
*/
private isInitialized = false;

/**
* The form data object.
*/
get formData(): KeyValueMap {
if (!this.isInitialized) {
return {};
}

const componentEditors = queryAll<SharedComponentEditorComponent>(
SharedComponentEditorComponent.TAG_NAME,
this
Expand Down Expand Up @@ -166,6 +176,8 @@ export class SharedComponentsFormComponent extends FormComponent {
this.submit();
},
});

this.isInitialized = true;
}

fire(EventName.contentSaved);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static function data(): Response {
$components = Request::post('components');
$SharedComponentStore = new SharedComponentStore();

if (!empty($components) && is_array($components)) {
if (isset($components) && is_array($components)) {
if ($SharedComponentStore->setState(PublicationState::DRAFT, array('components' => $components))->save()) {
return $Response;
}
Expand Down
4 changes: 4 additions & 0 deletions shared/components
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"draft": []
}

0 comments on commit da6c00e

Please sign in to comment.