Skip to content

Commit

Permalink
imp: Group news and read links by dates
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Mar 25, 2024
1 parent e671774 commit f83a22d
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 66 deletions.
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
46 changes: 25 additions & 21 deletions locales/fr_FR/LC_MESSAGES/main.po
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
msgid ""
msgstr ""
"Project-Id-Version: flusio\n"
"POT-Creation-Date: 2024-03-24 20:14+0100\n"
"PO-Revision-Date: 2024-03-24 20:14+0100\n"
"POT-Creation-Date: 2024-03-25 15:13+0100\n"
"PO-Revision-Date: 2024-03-25 15:13+0100\n"
"Last-Translator: Marien Fressinaud <[email protected]>\n"
"Language-Team: \n"
"Language: fr_FR\n"
Expand Down Expand Up @@ -50,7 +50,7 @@ msgstr "Afficher"
#: controllers/Feeds.php:107 controllers/Groups.php:90
#: controllers/Links.php:270 controllers/Links.php:442
#: controllers/Mastodon.php:211 controllers/Mastodon.php:297
#: controllers/News.php:75 controllers/Passwords.php:89
#: controllers/News.php:79 controllers/Passwords.php:89
#: controllers/Passwords.php:192 controllers/Registrations.php:103
#: controllers/Sessions.php:85 controllers/Support.php:70
#: controllers/collections/Filters.php:105
Expand Down Expand Up @@ -455,28 +455,28 @@ msgstr "plateforme inconnue"
msgid "%s on %s"
msgstr "%s sur %s"

#: utils/view_helpers.php:102
#: utils/view_helpers.php:81
msgid "< 1 min"
msgstr "< 1 min"

#: utils/view_helpers.php:104
#: utils/view_helpers.php:83
#, php-format
msgid "%s&nbsp;min"
msgstr "%s&nbsp;min"

#: utils/view_helpers.php:222
#: utils/view_helpers.php:201
msgid "There are no relevant links to suggest at this time."
msgstr "Il n'y a aucun lien pertinent à vous proposer pour le moment."

#: utils/view_helpers.php:224
#: utils/view_helpers.php:203
#, php-format
msgid ""
"You can add links to <a href=\"%s\">your bookmarks</a> to read them later."
msgstr ""
"Vous pouvez placer des liens dans <a href=\"%s\">vos signets</a> pour les "
"lire plus tard."

#: utils/view_helpers.php:254 views/links/show.phtml:73
#: utils/view_helpers.php:233 views/links/show.phtml:73
msgid "you"
msgstr "vous"

Expand Down Expand Up @@ -1143,7 +1143,7 @@ msgstr "Régler pour le journal"
msgid "Copy the link"
msgstr "Copier le lien"

#: views/collections/show_public.phtml:165 views/news/index.phtml:52
#: views/collections/show_public.phtml:165 views/news/index.phtml:68
msgid "Mark all as read"
msgstr "Tout marquer comme lu"

Expand Down Expand Up @@ -2110,57 +2110,61 @@ msgstr "Toujours rien&nbsp;? Avez-vous vérifié votre spam&nbsp;?"
msgid "Didn’t receive the email? Resend it"
msgstr "Courriel non reçu ? Renvoyer"

#: views/news/index.phtml:41
#: views/news/index.phtml:21 views/read/index.phtml:38
msgid "Today"
msgstr "Aujourd’hui"

#: views/news/index.phtml:57
msgid "Empty the news"
msgstr "Vider le journal"

#: views/news/index.phtml:62
#: views/news/index.phtml:78
msgid "Read the links later"
msgstr "Lire les liens plus tard"

#: views/news/index.phtml:71
#: views/news/index.phtml:87
msgid ""
"You’ll remove all the news links, this action cannot be canceled. Are you "
"sure?"
msgstr ""
"Vous allez retirer tous les liens du journal, cette action ne peut pas être "
"annulée. Confirmez-vous ?"

#: views/news/index.phtml:79
#: views/news/index.phtml:95
msgid "Never see the links again"
msgstr "Ne plus revoir les liens"

