add comment preview

This commit is contained in:
Simon Vieille 2021-03-30 13:47:58 +02:00
parent e7321ef146
commit ca43d520e7
3 changed files with 28 additions and 3 deletions

View file

@ -1,3 +1,5 @@
const Routing = require('./routing')
const Post = function(w) {
this.window = w;
}
@ -48,7 +50,7 @@ Post.prototype.commentsEvents = function() {
previewRender.innerHTML = '<p>Chargement en cours…</p>';
}
var content = document.querySelector('#comment_content').value;
var content = document.querySelector('#user_comment_content').value;
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(data) {
@ -59,7 +61,7 @@ Post.prototype.commentsEvents = function() {
}
};
httpRequest.open('POST', Routing.generate('api_comment_preview'));
httpRequest.open('POST', Routing.generate('api_blog_comment_preview'));
httpRequest.setRequestHeader(
'Content-Type',
'application/x-www-form-urlencoded'

View file

@ -1 +1 @@
{"base_url":"","routes":{"blog_tech_form_without_javascript":{"tokens":[["text","\/nojs"]],"defaults":[],"requirements":[],"hosttokens":[["text","local.deblan"]],"methods":[],"schemes":[]}},"prefix":"","host":"localhost","port":"","scheme":"http","locale":[]}
{"base_url":"","routes":{"api_blog_comment_preview":{"tokens":[["text","\/api\/blog\/comment\/preview"]],"defaults":[],"requirements":[],"hosttokens":[],"methods":[],"schemes":[]},"blog_tech_form_without_javascript":{"tokens":[["text","\/nojs"]],"defaults":[],"requirements":[],"hosttokens":[["text","local.deblan"]],"methods":[],"schemes":[]}},"prefix":"","host":"localhost","port":"","scheme":"http","locale":[]}

View file

@ -0,0 +1,23 @@
<?php
namespace App\Controller\Blog\Api;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Markdown\Parser\Comment as CommentParser;
use Symfony\Component\HttpFoundation\Request;
class CommentController extends AbstractController
{
/**
* @Route("/api/blog/comment/preview", name="api_blog_comment_preview", options={"expose"=true})
*/
public function preview(Request $request, CommentParser $parser): JsonResponse
{
return $this->json([
'render' => $parser->transformMarkdown($request->request->get('content')),
]);
}
}