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 a1ec6c2
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 66 deletions.
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
50 changes: 29 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:41+0100\n"
"PO-Revision-Date: 2024-03-25 15:41+0100\n"
"Last-Translator: Marien Fressinaud <dev@marienfressinaud.fr>\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:70
msgid "Mark all as read"
msgstr "Tout marquer comme lu"

Expand Down Expand Up @@ -2110,57 +2110,65 @@ 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:23 views/read/index.phtml:40
msgid "today"
msgstr "aujourd’hui"

#: views/news/index.phtml:25 views/read/index.phtml:42
msgid "yesterday"
msgstr "hier"

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

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

#: views/news/index.phtml:71
#: views/news/index.phtml:89
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:97
msgid "Never see the links again"
msgstr "Ne plus revoir les liens"

#: views/news/index.phtml:87
#: views/news/index.phtml:105
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:119
msgid "Refresh the news"
msgstr "Rafraichir le journal"

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

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

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

#: views/news/index.phtml:145
#: views/news/index.phtml:163
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:164 views/news/index.phtml:180
msgid "from your bookmarks"
msgstr "depuis vos signets"

#: views/news/index.phtml:161
#: views/news/index.phtml:179
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 <dev@marienfressinaud.fr>
* @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);
}
}
34 changes: 34 additions & 0 deletions src/utils/LinksTimeline/DateGroup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace flusio\utils\LinksTimeline;

use flusio\models;

/**
* @author Marien Fressinaud <dev@marienfressinaud.fr>
* @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');
}

public function isYesterday(): bool
{
$yesterday = \Minz\Time::ago(1, 'day');
return $this->date->format('Y-m-d') === $yesterday->format('Y-m-d');
}
}
50 changes: 34 additions & 16 deletions src/views/news/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,40 @@
<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">
<?= _date($date_group->date, 'dd MMMM') ?>

<?php if ($date_group->isToday()): ?>
<small class="text--secondary"><?= _('today') ?></small>
<?php elseif ($date_group->isYesterday()): ?>
<small class="text--secondary"><?= _('yesterday') ?></small>
<?php endif; ?>
</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

0 comments on commit a1ec6c2

Please sign in to comment.