#: views/news/index.phtml:87
#: views/news/index.phtml:103
msgid ""
"Fill your news feed with the content published by the feeds that you follow."
msgstr ""
"Remplissez votre journal avec le contenu publié par les flux que vous suivez."

#: views/news/index.phtml:101
#: views/news/index.phtml:117
msgid "Refresh the news"
msgstr "Rafraichir le journal"

#: views/news/index.phtml:106
#: views/news/index.phtml:122
msgid "Fill the news with…"
msgstr "Remplissez votre journal avec…"

#: views/news/index.phtml:129
#: views/news/index.phtml:145
msgid "the latest publications"
msgstr "les dernières publications"

#: views/news/index.phtml:130
#: views/news/index.phtml:146
msgid "from your followed feeds"
msgstr "depuis vos flux suivis"

#: views/news/index.phtml:145
#: views/news/index.phtml:161
msgid "3 links of -10 minutes"
msgstr "3 liens de -10 minutes"

#: views/news/index.phtml:146 views/news/index.phtml:162
#: views/news/index.phtml:162 views/news/index.phtml:178
msgid "from your bookmarks"
msgstr "depuis vos signets"

#: views/news/index.phtml:161
#: views/news/index.phtml:177
msgid "1 link of +10 minutes"
msgstr "1 lien de +10 minutes"

Expand Down
8 changes: 6 additions & 2 deletions src/controllers/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use flusio\auth;
use flusio\models;
use flusio\services;
use flusio\utils;

/**
* Handle the requests related to the news.
Expand All @@ -33,9 +34,12 @@ public function index(): Response
}

$news = $user->news();
$links = $news->links(['published_at', 'number_comments']);
$links_timeline = new utils\LinksTimeline($links);

return Response::ok('news/index.phtml', [
'news' => $news,
'links' => $news->links(['published_at', 'number_comments']),
'links_timeline' => $links_timeline,
'no_news' => \Minz\Flash::pop('no_news'),
]);
}
Expand Down Expand Up @@ -70,7 +74,7 @@ public function create(Request $request): Response
if (!\Minz\Csrf::validate($csrf)) {
return Response::badRequest('news/index.phtml', [
'news' => $news,
'links' => [],
'links_timeline' => new utils\LinksTimeline([]),
'no_news' => false,
'error' => _('A security verification failed: you should retry to submit the form.'),
]);
Expand Down
19 changes: 11 additions & 8 deletions src/controllers/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ public function index(Request $request): Response
]);
}

$links = $read_list->links(
['published_at', 'number_comments'],
[
'offset' => $pagination->currentOffset(),
'limit' => $pagination->numberPerPage(),
'context_user_id' => $user->id,
]
);
$links_timeline = new utils\LinksTimeline($links);

return Response::ok('read/index.phtml', [
'collection' => $read_list,
'links' => $read_list->links(
['published_at', 'number_comments'],
[
'offset' => $pagination->currentOffset(),
'limit' => $pagination->numberPerPage(),
'context_user_id' => $user->id,
]
),
'links_timeline' => $links_timeline,
'pagination' => $pagination,
]);
}
Expand Down
52 changes: 52 additions & 0 deletions src/utils/LinksTimeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace flusio\utils;

use flusio\models;

/**
* A class to organise a list of links in a timeline (i.e. grouped by dates).
*
* @author Marien Fressinaud <[email protected]>
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL
*/
class LinksTimeline
{
/** @var array<string, LinksTimeline\DateGroup> */
private array $dates_groups = [];

/**
* @param models\Link[] $links
*/
public function __construct(array $links)
{
foreach ($links as $link) {
if (!$link->published_at) {
continue;
}

$date_key = $link->published_at->format('Y-m-d');
if (isset($this->dates_groups[$date_key])) {
$date_group = $this->dates_groups[$date_key];
} else {
$date_group = new LinksTimeline\DateGroup($link->published_at);
$this->dates_groups[$date_key] = $date_group;
}

$date_group->links[] = $link;
}
}

/**
* @return array<string, LinksTimeline\DateGroup>
*/
public function datesGroups(): array
{
return $this->dates_groups;
}

public function empty(): bool
{
return empty($this->dates_groups);
}
}
28 changes: 28 additions & 0 deletions src/utils/LinksTimeline/DateGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace flusio\utils\LinksTimeline;

