Skip to content

Commit

Permalink
imp: Enable the reading tab for all
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Jun 13, 2024
2 parents b419977 + 8d48fcc commit c45d8bd
Show file tree
Hide file tree
Showing 30 changed files with 307 additions and 770 deletions.
Binary file modified locales/fr_FR/LC_MESSAGES/main.mo
Binary file not shown.
207 changes: 99 additions & 108 deletions locales/fr_FR/LC_MESSAGES/main.po

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/static/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/static/onboarding/reading_menu.en_GB.webp
Binary file not shown.
Binary file added public/static/onboarding/reading_menu.fr_FR.webp
Binary file not shown.
Binary file modified public/static/screenshot.webp
Binary file not shown.
2 changes: 2 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ public function run(\Minz\Request $request): mixed
$autoload_modal_url = \Minz\Url::for('showcase', ['id' => 'link']);
} elseif ($current_user->autoload_modal === 'showcase contact') {
$autoload_modal_url = \Minz\Url::for('showcase', ['id' => 'contact']);
} elseif ($current_user->autoload_modal === 'showcase reading') {
$autoload_modal_url = \Minz\Url::for('showcase', ['id' => 'reading']);
}

// Force CSRF token to avoid weird issues when user did nothing for a while
Expand Down
File renamed without changes
4 changes: 0 additions & 4 deletions src/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,3 @@ hr {

background: linear-gradient(to right, var(--color-turquoise-5), var(--color-purple-5));
}

.easter-egg {
float: right;
}
24 changes: 0 additions & 24 deletions src/assets/stylesheets/custom/news.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@
animation: icon-spin 5s linear infinite;
}

@media (max-width: 799px) {
.news-selection__button {
display: flex;

align-items: center;
}

.news-selection__image {
width: auto;
height: 125px;
min-height: auto;
}

.news-selection__description {
flex: 1;
}
}

.news-selection__title {
display: block;
margin-top: var(--space-small);
margin-bottom: var(--space-small);
}

.news__source {
font-style: italic;
}
Expand Down
27 changes: 3 additions & 24 deletions src/controllers/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function index(): Response
* collections)
*
* @request_param string csrf
* @request_param string type
*
* @response 302 /login?redirect_to=/news
* if not connected
Expand All @@ -66,7 +65,6 @@ public function create(Request $request): Response
]);
}

$type = $request->param('type', '');
$csrf = $request->param('csrf', '');

$news = $user->news();
Expand All @@ -80,28 +78,9 @@ public function create(Request $request): Response
]);
}

if ($type === 'newsfeed') {
$beta_enabled = models\FeatureFlag::isEnabled('beta', $user->id);

$options = [
'number_links' => $beta_enabled ? 50 : 9,
'from' => 'followed',
];
} elseif ($type === 'short') {
$options = [
'number_links' => 3,
'max_duration' => 10,
'from' => 'bookmarks',
];
} else {
$options = [
'number_links' => 1,
'min_duration' => 10,
'from' => 'bookmarks',
];
}

$news_picker = new services\NewsPicker($user, $options);
$news_picker = new services\NewsPicker($user, [
'number_links' => 50,
]);
$links = $news_picker->pick();

