Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions src/Widget/ContinueWith.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,46 @@ class ContinueWith extends BaseHtmlElement
protected $defaultAttributes = ['class' => 'continue-with'];

/** @var Url */
protected $url;
protected Url $url;

/** @var Filter\Rule|callable */
protected $filter;

/** @var string */
protected $title;
/** @var ?string */
protected ?string $title;

public function __construct(Url $url, $filter)
/** @var ?bool Whether the current query has results */
protected ?bool $hasResults;

/**
* Whether the current query has results
*
* @return bool
*/
public function hasResults(): bool
{
return $this->hasResults;
}

/**
* Set whether the current query has results
*
* @param bool $hasResults
*
* @return ContinueWith
*/
public function setHasResults(bool $hasResults): ContinueWith
{
$this->hasResults = $hasResults;

return $this;
}

public function __construct(Url $url, $filter, bool $hasResults)
{
$this->url = $url;
$this->filter = $filter;
$this->hasResults = $hasResults;
}

/**
Expand All @@ -40,32 +68,32 @@ public function __construct(Url $url, $filter)
*
* @return $this
*/
public function setTitle($title)
public function setTitle(string $title): static
{
$this->title = $title;

return $this;
}

public function assemble()
public function assemble(): void
{
$filter = $this->filter;
if (is_callable($filter)) {
$filter = $filter(); /** @var Filter\Rule $filter */
}

$baseFilter = $this->url->getFilter();
if ($baseFilter && ((! $baseFilter instanceof Filter\Chain) || ! $baseFilter->isEmpty())) {
$filter = Filter::all($baseFilter, $filter);
}

if ($filter instanceof Filter\Chain && $filter->isEmpty()) {
if (! $this->hasResults || ($filter instanceof Filter\Chain && $filter->isEmpty())) {
$this->addHtml(new HtmlElement(
'span',
Attributes::create(['class' => ['control-button', 'disabled']]),
new Icon('share')
));
} else {
$baseFilter = $this->url->getFilter();
if ($baseFilter && ((! $baseFilter instanceof Filter\Chain) || ! $baseFilter->isEmpty())) {
$filter = Filter::all($baseFilter, $filter);
}

$this->addHtml(new ActionLink(
null,
$this->url->setFilter($filter),
Expand Down
Loading