"use client"; import { FormEvent, useEffect, useMemo, useState } from "react"; import Image from "next/image"; type ShamePhoto = { name: string; path: string; url: string; htmlUrl: string; }; type PhotoResponse = { photos: ShamePhoto[]; repo: string | null; path: string; branch?: string | null; message: string | null; }; const initialRepo = process.env.NEXT_PUBLIC_GITHUB_REPO ?? ""; const initialPath = process.env.NEXT_PUBLIC_GITHUB_PHOTOS_PATH ?? ""; const initialBranch = process.env.NEXT_PUBLIC_GITHUB_BRANCH ?? ""; function buildQuery(repo: string, path: string, branch: string) { const query = new URLSearchParams(); if (repo.trim()) { query.set("repo", repo.trim()); } if (path.trim()) { query.set("path", path.trim().replace(/^\/+/, "")); } if (branch.trim()) { query.set("branch", branch.trim()); } return query.toString(); } export default function Home() { const [repo, setRepo] = useState(initialRepo); const [path, setPath] = useState(initialPath); const [branch, setBranch] = useState(initialBranch); const [activeQuery, setActiveQuery] = useState(() => buildQuery(initialRepo, initialPath, initialBranch)); const [data, setData] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); useEffect(() => { const controller = new AbortController(); async function loadPhotos() { setIsLoading(true); setError(null); try { const response = await fetch(`/api/github-photos?${activeQuery}`, { signal: controller.signal }); const nextData = (await response.json()) as PhotoResponse; setData(nextData); if (!response.ok) { setError(nextData.message || "Could not load photos from GitHub."); } } catch (nextError) { if (nextError instanceof DOMException && nextError.name === "AbortError") { return; } setError("Could not reach the photo source."); } finally { setIsLoading(false); } } loadPhotos(); return () => controller.abort(); }, [activeQuery]); const repoLabel = data?.repo ?? "GitHub source not set"; const boardStamp = useMemo(() => { const count = data?.photos.length ?? 0; if (count === 0) { return "Empty"; } return `${count} filed`; }, [data?.photos.length]); function handleSubmit(event: FormEvent) { event.preventDefault(); setActiveQuery(buildQuery(repo, path, branch)); } return (

Доска позора

тут только самое позорное.

{boardStamp} {repoLabel}
{isLoading ?
Загружаю фотографии с GitHub...
: null} {!isLoading && error ?
{error}
: null} {!isLoading && !error && data?.message ?
{data.message}
: null} {data?.photos.map((photo, index) => (
{photo.name}
#{String(index + 1).padStart(2, "0")} {photo.name}
))}
); }