$news = $user->news();
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/Showcases.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function show(Request $request): Response
return Response::ok('showcases/show_link.phtml');
} elseif ($id === 'contact') {
return Response::ok('showcases/show_contact.phtml');
} elseif ($id === 'reading') {
return Response::ok('showcases/show_reading.phtml');
} else {
return Response::notFound('not_found.phtml');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\migrations;

class Migration202406130001SetAutoloadModalToShowcaseReading
{
public function migrate(): bool
{
$database = \Minz\Database::get();

$database->exec(<<<'SQL'
UPDATE users SET autoload_modal = 'showcase reading';
SQL);

return true;
}

public function rollback(): bool
{
$database = \Minz\Database::get();

$database->exec(<<<'SQL'
UPDATE users SET autoload_modal = '';
SQL);

return true;
}
}
68 changes: 2 additions & 66 deletions src/models/dao/links/NewsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,84 +12,20 @@
*/
trait NewsQueries
{
/**
* Return links listed in bookmarks of the given user, ordered randomly.
*
* @return self[]
*/
public static function listFromBookmarksForNews(
string $user_id,
?int $min_duration,
?int $max_duration,
): array {
$where_placeholder = '';
$values = [
':user_id' => $user_id,
];

if ($min_duration !== null) {
$where_placeholder .= 'AND l.reading_time >= :min_duration ';
$values[':min_duration'] = $min_duration;
}

if ($max_duration !== null) {
$where_placeholder .= 'AND l.reading_time < :max_duration ';
$values[':max_duration'] = $max_duration;
}

$sql = <<<SQL
SELECT l.*, lc.created_at AS published_at, 'bookmarks' AS source_news_type
FROM links l, collections c, links_to_collections lc
WHERE lc.link_id = l.id
AND lc.collection_id = c.id
AND c.user_id = :user_id
AND l.user_id = :user_id
AND c.type = 'bookmarks'
{$where_placeholder}
GROUP BY l.id, lc.created_at
ORDER BY random()
SQL;

$database = Database::get();
$statement = $database->prepare($sql);
$statement->execute($values);

return self::fromDatabaseRows($statement->fetchAll());
}

/**
* Return public links listed in followed collections of the given user,
* ordered by publication date. Links with a matching url in bookmarks or
* read list are not returned.
*
* @return self[]
*/
public static function listFromFollowedCollectionsForNews(
string $user_id,
?int $min_duration,
?int $max_duration,
): array {
public static function listFromFollowedCollectionsForNews(string $user_id): array
{
$where_placeholder = '';
$values = [
':user_id' => $user_id,
];

if ($min_duration !== null) {
$where_placeholder .= 'AND l.reading_time >= :min_duration ';
$values[':min_duration'] = $min_duration;
}

if ($max_duration !== null) {
$where_placeholder .= 'AND l.reading_time < :max_duration ';
$values[':max_duration'] = $max_duration;
}

$where_placeholder .= <<<'SQL'
AND (
(fc.time_filter = 'strict' AND lc.created_at >= :until_strict) OR
Expand Down
26 changes: 2 additions & 24 deletions src/services/NewsPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
*
* @phpstan-type Options array{
* 'number_links': int,
* 'min_duration': ?int,
* 'max_duration': ?int,
* 'from': string,
* }
*
* @author Marien Fressinaud <[email protected]>
Expand All @@ -22,9 +19,6 @@ class NewsPicker
{
private const DEFAULT_OPTIONS = [
'number_links' => 9,
'min_duration' => null,
'max_duration' => null,
'from' => 'bookmarks',
];

private models\User $user;
Expand All @@ -35,12 +29,9 @@ class NewsPicker
/**
* @param array{
* 'number_links'?: int,
* 'min_duration'?: ?int,
* 'max_duration'?: ?int,
* 'from'?: string,
* } $options
*/
public function __construct(models\User $user, array $options)
public function __construct(models\User $user, array $options = [])
{
$this->user = $user;
$this->options = array_merge(self::DEFAULT_OPTIONS, $options);
Expand All @@ -53,20 +44,7 @@ public function __construct(models\User $user, array $options)
*/
public function pick(): array
{
if ($this->options['from'] === 'bookmarks') {
$links = models\Link::listFromBookmarksForNews(
$this->user->id,
$this->options['min_duration'],
$this->options['max_duration'],
);
} else {
$links = models\Link::listFromFollowedCollectionsForNews(
$this->user->id,
$this->options['min_duration'],
$this->options['max_duration'],
);
}

$links = models\Link::listFromFollowedCollectionsForNews($this->user->id);
$links = $this->mergeByUrl($links);
return array_slice($links, 0, $this->options['number_links']);
}
Expand Down
22 changes: 0 additions & 22 deletions src/utils/view_helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,6 @@ function human_implode(array $array, string $separator, string $last_separator):
return $string;
}

/**
* Return a random sentence to display when there are no news.
*/
function no_news_sentence(bool $beta_enabled): string
{
$bookmarks_url = url('bookmarks');
$sentence = _('There are no relevant links to suggest at this time.') . '<br />';
if (!$beta_enabled) {
$sentence .= _f('You can add links to <a href="%s">your bookmarks</a> to read them later.', $bookmarks_url);
}

if (rand(0, 100) === 0) {
if (rand(0, 10) === 0) {
$sentence .= '<span class="easter-egg">🦔</span>';
} else {
$sentence .= '<span class="easter-egg">🐾</span>';
}
}

return $sentence;
}

/**
* Return the list of publishers of a collection.
*/
Expand Down
8 changes: 2 additions & 6 deletions src/views/_layouts/connected.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,10 @@
<?= $current_page === 'reading' ? 'aria-current="page"' : '' ?>
href="<?= url('news') ?>"
>
<?= icon('news') ?>
<?= icon('reading') ?>

<span class="no-mobile">
<?php if ($beta_enabled): ?>
<?= _('Reading') ?>
<?php else: ?>
<?= _('News') ?>
<?php endif; ?>
<?= _('Reading') ?>
</span>
</a>

Expand Down
66 changes: 32 additions & 34 deletions src/views/_layouts/reading.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,40 @@
]);
?>

<div class="section <?= $beta_enabled ? '' : 'section--longbottom' ?>">
<?php if ($beta_enabled): ?>
<nav class="reading-nav">
<ul class="reading-nav__container">
<li class="reading-nav__item">
<a
class="reading-nav__anchor"
href="<?= url('news') ?>"
<?= $current_page === 'news' ? 'aria-current="page"' : '' ?>
>
<?= _('News') ?>
</a>
</li>
<div class="section">
<nav class="reading-nav">
<ul class="reading-nav__container">
<li class="reading-nav__item">
<a
class="reading-nav__anchor"
href="<?= url('news') ?>"
<?= $current_page === 'news' ? 'aria-current="page"' : '' ?>
>
<?= _('News') ?>
</a>
</li>

<li class="reading-nav__item">
<a
class="reading-nav__anchor"
href="<?= url('bookmarks') ?>"
<?= $current_page === 'bookmarks' ? 'aria-current="page"' : '' ?>
>
<?= _('Bookmarks') ?>
</a>
</li>
<li class="reading-nav__item">
<a
class="reading-nav__anchor"
href="<?= url('bookmarks') ?>"
<?= $current_page === 'bookmarks' ? 'aria-current="page"' : '' ?>
>
<?= _('Bookmarks') ?>
</a>
</li>

<li class="reading-nav__item">
<a
class="reading-nav__anchor"
href="<?= url('read list') ?>"
<?= $current_page === 'read' ? 'aria-current="page"' : '' ?>
>
<?= _('Links read') ?>
</a>
</li>
</ul>
</nav>
<?php endif; ?>
<li class="reading-nav__item">
<a
class="reading-nav__anchor"
href="<?= url('read list') ?>"
<?= $current_page === 'read' ? 'aria-current="page"' : '' ?>
>
<?= _('Links read') ?>
</a>
</li>
</ul>
</nav>

<?= $this->safe('content') ?>
</div>
Loading

0 comments on commit c45d8bd

Please sign in to comment.