add base view for detailed post

pull/11/head^2
remrem 10 months ago
parent 0c142515c1
commit 1c7fc75662

@ -0,0 +1,56 @@
:root {
font-family: "Helvetica", 'Courier New', Courier, monospace;
}
#post-wrapper {
width: 70%;
background-color: #f2f2f7;
margin: 0 auto;
border: 3px solid black;
border-radius: 1rem;
padding: 20px;
margin-top: 25vh;
}
#post-info {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
h1 {
font-size: 3em;
}
p {
white-space: pre-wrap;
font-size: 1.2em;
}
#comments {
h2 {
font-size: 30px;
}
}
hr {
color: black;
}
html {
--s: 257px;
/* control the size */
--c1: #38476b;
--c2: #bda3b6;
--_c: var(--c1) calc(100% - var(--s)/2) 99%, #0000;
--_g: var(--s), #0000 calc(99% - var(--s)/2), var(--_c);
background:
radial-gradient(var(--s) at 100% var(--_g)),
radial-gradient(calc(var(--s)/4) at 50% calc(100%/3), var(--_c)) var(--s) 0,
radial-gradient(var(--s) at 0% var(--_g)) 0 calc(3*var(--s)) var(--c2);
background-size:
calc(2*var(--s)) calc(9*var(--s)/4),
calc(2*var(--s)) calc(3*var(--s)/4);
}

@ -7,7 +7,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Attribute\Route; use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Post; use App\Entity\Post;
use App\Entity\Profil;
use App\Form\Type\PostType; use App\Form\Type\PostType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -32,20 +31,22 @@ class PostController extends AbstractController
]); ]);
} }
#[Route('/post/{id}', #[Route(
'/post/{id}',
name: 'display post', name: 'display post',
methods: ['GET'], methods: ['GET'],
requirements: ['id' => '\d+'])] requirements: ['id' => '\d+']
)]
public function getPost(int $id): Response public function getPost(int $id): Response
{ {
$post = $this->em->getRepository(Post::class)->find($id); $post = $this->em->getRepository(Post::class)->find($id);
if (!$post) { if (!$post) {
# Error 404 page
} }
# Return twig return $this->render('post/post.html.twig', [
return new Response(); 'post' => $post
]);
} }
#[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])] #[Route('/post/new/', name: 'add_post', methods: ['GET', 'POST'])]
@ -59,14 +60,7 @@ class PostController extends AbstractController
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$form = $form->getData(); $form = $form->getData();
$user = $this->getUser(); $user = $this->getUser();
$profil = new Profil();
$profil->setId(11);
$profil->setName("coucou");
$post->setProfil($user); $post->setProfil($user);
$this->em->persist($post); $this->em->persist($post);
@ -78,16 +72,13 @@ class PostController extends AbstractController
return $this->render('post/new.html.twig', [ return $this->render('post/new.html.twig', [
'form' => $form, 'form' => $form,
]); ]);
# Handle error on data
} }
#[Route('/post/{id}', name: 'remove_post', methods: ['DELETE'])] #[Route('/post/{id}', name: 'remove_post', methods: ['DELETE'])]
public function removePost(int $id): Response public function removePost(int $id): Response
{ {
$postRef = $this->em->getReference('Post', $id); $post = $this->em->getRepository(Post::class)->find($id);
$this->em->remove($postRef); $this->em->remove($post);
$this->em->flush(); $this->em->flush();
return new Response(); return new Response();

@ -33,7 +33,6 @@ class RegistrationController extends AbstractController
$entityManager->persist($user); $entityManager->persist($user);
$entityManager->flush(); $entityManager->flush();
return $security->login($user, 'form_login', 'main'); return $security->login($user, 'form_login', 'main');
} }

@ -0,0 +1,25 @@
<link rel="stylesheet" href="{{ asset('css/components/post.css') }}">
<title>{{ post.title }}</title>
{% block body %}
<div id="post-wrapper">
<div id="post">
<div id="post-info">
<img src="https://api.dicebear.com/8.x/big-smile/svg?seed={{ post.profil.name }}" width="50px">
<span>{{ post.profil.name }}</span>
{# <span>- {{ post.dateCreated }}</span> #}
<span>- Il y a 3 jours</span>
</div>
<h1 id="post-title">{{ post.title }}</h1>
<p>{{ post.text }}</p>
</div>
<hr>
<div id="comments">
<h2>Comments</h2>
</div>
</div>
{% endblock %}

Binary file not shown.
Loading…
Cancel
Save