Skip to content

Commit

Permalink
Replace an include with TalksList component
Browse files Browse the repository at this point in the history
  • Loading branch information
spaze committed Aug 12, 2023
1 parent 7cf09ce commit 6e0fc41
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 16 deletions.
20 changes: 20 additions & 0 deletions site/app/Talks/TalksList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Talks;

use MichalSpacekCz\Application\UiControl;

class TalksList extends UiControl
{

/**
* @param list<Talk> $talks
*/
public function render(array $talks): void
{
$this->template->talks = $talks;
$this->template->render(__DIR__ . '/talksList.latte');
}

}
11 changes: 11 additions & 0 deletions site/app/Talks/TalksListFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
declare(strict_types = 1);

namespace MichalSpacekCz\Talks;

interface TalksListFactory
{

public function create(): TalksList;

}
7 changes: 7 additions & 0 deletions site/app/Talks/talksList.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{varType MichalSpacekCz\Talks\Talk[] $talks}
<p class="indent" n:foreach="$talks as $talk">
<a href="{plink Talks:talk $talk->getAction()}" n:tag-if="$talk->getAction()"><strong>{$talk->getTitle()}</strong></a><br>
<small><strong class="date">{$talk->getDate()|localeDay}</strong>, {$talk->getEvent()}{if $talk->getDuration()} ({_messages.talks.durationshort|format:$talk->getDuration()}){/if}</small>
<span n:if="$talk->isHasSlides()" title="{_messages.label.slides}">{icon images}</span>
<span n:if="$talk->getVideo()->getVideoHref()" title="{_messages.label.videorecording}">{icon camera-video}</span>
</p>
9 changes: 9 additions & 0 deletions site/app/Www/Presenters/HomepagePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use MichalSpacekCz\Articles\ArticleSummaryFactory;
use MichalSpacekCz\Interviews\Interviews;
use MichalSpacekCz\Talks\Talks;
use MichalSpacekCz\Talks\TalksList;
use MichalSpacekCz\Talks\TalksListFactory;
use MichalSpacekCz\Training\Company\CompanyTrainings;
use MichalSpacekCz\Training\DateList\UpcomingTrainingDatesList;
use MichalSpacekCz\Training\DateList\UpcomingTrainingDatesListFactory;
Expand All @@ -24,6 +26,7 @@ public function __construct(
private readonly DiscontinuedTrainings $discontinuedTrainings,
private readonly UpcomingTrainingDatesListFactory $upcomingTrainingDatesListFactory,
private readonly ArticleSummaryFactory $articleSummaryFactory,
private readonly TalksListFactory $talksListFactory,
) {
parent::__construct();
}
Expand Down Expand Up @@ -53,4 +56,10 @@ protected function createComponentArticleSummary(): ArticleSummary
return $this->articleSummaryFactory->create();
}


protected function createComponentTalksList(string $name): TalksList
{
return $this->talksListFactory->create();
}

}
9 changes: 9 additions & 0 deletions site/app/Www/Presenters/TalksPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use MichalSpacekCz\Talks\Exceptions\UnknownSlideException;
use MichalSpacekCz\Talks\Talks;
use MichalSpacekCz\Talks\TalkSlides;
use MichalSpacekCz\Talks\TalksList;
use MichalSpacekCz\Talks\TalksListFactory;
use MichalSpacekCz\Training\Dates\UpcomingTrainingDates;
use Nette\Application\BadRequestException;
use Nette\Application\UI\InvalidLinkException;
Expand All @@ -20,6 +22,7 @@ public function __construct(
private readonly Talks $talks,
private readonly TalkSlides $talkSlides,
private readonly UpcomingTrainingDates $upcomingTrainingDates,
private readonly TalksListFactory $talksListFactory,
) {
parent::__construct();
}
Expand Down Expand Up @@ -79,4 +82,10 @@ public function actionTalk(string $name, ?string $slide = null): void
$this->template->slidesPlatform = $talk->getSlidesHref() ? SlidesPlatform::tryFromUrl($talk->getSlidesHref())?->getName() : null;
}


protected function createComponentTalksList(string $name): TalksList
{
return $this->talksListFactory->create();
}

}
8 changes: 2 additions & 6 deletions site/app/Www/Presenters/templates/Homepage/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
</ul>
<h3>{_messages.label.upcomingtalks}</h3>
{if $upcomingTalks}
<p class="indent" n:foreach="$upcomingTalks as $talk">
{include "../Talks/common/itemTalk.latte", talk: $talk}
</p>
{control talksList $upcomingTalks}
<p>{_messages.talks.atyourevent.upcoming|format:'[email protected]'}</p>
{else}
<p>{_messages.talks.atyourevent.noupcoming|format:'[email protected]'}</p>
{/if}
<h3>{_messages.label.pasttalks}</h3>
<p class="indent" n:foreach="$talks as $talk">
{include "../Talks/common/itemTalk.latte", talk: $talk}
</p>
{control talksList $talks}
<p><a n:href="Talks:">{_messages.label.alltalks}</a></p>
<hr>
<h2 id="{_html.id.interviews}">{_messages.label.myinterviews}</h2>
Expand Down
4 changes: 0 additions & 4 deletions site/app/Www/Presenters/templates/Talks/common/itemTalk.latte

This file was deleted.

8 changes: 2 additions & 6 deletions site/app/Www/Presenters/templates/Talks/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
</ul>
<h2>{_messages.label.upcomingtalks}</h2>
{if $upcomingTalks}
<p n:foreach="$upcomingTalks as $talk">
{include "common/itemTalk.latte", talk: $talk}
</p>
{control talksList $upcomingTalks}
<p>{_messages.talks.atyourevent.upcoming|format:'[email protected]'}</p>
{else}
<p>{_messages.talks.atyourevent.noupcoming|format:'[email protected]'}</p>
Expand All @@ -24,9 +22,7 @@
</p>
{foreach $talks as $year => $items}
<h3>{$year}</h3>
<p class="indent" n:foreach="$items as $talk">
{include "common/itemTalk.latte", talk: $talk}
</p>
{control talksList $items}
{/foreach}
{_messages.talks.more|format:'https://www.slideshare.net/spaze/presentations', 'https://speakerdeck.com/u/spaze'}
{/define}
1 change: 1 addition & 0 deletions site/config/services.neon
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ services:
- MichalSpacekCz\Talks\TalkInputsFactory(videoThumbnails: @talkVideoThumbnails)
- MichalSpacekCz\Talks\Talks
- MichalSpacekCz\Talks\TalkSlides
- MichalSpacekCz\Talks\TalksListFactory
- MichalSpacekCz\Templating\Filters
latte.templateFactory:
create: MichalSpacekCz\Templating\TemplateFactory()
Expand Down

0 comments on commit 6e0fc41

Please sign in to comment.