use flusio\models;

/**
* @author Marien Fressinaud <[email protected]>
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL
*/
class DateGroup
{
public \DateTimeImmutable $date;

/** @var models\Link[] */
public array $links = [];

public function __construct(\DateTimeImmutable $date)
{
$this->date = $date;
}

public function isToday(): bool
{
$today = \Minz\Time::now();
return $this->date->format('Y-m-d') === $today->format('Y-m-d');
}
}
48 changes: 32 additions & 16 deletions src/views/news/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,38 @@
<h1><?= _('News') ?></h1>
</div>

<?php if ($links): ?>
<div class="cards cards--centered">
<?php foreach ($links as $link): ?>
<?= $this->include('links/_link.phtml', [
'link' => $link,
'from' => \Minz\Url::for('news'),
'display_edit' => true,
'display_repair' => true,
'display_via' => true,
'display_read_later' => true,
'display_mark_as_read' => true,
'display_never' => true,
'storing_must_mark_as_read' => true,
]); ?>
<?php endforeach; ?>
</div>
<?php if (!$links_timeline->empty()): ?>
<?php foreach ($links_timeline->datesGroups() as $date_group): ?>
<section class="group">
<header class="group__header">
<h2 class="group__title">
<?php if ($date_group->isToday()): ?>
<?= _('Today') ?>
<?php endif; ?>

<?= _date($date_group->date, 'dd MMMM') ?>
</h2>

<div class="group__separator"></div>
</header>

<div class="cards">
<?php foreach ($date_group->links as $link): ?>
<?= $this->include('links/_link.phtml', [
'link' => $link,
'from' => \Minz\Url::for('news'),
'display_edit' => true,
'display_repair' => true,
'display_via' => true,
'display_read_later' => true,
'display_mark_as_read' => true,
'display_never' => true,
'storing_must_mark_as_read' => true,
]); ?>
<?php endforeach; ?>
</div>
</section>
<?php endforeach; ?>

<div class="news__postpone">
<details
Expand Down
50 changes: 31 additions & 19 deletions src/views/read/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,37 @@
</div>
<?php endif; ?>

<div class="cards">
<?php foreach ($links as $link): ?>
<?= $this->include('links/_link.phtml', [
'link' => $link,
'from' => \Minz\Url::for('read list', $current_url_params),
'display_via' => $link->via_type !== 'bookmarks',
'display_comments' => true,
'display_edit' => true,
'display_repair' => true,
'display_delete' => true,
'display_read_later' => 'auto',
'display_mark_as_unread' => true,
]); ?>
<?php endforeach; ?>

<?php for ($i = 0; $i < max(3, (3 - (count($links) % 3))); $i++): ?>
<div class="card card--shadow no-mobile"></div>
<?php endfor; ?>
</div>
<?php foreach ($links_timeline->datesGroups() as $date_group): ?>
<section class="group">
<header class="group__header">
<h2 class="group__title">
<?php if ($date_group->isToday()): ?>
<?= _('Today') ?>
<?php endif; ?>

<?= _date($date_group->date, 'dd MMMM') ?>
</h2>

<div class="group__separator"></div>
</header>

<div class="cards">
<?php foreach ($date_group->links as $link): ?>
<?= $this->include('links/_link.phtml', [
'link' => $link,
'from' => \Minz\Url::for('read list', $current_url_params),
'display_via' => $link->via_type !== 'bookmarks',
'display_comments' => true,
'display_edit' => true,
'display_repair' => true,
'display_delete' => true,
'display_read_later' => 'auto',
'display_mark_as_unread' => true,
]); ?>
<?php endforeach; ?>
</div>
</section>
<?php endforeach; ?>

<?= $this->include('_pagination.phtml', ['pagination' => $pagination, 'url' => url('read list')]) ?>

Expand Down
Loading

0 comments on commit f83a22d

Please sign in to comment.