From 8a8e44c83d8ca4551d86d8939005274ea29ed60c Mon Sep 17 00:00:00 2001
From: tisachi
Date: Sun, 11 Oct 2026 17:56:54 +0200
Subject: [PATCH] Aplikacja: zdjecia silowni przez AuthImage (blob z
chronionego endpointu) - wczesniej surowy
nie mial bearer i nie rysowal
---
app/src/components/AuthImage.tsx | 53 +++++++++++++++
app/src/components/gyms/GymGallery.tsx | 18 +++--
app/src/pages/gyms/GymDetail.tsx | 91 ++++++++++++++++++--------
app/src/pages/gyms/Gyms.tsx | 6 +-
4 files changed, 135 insertions(+), 33 deletions(-)
create mode 100644 app/src/components/AuthImage.tsx
diff --git a/app/src/components/AuthImage.tsx b/app/src/components/AuthImage.tsx
new file mode 100644
index 0000000..00cec0f
--- /dev/null
+++ b/app/src/components/AuthImage.tsx
@@ -0,0 +1,53 @@
+import { useEffect, useState } from 'react';
+import { apiBlob } from '../api/client';
+
+// Obiekty URL trzymamy w buforze na czas życia karty — galeria potrafi
+// renderować ten sam obraz wiele razy (cover + miniatura + lightbox).
+const srcCache = new Map>();
+
+function loadObjectUrl(url: string): Promise {
+ let pending = srcCache.get(url);
+ if (!pending) {
+ pending = apiBlob(url).then((blob) => URL.createObjectURL(blob));
+ srcCache.set(url, pending);
+ pending.catch(() => srcCache.delete(url));
+ }
+ return pending;
+}
+
+interface AuthImageProps {
+ /** Ścieżka względna API (np. `/gyms/x/photos/y`) — jak dawniej `gymPhotoSrc`. */
+ src: string | null | undefined;
+ alt: string;
+ className?: string;
+}
+
+/**
+ * Zdjęcia siłowni serwuje chroniony endpoint (Authorization), więc zwykły
+ *
nie przejdzie — pobieramy blob przez `api()` i wyświetlamy z
+ * URL.createObjectURL. Błąd poboru = pusty render (bez errorów w konsoli).
+ */
+export function AuthImage({ src, alt, className }: AuthImageProps) {
+ const [objectUrl, setObjectUrl] = useState(null);
+
+ useEffect(() => {
+ if (!src) {
+ setObjectUrl(null);
+ return;
+ }
+ let active = true;
+ loadObjectUrl(src)
+ .then((url) => {
+ if (active) setObjectUrl(url);
+ })
+ .catch(() => {
+ if (active) setObjectUrl(null);
+ });
+ return () => {
+ active = false;
+ };
+ }, [src]);
+
+ if (!src || !objectUrl) return null;
+ return
;
+}
diff --git a/app/src/components/gyms/GymGallery.tsx b/app/src/components/gyms/GymGallery.tsx
index 03ebd63..38cf0e6 100644
--- a/app/src/components/gyms/GymGallery.tsx
+++ b/app/src/components/gyms/GymGallery.tsx
@@ -1,7 +1,8 @@
import { useRef, useState } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import { ImagePlus, Star, Trash2 } from 'lucide-react';
-import { addGymPhotos, deleteGymPhoto, gymPhotoSrc, setGymPhotoCover } from '../../api/queries';
+import { addGymPhotos, deleteGymPhoto, setGymPhotoCover } from '../../api/queries';
+import { AuthImage } from '../AuthImage';
import type { Gym, GymPhoto } from '../../api/types';
import { Badge, Button, ErrorText } from '../ui';
import { useToast } from '../toast';
@@ -110,7 +111,12 @@ export default function GymGallery({
Zdjęcia siłowni. Pierwsze zdjęcie (najmniejsza kolejność) jest okładką.
{canManage && (
-