Skip to content

Commit

Permalink
fixing live preview
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Nov 29, 2023
1 parent bab7651 commit 3bbc185
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/actions/EditComponentData.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ public function handle(Component $component, array $data)
return $component;
}

$component
// Touch the component so we log that the data has updated
$component->touch();

// Save the data
$componentData = $component
->maybeDuplicateData()
->merge($data)
->save();
Expand Down
5 changes: 5 additions & 0 deletions src/base/ComponentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ public function render(array $variables = []): string

abstract public function getTemplatePath(): string;

public function hasSlots(): bool
{
return $this->getSlotDefinitions()->isNotEmpty();
}

/**
* @return Collection<SlotDefinition>
*/
Expand Down
9 changes: 9 additions & 0 deletions src/models/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use craft\base\ElementInterface;
use craft\base\FieldInterface;
use craft\db\ActiveQuery;
use craft\helpers\DateTimeHelper;
use Illuminate\Support\Collection;
use markhuot\keystone\actions\GetComponentType;
use markhuot\keystone\actions\NormalizeFieldDataForComponent;
Expand Down Expand Up @@ -144,6 +145,14 @@ public function refresh()
return parent::refresh();
}

public function touch()
{
$this->dateUpdated = DateTimeHelper::now();
$this->save();

return $this;
}

public function __get($name)
{
$value = parent::__get($name);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/field.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{% endif %}
<ul style="margin-left: 2rem;">
{% for child in component.getSlot(slot.name) %}
<li class="k-relative {{ child.isCollapsed() ? 'k-collapsed' }}"
<li class="k-relative {{ child.getType().hasSlots() and child.isCollapsed() ? 'k-collapsed' }}"
draggable="true"
data-draggable="{{ child.id }}"
data-draggable-type="{{ child.getType().getHandle() }}"
Expand Down

0 comments on commit 3bbc185

Please sign in to comment.