HifiPlanet-Website/hifi-src/src/pages/public/GalleryOverview.jsx
Maaxxs e9f68d054c Replace left/center/right buttons with real drag-and-drop positioning
Follow-up to the previous commit per explicit feedback: three preset
buttons weren't what was asked for - the ask was to grab the label in
the live preview and drag it directly.

Swaps app_settings.gallery_card_text_align (ENUM left/center/right,
one commit old) for gallery_card_text_x (TINYINT UNSIGNED 0-100, same
default position as before at 0). A discrete enum can't represent a
free-dragged position, so this is a real column replacement via
migration_gallery_card_drag.sql (drops the old column outright rather
than keeping both, since the old one is a single commit old and
unlikely to hold any real per-site customization yet).

The label is now positioned with `left: X%; transform: translateX(-X%)`
instead of a text-align class - the standard CSS trick for interpolating
a single percentage continuously between flush-left (X=0) and
flush-right (X=100, shifted back by its own width) with X=50 centering
it, so dragging feels continuous rather than snapping between three
fixed states. hifi-src/src/utils/galleryCardAlign.js now exports a
style-computing function instead of a class lookup table.

WebsiteSettings.jsx's preview label is draggable via Pointer Events
(setPointerCapture on pointerdown, so tracking keeps working even if
the cursor leaves the element mid-drag) with the card's own
getBoundingClientRect() converting cursor position to a 0-100 percent.
Kept small Links/Mittig/Rechts buttons as a secondary quick-jump
alongside the drag, not instead of it.

Verified against the local database directly via PHP CLI: default
comes back as 0, and an arbitrary value (73) written directly to the
column round-trips correctly through SiteSettingsController::show().

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-09 03:23:37 +02:00

66 lines
2.6 KiB
JavaScript

import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { api } from '../../api/client.js';
import usePageMeta from '../../hooks/usePageMeta.js';
import { useLanguage } from '../../context/LanguageContext.jsx';
import { useSiteSettings } from '../../context/SiteSettingsContext.jsx';
import { galleryCardLabelStyle } from '../../utils/galleryCardAlign.js';
export default function GalleryOverview() {
const [brands, setBrands] = useState(null);
const [error, setError] = useState('');
const { t } = useLanguage();
const { gallery_card_text_x: cardTextX } = useSiteSettings();
usePageMeta({
title: t('galleryOverview.metaTitle'),
description: t('galleryOverview.metaDescription'),
path: '/galerie',
});
useEffect(() => {
api.get('/gallery-brands').then(setBrands).catch((e) => setError(e.message));
}, []);
return (
<div className="mx-auto max-w-6xl px-4 py-12 sm:px-6">
<h1 className="mb-2 text-2xl font-bold text-neutral-900 dark:text-white sm:text-3xl">{t('galleryOverview.title')}</h1>
<p className="mb-8 text-neutral-600 dark:text-neutral-300">
{t('galleryOverview.intro')}
</p>
{error && <p className="text-red-600">{error}</p>}
{!brands && !error && <p className="text-neutral-500 dark:text-neutral-400">{t('galleryOverview.loading')}</p>}
{brands && brands.length === 0 && (
<p className="text-neutral-500 dark:text-neutral-400">{t('galleryOverview.empty')}</p>
)}
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4">
{brands?.map((brand) => (
<Link
key={brand.id}
to={`/galerie/${brand.slug}`}
className="group relative block aspect-[4/3] overflow-hidden rounded-xl bg-neutral-900 shadow-sm transition hover:shadow-lg"
>
{brand.cover_image_path ? (
<img
src={brand.cover_image_path}
alt={brand.name}
className="h-full w-full object-cover transition duration-300 group-hover:scale-105"
/>
) : (
<div className="flex h-full w-full items-center justify-center bg-neutral-200 dark:bg-neutral-800" />
)}
<div className="absolute inset-0 bg-gradient-to-t from-black/85 via-black/10 to-transparent transition group-hover:from-black/95" />
<span
className="absolute bottom-0 whitespace-nowrap p-4 text-lg font-extrabold text-white"
style={galleryCardLabelStyle(cardTextX)}
>
{brand.name}
</span>
</Link>
))}
</div>
</div>
);
}