Implement comments (#10)
Allow logged users to comment posts. Edition is not allowed via the API since it doesn't support auth yet. Symfony UX is used with Turbo to avoid full pages reload, without JavaScript™. Co-authored-by: clfreville2 <clement.freville2@etu.uca.fr> Reviewed-on: https://codefirst.iut.uca.fr/git/clement.freville2/herbarium/pulls/10
This commit was merged in pull request #10.
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
<form method="post" action="{{ path('app_post_comment_delete', {'id': comment.id}) }}" onsubmit="return confirm('Are you sure you want to delete this comment?');">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ comment.id) }}">
|
||||
<button class="btn btn-danger">Delete</button>
|
||||
</form>
|
||||
@@ -0,0 +1,17 @@
|
||||
<turbo-frame id="comment_{{ comment.id }}">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
{{ comment.author.email }} le {{ comment.createdAt | date }}
|
||||
{% if comment.createdAt != comment.editedAt %}
|
||||
(modifié le {{ comment.editedAt | date }})
|
||||
{% endif %}
|
||||
</h5>
|
||||
<p class="card-text">{{ comment.content }}</p>
|
||||
{% if is_granted('COMMENT_EDIT', comment) %}
|
||||
<a href="{{ path('app_post_comment_edit', {'id': comment.id}) }}" class="btn btn-primary">Modifier</a>
|
||||
{{ include('comment/_delete_form.html.twig') }}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</turbo-frame>
|
||||
@@ -0,0 +1,3 @@
|
||||
{% block success_stream %}
|
||||
<turbo-stream action="remove" target="comment_{{ comment }}"></turbo-stream>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,11 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Edit Comment{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Edit Comment</h1>
|
||||
|
||||
<turbo-frame id="comment_{{ comment.id }}">
|
||||
{{ include('post/_form.html.twig', {'button_label': 'Update'}) }}
|
||||
</turbo-frame>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,7 @@
|
||||
{% block success_stream %}
|
||||
<turbo-stream action="append" targets="#comments">
|
||||
<template>
|
||||
{{ include('comment/comment.html.twig') }}
|
||||
</template>
|
||||
</turbo-stream>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user