Skip to content

Commit

Permalink
imp: Allow to follow a shared collection
Browse files Browse the repository at this point in the history
  • Loading branch information
marienfressinaud committed Oct 3, 2024
1 parent 5700d39 commit 12e8860
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/assets/stylesheets/components/sections.css
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
}

.section__actions {
display: flex;

gap: var(--space-small);

flex-shrink: 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/controllers/collections/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ public function update(Request $request): Response
if ($can_update) {
$collection->group_id = $group_id;
$collection->save();
} else {
}

if ($is_following) {
$followed_collection = models\FollowedCollection::findBy([
'user_id' => $user->id,
'collection_id' => $collection->id,
Expand Down
10 changes: 9 additions & 1 deletion src/models/dao/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,15 @@ public static function listComputedFollowedByUserId(
WHERE fc.collection_id = c.id
AND fc.user_id = :user_id
AND c.is_public = true
AND (
c.is_public = true
OR c.user_id = :user_id
OR EXISTS (
SELECT 1 FROM collection_shares cs
WHERE cs.user_id = :user_id
AND cs.collection_id = c.id
)
)
{$type_clause}
Expand Down
5 changes: 3 additions & 2 deletions src/models/dao/links/NewsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ public static function listFromFollowedCollections(string $user_id, int $max): a
AND lc.collection_id = c.id
AND (
(l.is_hidden = false AND c.is_public = true) OR
EXISTS (
(l.is_hidden = false AND c.is_public = true)
OR c.user_id = :user_id
OR EXISTS (
SELECT 1 FROM collection_shares cs
WHERE cs.user_id = :user_id
AND cs.collection_id = c.id
Expand Down
68 changes: 54 additions & 14 deletions src/views/collections/show.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
</span>
</summary>

<?php $is_following = $current_user->isFollowing($collection->id); ?>
<?php $is_shared = count($collection->shares(['access_type' => 'write'])) > 0; ?>

<nav class="popup__container popup__container--left" role="menu">
<button
class="popup__item popup__item--button"
Expand All @@ -91,6 +94,21 @@

<div class="popup__separator"></div>

<?php if ($is_following): ?>
<button
class="popup__item popup__item--button"
data-controller="modal-opener"
data-action="modal-opener#fetch"
data-modal-opener-href-value="<?= url('edit collection filter', ['id' => $collection->id, 'from' => url('collection', $current_url_params)]) ?>"
aria-haspopup="dialog"
aria-controls="modal"
role="menuitem"
>
<?= icon('slider') ?>
<?= _('Adjust for the news') ?>
</button>
<?php endif; ?>

<button
class="popup__item popup__item--button"
data-controller="modal-opener"
Expand All @@ -104,20 +122,18 @@
<?= _('Edit') ?>
</button>

<?php if ($collection->user_id === $current_user->id): ?>
<button
class="popup__item popup__item--button"
data-controller="modal-opener"
data-action="modal-opener#fetch"
data-modal-opener-href-value="<?= url('edit group collection', ['id' => $collection->id, 'from' => url('collection', $current_url_params)]) ?>"
aria-haspopup="dialog"
aria-controls="modal"
role="menuitem"
>
<?= icon('directory') ?>
<?= _('Put in a group') ?>
</button>
<?php endif; ?>
<button
class="popup__item popup__item--button"
data-controller="modal-opener"
data-action="modal-opener#fetch"
data-modal-opener-href-value="<?= url('edit group collection', ['id' => $collection->id, 'from' => url('collection', $current_url_params)]) ?>"
aria-haspopup="dialog"
aria-controls="modal"
role="menuitem"
>
<?= icon('directory') ?>
<?= _('Put in a group') ?>
</button>

<button
class="popup__item popup__item--button"
Expand All @@ -132,6 +148,30 @@
<?= _('Change the illustration') ?>
</button>

<div class="popup__separator"></div>

<?php if ($is_following): ?>
<form method="post" action="<?= url('unfollow collection', ['id' => $collection->id]) ?>" role="menuitem">
<input type="hidden" name="csrf" value="<?= $csrf_token ?>" />
<input type="hidden" name="from" value="<?= url('collection', $current_url_params) ?>" />

<button class="popup__item popup__item--button">
<?= icon('feed-stop') ?>
<?= _('Unfollow') ?>
</button>
</form>
<?php elseif ($is_shared): ?>
<form method="post" action="<?= url('follow collection', ['id' => $collection->id]) ?>" role="menuitem">
<input type="hidden" name="csrf" value="<?= $csrf_token ?>" />
<input type="hidden" name="from" value="<?= url('collection', $current_url_params) ?>" />

<button class="popup__item popup__item--button">
<?= icon('feed') ?>
<?= _('Follow') ?>
</button>
</form>
<?php endif; ?>

<?php if ($collection->user_id === $current_user->id): ?>
<div class="popup__separator"></div>

Expand Down

0 comments on commit 12e8860

Please sign in to comment.