Browse Source

Lists, reorganizing again

imwald
Nuša Pukšič 3 months ago
parent
commit
48247e9eab
  1. 24
      src/Service/ReadingListManager.php
  2. 2
      templates/components/ReadingListDropdown.html.twig

24
src/Service/ReadingListManager.php

@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface; @@ -10,6 +10,7 @@ use Doctrine\ORM\EntityManagerInterface;
use swentel\nostr\Key\Key;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use function Webmozart\Assert\Tests\StaticAnalysis\startsWith;
/**
* Service for managing reading list drafts and published lists
@ -24,7 +25,7 @@ class ReadingListManager @@ -24,7 +25,7 @@ class ReadingListManager
) {}
/**
* Get all published reading lists for the current user
* Get all published reading lists and categories for the current user
* @return array<array{id: int, title: string, summary: ?string, slug: string, createdAt: \DateTimeInterface, pubkey: string, articleCount: int}>
*/
public function getUserReadingLists(): array
@ -50,7 +51,8 @@ class ReadingListManager @@ -50,7 +51,8 @@ class ReadingListManager
foreach ($events as $ev) {
if (!$ev instanceof Event) continue;
$tags = $ev->getTags();
$isReadingList = false;
$isIndex = false;
$isMagazine = false;
$title = null;
$slug = null;
$summary = null;
@ -58,8 +60,8 @@ class ReadingListManager @@ -58,8 +60,8 @@ class ReadingListManager
foreach ($tags as $t) {
if (is_array($t)) {
if (($t[0] ?? null) === 'type' && ($t[1] ?? null) === 'reading-list') {
$isReadingList = true;
if (($t[0] ?? null) === 'type' && in_array($t[1] ?? null, ['reading-list', 'magazine'])) {
$isIndex = true;
}
if (($t[0] ?? null) === 'title') {
$title = (string)$t[1];
@ -71,12 +73,18 @@ class ReadingListManager @@ -71,12 +73,18 @@ class ReadingListManager
$slug = (string)$t[1];
}
if (($t[0] ?? null) === 'a') {
$articleCount++;
// Look for kind 30023 articles only
if (isset($t[1]) && str_starts_with($t[1],'30023')) {
$articleCount++;
}
if (isset($t[1]) && str_starts_with($t[1],'30040')) {
$isMagazine = true;
}
}
}
}
if ($isReadingList) {
if ($isIndex && !$isMagazine) {
// Collapse by slug: keep only newest per slug
$keySlug = $slug ?: ('__no_slug__:' . $ev->getId());
if (isset($seenSlugs[$slug ?? $keySlug])) {
@ -163,7 +171,7 @@ class ReadingListManager @@ -163,7 +171,7 @@ class ReadingListManager
if (($t[0] ?? null) === 'd') {
$eventSlug = (string)$t[1];
}
if (($t[0] ?? null) === 'type' && ($t[1] ?? null) === 'reading-list') {
if (($t[0] ?? null) === 'type' && in_array($t[1] ?? null, ['reading-list', 'category'])) {
$isReadingList = true;
}
}
@ -285,7 +293,7 @@ class ReadingListManager @@ -285,7 +293,7 @@ class ReadingListManager
if (($t[0] ?? null) === 'd') {
$eventSlug = (string)$t[1];
}
if (($t[0] ?? null) === 'type' && ($t[1] ?? null) === 'reading-list') {
if (($t[0] ?? null) === 'type' && in_array($t[1] ?? null, ['reading-list', 'category'])) {
$isReadingList = true;
}
if (($t[0] ?? null) === 'a') {

2
templates/components/ReadingListDropdown.html.twig

@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
data-action="click->reading-list-dropdown#addToList"
data-slug="{{ list.slug }}"
data-title="{{ list.title }}">
<div class="d-flex flex-row">
<div class="d-flex flex-row justify-content-between">
<div>
<strong>{{ list.title }}</strong>
<br>

Loading…
Cancel
Save