Skip to content

Commit 8d9cdf2

Browse files
rozsivalf3l1x
authored andcommitted
refactor(WIP): get rid of wavevision/props-control in favor of built-in nette controls
1 parent 8f03dfe commit 8d9cdf2

40 files changed

Lines changed: 190 additions & 407 deletions

File tree

app/model/UI/BaseRenderControl.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
namespace App\Model\UI;
44

5+
use Nette\Application\UI\Template;
56
use Nette\Bridges\ApplicationLatte\DefaultTemplate;
6-
use Wavevision\PropsControl\BaseControl;
77

88
/**
99
* @property-read DefaultTemplate $template
1010
*/
1111
abstract class BaseRenderControl extends BaseControl
1212
{
1313

14-
public function render(): void
14+
protected const DEFAULT_TEMPLATE = 'default';
15+
16+
protected function createTemplate(): Template
1517
{
16-
$this->beforeRender();
17-
$this->template->render();
18+
$template = parent::createTemplate();
19+
$template->setFile($this->getTemplateFile());
20+
return $template;
1821
}
1922

20-
protected function beforeRender(): void
23+
final protected function getTemplateFile(?string $template = null): string
2124
{
25+
if (!$template) {
26+
$template = static::DEFAULT_TEMPLATE;
27+
}
28+
$file = (string)$this->getReflection()->getFileName();
29+
return dirname($file) . "/templates/$template.latte";
2230
}
2331

2432
}

app/modules/Front/Base/Controls/AddonList/Avatar/AvatarProps.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/modules/Front/Base/Controls/AddonList/Avatar/Control.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
namespace App\Modules\Front\Base\Controls\AddonList\Avatar;
44

5-
use Wavevision\PropsControl\PropsControl;
5+
use App\Model\Database\ORM\Addon\Addon;
6+
use App\Model\UI\BaseRenderControl;
67

7-
class Control extends PropsControl
8+
class Control extends BaseRenderControl
89
{
910

10-
protected function getPropsClass(): string
11+
public function render(Addon $addon, bool $linkToGitHub = false, bool $small = false): void
1112
{
12-
return AvatarProps::class;
13+
$this->template->setParameters([
14+
'addon' => $addon,
15+
'linkToGitHub' => $linkToGitHub,
16+
'small' => $small,
17+
])->render();
1318
}
1419

1520
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{templateType Wavevision\PropsControl\PropsControlTemplate}
21
{varType App\Model\Database\ORM\Addon\Addon $addon}
3-
{var $addon = $props->get(App\Modules\Front\Base\Controls\AddonList\Avatar\AvatarProps::ADDON)}
4-
<a href="{if $props->linkToGithub}{$addon->github->linker->getRepoUrl()}{else}{plink Addon:detail, slug => $addon->id}{/if}"
2+
{varType bool $linkToGithub}
3+
{varType bool $small}
4+
<a href="{if $linkToGithub}{$addon->github->linker->getRepoUrl()}{else}{plink Addon:detail, slug => $addon->id}{/if}"
55
class="flex-shrink-0 mr-4"
66
>
77
<img loading="lazy" alt="{$addon->author}"
8-
src="{avatar $addon->author}" n:class="'w-8 h-8 rounded-full', !$props->small ? 'lg:h-16 lg:w-16'">
8+
src="{avatar $addon->author}" n:class="'w-8 h-8 rounded-full', !$small ? 'lg:h-16 lg:w-16'">
99
</a>

app/modules/Front/Base/Controls/AddonList/Description/Control.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22

33
namespace App\Modules\Front\Base\Controls\AddonList\Description;
44

5-
use Wavevision\PropsControl\PropsControl;
5+
use App\Model\Database\ORM\Addon\Addon;
6+
use App\Model\UI\BaseRenderControl;
67

7-
class Control extends PropsControl
8+
class Control extends BaseRenderControl
89
{
910

10-
protected function getPropsClass(): string
11+
public function render(Addon $addon): void
1112
{
12-
return DescriptionProps::class;
13+
$this->template->setParameters(['addon' => $addon])->render();
1314
}
1415

1516
}

app/modules/Front/Base/Controls/AddonList/Description/DescriptionProps.php

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{templateType Wavevision\PropsControl\PropsControlTemplate}
2-
<p class="text-sm text-gray-700">{$props->addon->github->description|truncate:150|striptags|emojify|noescape}</p>
1+
{varType App\Model\Database\ORM\Addon\Addon $addon}
2+
<p class="text-sm text-gray-700">{$addon->github->description|truncate:150|striptags|emojify|noescape}</p>

app/modules/Front/Base/Controls/AddonList/Name/Control.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,21 @@
44

55
use App\Model\Database\ORM\Addon\Addon;
66
use App\Model\Database\ORM\GithubRelease\GithubRelease;
7-
use App\Model\UI\BasePropsControl;
7+
use App\Model\UI\BaseRenderControl;
88
use Nextras\Orm\Collection\ICollection;
9-
use Wavevision\PropsControl\ValidProps;
109

11-
class Control extends BasePropsControl
10+
class Control extends BaseRenderControl
1211
{
1312

14-
protected function getPropsClass(): string
13+
public function render(Addon $addon, bool $linkToGitHub = false, bool $inverseTag = false): void
1514
{
16-
return NameProps::class;
17-
}
18-
19-
protected function beforeRender(ValidProps $props): void
20-
{
21-
parent::beforeRender($props);
22-
/** @var Addon $addon */
23-
$addon = $props->get(NameProps::ADDON);
24-
$this->template->setParameters(['addon' => $addon]);
15+
$this->template->setParameters(['addon' => $addon, 'linkToGitHub' => $linkToGitHub, 'inverseTag' => $inverseTag]);
2516
if ($github = $addon->github) {
2617
/** @var GithubRelease|null $release */
2718
$release = $github->releases->get()->orderBy(['crawledAt' => ICollection::DESC])->fetch();
2819
$this->template->setParameters(['release' => $release]);
2920
}
21+
$this->template->render();
3022
}
3123

3224
}

app/modules/Front/Base/Controls/AddonList/Name/NameProps.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

app/modules/Front/Base/Controls/AddonList/Name/templates/default.latte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
{templateType Wavevision\PropsControl\PropsControlTemplate}
21
{varType App\Model\Database\ORM\Addon\Addon $addon}
32
{varType App\Model\Database\ORM\GithubRelease\GithubRelease|null $release}
3+
{varType bool $linkToGitHub}
4+
{varType bool $inverseTag}
45
<h3 class="inline-block mb-2 text-lg font-bold leading-tight text-teal-800 font-headers xl:text-xl align-middle">
5-
{if $props->linkToGithub}
6+
{if $linkToGitHub}
67
<a data-ga="1" data-event="click" data-category="header" data-action="repo-author"
78
title="Show all addons by {$addon->author}" href="{plink Index:author, slug => $addon->author}"
89
>
@@ -19,7 +20,7 @@
1920
{$addon->author} / {$addon->name}
2021
</a>
2122
{/if}
22-
<span n:if="$release" n:class="'relative inline-block px-2 text-sm font-normal text-blue-700 rounded-full -mt-1 align-middle', $props->inverseTag ? 'bg-white' :'bg-blue-100'">
23+
<span n:if="$release" n:class="'relative inline-block px-2 text-sm font-normal text-blue-700 rounded-full -mt-1 align-middle', $inverseTag ? 'bg-white' :'bg-blue-100'">
2324
{$release->tag}
2425
</span>
2526
</h3>

0 commit comments

Comments
 (0)