[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:
parent
56ba7bd845
commit
ebf675ec59
|
@ -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]);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue
Block a user