- trop de trucs d'un coup... je vais faire attention ensuite ^^'

This commit is contained in:
Jérémy Guillot
2024-06-10 13:57:50 +02:00
parent 9595831aa3
commit c46e1a0a5c
69 changed files with 4004 additions and 385 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Twig\Components;
use App\Entity\Manga;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
class AddMangaModalComponent
{
use DefaultActionTrait;
#[LiveProp(writable: true)]
public ?Manga $manga;
public function open(Manga $manga): void
{
$this->manga = $manga;
}
public function close(): void
{
$this->manga = null;
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Twig\Components;
use Symfony\UX\TwigComponent\Attribute\AsTwigComponent;
#[AsTwigComponent]
class BootstrapModal
{
public ?string $id = null;
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Twig\Components;
use App\Repository\ChapterRepository;
use App\Repository\MangaRepository;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
final class DownloadChapter
{
use DefaultActionTrait;
public ?string $mangaSlug = '';
public float $chapter;
public function __construct()
{
}
public function downloadChapter(MangaRepository $mangaRepository, ChapterRepository $chapterRepository): int
{
// $mangaSlug = $this->mangaSlug;
// $chapter = $this->chapter;
// $manga = $mangaRepository->findOneBy(['slug' => $mangaSlug]);
// $chapter = $chapterRepository->findOneBy(['manga' => $manga, 'number' => $chapter]);
return 0;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Twig\Components;
use App\Service\MangadexProvider;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Exception;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\ComponentToolsTrait;
use Symfony\UX\LiveComponent\DefaultActionTrait;
use Symfony\UX\LiveComponent\ValidatableComponentTrait;
#[AsLiveComponent]
class MangaSearch
{
use DefaultActionTrait;
#[LiveProp(writable: true)]
public ?string $query = null;
public function __construct(private readonly MangadexProvider $mangadexProvider)
{
}
/**
* @throws Exception
*/
public function getMangas(): Collection|null
{
if ($this->query === null || $this->query === '') {
return null;
}
return $this->mangadexProvider->search($this->query);
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace App\Twig\Components;
use App\Entity\Manga;
use App\Service\MangadexProvider;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\ComponentToolsTrait;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
class NewMangaForm
{
use ComponentToolsTrait;
use DefaultActionTrait;
public ?Manga $manga = null;
#[LiveProp(writable: true)]
public array $mangaData = [];
#[LiveProp(writable: true)]
public ?int $index = 0;
public function mount(Manga $manga): void
{
$this->manga = $manga;
$this->mangaData = [
'title' => $manga->getTitle(),
'slug' => $manga->getSlug(),
'description' => $manga->getDescription(),
'imageUrl' => $manga->getImageUrl(),
'status' => $manga->getStatus(),
'genres' => $manga->getGenres(),
'author' => $manga->getAuthor(),
'publicationYear' => $manga->getPublicationYear(),
'rating' => $manga->getRating(),
'externalId' => $manga->getExternalId(),
];
}
#[LiveAction]
public function saveManga(EntityManagerInterface $entityManager, MangadexProvider $mangadexProvider): Response
{
$manga = new Manga();
$manga->setTitle($this->mangaData['title'])
->setSlug($this->mangaData['slug'])
->setDescription($this->mangaData['description'])
->setImageUrl($this->mangaData['imageUrl'])
->setStatus($this->mangaData['status'])
->setGenres($this->mangaData['genres'])
->setAuthor($this->mangaData['author'])
->setPublicationYear($this->mangaData['publicationYear'])
->setRating($this->mangaData['rating'])
->setExternalId($this->mangaData['externalId']);
$mangadexProvider->getFeed($manga);
try {
foreach ($manga->getChapters() as $chapter) {
$entityManager->persist($chapter);
}
$entityManager->persist($manga);
$entityManager->flush();
} catch (\Exception $e) {
if ($e instanceof UniqueConstraintViolationException) {
return new RedirectResponse('/manga/' . $manga->getSlug());
}
throw $e;
}
return new RedirectResponse('/manga/' . $manga->getSlug());
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Twig\Components;
use App\Repository\MangaRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveProp;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
final class Search
{
use DefaultActionTrait;
#[LiveProp (writable: true)]
public ?string $query = null;
public function __construct(private readonly MangaRepository $mangaRepository)
{
}
public function getMangas(): array
{
return $this->query ? $this->mangaRepository->findByTitle($this->query) : [];
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Twig\Components;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
final class ToolBarButton
{
use DefaultActionTrait;
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Twig\Extension;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class TruncateExtension extends AbstractExtension
{
public function getFilters(): array
{
return [
new TwigFilter('truncate', [$this, 'truncate']),
];
}
public function truncate(?string $value, int $limit): string
{
if ($value === null) {
return '';
}
return strlen($value) > $limit ? substr($value, 0, $limit) . '...' : $value;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace App\Twig\Runtime;
use Twig\Extension\RuntimeExtensionInterface;
class TruncateExtensionRuntime implements RuntimeExtensionInterface
{
public function __construct()
{
// Inject dependencies if needed
}
public function doSomething($value)
{
// ...
}
}