[Plugins][FAVOURITE] Redirect added. Only redirects from the route the user came from, not the anchored note. To be added. Further corner cases fixed.

This commit is contained in:
Eliseu Amaro 2021-10-24 15:12:18 +01:00 committed by Diogo Peralta Cordeiro
parent 56ba7bd845
commit ebf675ec59
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
6 changed files with 37 additions and 31 deletions

View File

@ -27,6 +27,7 @@ use App\Core\Controller;
use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Form;
use App\Core\Router\Router;
use App\Util\Common;
use App\Util\Exception\InvalidFormException;
use App\Util\Exception\NoLoggedInUser;
@ -72,8 +73,12 @@ class Favourite extends Controller
$opts = ['note_id' => $id, 'actor_id' => $user->getId()];
DB::persist(FavouriteEntity::create($opts));
DB::flush();
// TODO: proper redirect from where the user came from
throw new RedirectException();
if ($redirect_back_exists = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1] )[0]) {
$redirect_back_exists = substr($redirect_back_exists, 5);
# TODO anchor on element id
throw new RedirectException($redirect_back_exists);
}
}
return [
@ -114,8 +119,12 @@ class Favourite extends Controller
if ($form_remove_favourite->isSubmitted()) {
DB::remove($remove_favourite_note);
DB::flush();
// TODO: proper redirect from where the user came from
throw new RedirectException();
if ($redirect_back_exists = explode("&", explode("?", $_SERVER['REQUEST_URI'])[1] )[0]) {
$redirect_back_exists = substr($redirect_back_exists, 5);
# TODO anchor on element id
throw new RedirectException($redirect_back_exists);
}
}
$note = DB::find('note', ['id' => $id]);

View File

@ -34,6 +34,7 @@ use App\Util\Exception\InvalidFormException;
use App\Util\Exception\NoSuchNoteException;
use App\Util\Exception\RedirectException;
use App\Util\Nickname;
use phpDocumentor\Reflection\PseudoTypes\NumericString;
use Symfony\Component\HttpFoundation\Request;
class Favourite extends NoteHandlerPlugin
@ -54,7 +55,7 @@ class Favourite extends NoteHandlerPlugin
return Event::next;
}
// If note is favourite, "is_set" is 1
// If note is favourite, "is_favourite" is 1
$opts = ['note_id' => $note->getId(), 'actor_id' => $user->getId()];
$is_favourite = DB::find('favourite', $opts) !== null;
@ -65,10 +66,14 @@ class Favourite extends NoteHandlerPlugin
Router::url('note_remove_favourite', $args, $type) :
Router::url('note_add_favourite', $args, $type);
// Concatenating get parameter to redirect the user to where he came from
$favourite_action_url .= '?from=' . urlencode(Common::route());
$extra_classes = $is_favourite ? "note-actions-set" : "note-actions-unset";
$favourite_action = [
"url" => $favourite_action_url,
"classes" => "button-container favourite-button-container $extra_classes"
"classes" => "button-container favourite-button-container $extra_classes",
"id" => "favourite-button-container-" . $note->getId()
];
$actions[] = $favourite_action;

View File

@ -1,24 +1,17 @@
{% extends 'stdgrid.html.twig' %}
{% block meta %}
{{ parent() }}
{% endblock %}
{% block title %}{{ 'Favourite ' | trans }}{{ note.getActorNickname() }}{{ '\'s note.' | trans }}{% endblock %}
{% block header %}
{% block stylesheets %}
{{ parent() }}
{% endblock %}
{% block left %}
{{ parent() }}
{% endblock %}
<link rel="stylesheet" href="{{ asset('assets/default_theme/css/pages/feeds.css') }}" type="text/css">
{% endblock stylesheets %}
{% block body %}
{{ parent() }}
<div class="page">
<div class="main">
{% include '/cards/note/view.html.twig' with {'note': note} only %}
{% include '/cards/note/view.html.twig' with {'note': note, 'note_actions_show': false} only %}
{{ form(add_favourite) }}
</div>
</div>

View File

@ -1,24 +1,17 @@
{% extends 'stdgrid.html.twig' %}
{% block meta %}
{{ parent() }}
{% endblock %}
{% block title %}{{ 'Remove favourite from ' | trans }}{{ note.getActorNickname() }}{{ '\'s note.' | trans }}{% endblock %}
{% block header %}
{% block stylesheets %}
{{ parent() }}
{% endblock %}
{% block left %}
{{ parent() }}
{% endblock %}
<link rel="stylesheet" href="{{ asset('assets/default_theme/css/pages/feeds.css') }}" type="text/css">
{% endblock stylesheets %}
{% block body %}
{{ parent() }}
<div class="page">
<div class="main">
{% include '/cards/note/view.html.twig' with {'note': note} only %}
{% include '/cards/note/view.html.twig' with {'note': note, 'note_actions_show': false} only %}
{{ form(remove_favourite) }}
</div>
</div>

View File

@ -212,6 +212,11 @@
mask-image: url("../../icons/delete.svg");
}
#add_favourite,
#remove_favourite {
margin-top: var(--smaller);
}
.note-content {
display: -webkit-box;
display: -webkit-flex;

View File

@ -1,6 +1,7 @@
<article class="h-entry hentry note">
{% set nickname = note.getActorNickname() %}
{% set nickname = note.getActorNickname() %}
{% if note_actions_show is not defined %} {% set note_actions_show = true %} {% endif %}
<article class="h-entry hentry note">
<aside class="note-sidebar">
<img class="u-logo avatar" src="{{ note.getActorAvatarUrl() }}" alt="{{ nickname }}'s avatar" width="32px" height="32px">
</aside>
@ -14,7 +15,7 @@
{{ nickname }}
</strong>
{% if app.user %}
{% if app.user and note_actions_show %}
<div class="note-actions">
{% for current_action in get_note_actions(note) %}
<a class="{{ current_action["classes"] }}" href="{{ current_action["url"] }}"></a>