Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #6

Merged
merged 3 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/components/ui/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const TooltipContent = React.forwardRef<
ref={ref}
sideOffset={sideOffset}
className={cn(
'z-50 overflow-hidden rounded-base border-2 border-border dark:border-darkBorder bg-main px-3 py-1.5 text-sm font-base text-black animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
'z-50 overflow-hidden rounded-base border-2 border-border dark:border-darkBorder bg-bg px-3 py-1.5 text-sm font-base text-black animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
className,
)}
{...props}
Expand Down
41 changes: 31 additions & 10 deletions assets/react/controllers/SatisfactoryBp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
CardHeader,
CardTitle,
} from '@/components/ui/card';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip'
import { CalendarClock, Download, Hammer, Heart, RefreshCcw, User } from "lucide-react";

interface Block {
Expand Down Expand Up @@ -46,12 +52,14 @@ const SatisfactoryBp: React.FC<SatisfactoryBpProps> = ({ blocks }) => {
},
});

const data = await response.json();

if (!response.ok) {
throw new Error('Erreur lors de l\'envoi du remerciement');
// Afficher une notification ou un message d'erreur
alert(data.error || 'Erreur lors de l\'envoi du remerciement');
return;
}

const data = await response.json();

// Mettre à jour le thankCount dans l'état local
setBlocksState(prevBlocks => prevBlocks.map(block => {
if (block.id === id) {
Expand All @@ -61,7 +69,8 @@ const SatisfactoryBp: React.FC<SatisfactoryBpProps> = ({ blocks }) => {
}));
} catch (error) {
console.error(error);
// Optionnel : afficher une notification d'erreur à l'utilisateur
// Afficher une notification d'erreur à l'utilisateur
alert('Erreur réseau, veuillez réessayer plus tard.');
}
};

Expand Down Expand Up @@ -93,10 +102,10 @@ const SatisfactoryBp: React.FC<SatisfactoryBpProps> = ({ blocks }) => {
<User className="mr-2 text-secondary" />
<span className="font-bold">{block.author}</span>
</div>
<div className="flex items-center justify-end">
<span className="text-xs uppercase">Downloads</span>
<Download className="mr-2 ms-2 text-secondary" />
<div className="flex items-center justify-start">
<Download className="mr-2 text-secondary" />
<span className="font-bold">{block.downloadCount}</span>
<span className="text-xs uppercase ms-2">Downloads</span>
</div>
</CardHeader>
<CardContent className="flex-grow">
Expand All @@ -116,10 +125,22 @@ const SatisfactoryBp: React.FC<SatisfactoryBpProps> = ({ blocks }) => {
</CardContent>
<CardFooter className="flex flex-wrap justify-center gap-4 mt-auto">
<a href={`/satisfactory/blueprint/${block.id}/download/sbp`}>
<Button variant="default">Télécharger .sbp</Button>
<Button variant="default">Download .sbp (indispensable)</Button>
</a>
<a href={`/satisfactory/blueprint/${block.id}/download/sbpcfg`}>
<Button variant="neutral">Télécharger .sbpcfg (optionnel)</Button>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button variant="neutral">
Download .sbpcfg (optionnel)
</Button>
</TooltipTrigger>
<TooltipContent>
<p>Nécessaire uniquement si vous souhaitez conserver la description, l'icône et la couleur par défaut du plan</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>

</a>
<Button
variant="secondary"
Expand All @@ -140,4 +161,4 @@ const SatisfactoryBp: React.FC<SatisfactoryBpProps> = ({ blocks }) => {
)
}

export default SatisfactoryBp;
export default SatisfactoryBp;
21 changes: 18 additions & 3 deletions src/Infrastructure/Controller/Site/SatisfactoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;

Expand Down Expand Up @@ -124,13 +125,27 @@ public function downloadSbpcfg(int $id): Response
}

#[Route('/satisfactory/blueprint/{id}/thank', name: 'app_satisfactory_thank', methods: ['POST'])]
public function thank(int $id): Response
{
public function thank(
int $id,
SessionInterface $session,
): Response {
$blueprint = $this->satisfactoryBpRepository->find($id);
if (!$blueprint) {
return new JsonResponse(['error' => 'Blueprint not found'], Response::HTTP_NOT_FOUND);
return new JsonResponse(['error' => 'Blueprint introuvable'], Response::HTTP_NOT_FOUND);
}

// Récupérer les blueprints déjà remerciés depuis la session
$thankedBlueprints = $session->get('thanked_blueprints', []);

if (in_array($id, $thankedBlueprints)) {
return new JsonResponse(['error' => 'Vous avez déjà remercié pour ce blueprint'], Response::HTTP_BAD_REQUEST);
}

// Ajouter le blueprint aux blueprints remerciés
$thankedBlueprints[] = $id;
$session->set('thanked_blueprints', $thankedBlueprints);

// Incrémenter le compteur de remerciements
$blueprint->incrementThankCount();
$this->entityManager->persist($blueprint);
$this->entityManager->flush();
Expand Down