From 87ef79bea3c41017188f60cd7b8aee7b5d23a7a3 Mon Sep 17 00:00:00 2001 From: seb Date: Wed, 28 Oct 2026 21:55:24 +0100 Subject: [PATCH] u --- src/automats/articleIndexAutomat.js | 22 +++++++++++++++++++++- src/automats/categoryViewAutomat.js | 11 +++++++++++ src/routes/artikel.jsx | 28 ++++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/automats/articleIndexAutomat.js b/src/automats/articleIndexAutomat.js index 8c10616..8ff9b4d 100644 --- a/src/automats/articleIndexAutomat.js +++ b/src/automats/articleIndexAutomat.js @@ -120,6 +120,12 @@ function toIndexRecord(article, categoryId) { ? String(categoryId) : (Array.isArray(article.categoryIds) ? article.categoryIds.join(',') : (article.categories ?? null)); + const firstPhoto = Array.isArray(article.photos) && article.photos.length > 0 ? article.photos[0] : null; + const fullHash = article.fullHash ?? firstPhoto?.fullHash ?? null; + const thumbHash = article.thumbHash ?? firstPhoto?.thumbHash ?? null; + const smallThumbBinary = article.smallThumbBinary ?? firstPhoto?.smallThumbBinary ?? null; + const photos = article.photos ?? (fullHash ? [{ fullHash, thumbHash }] : []); + return { ...article, id: article.id, @@ -137,6 +143,10 @@ function toIndexRecord(article, categoryId) { categories, isParent: Boolean(article.isParent ?? article.is_parent ?? (childCount > 0)), childCount, + fullHash, + thumbHash, + photos, + smallThumbBinary, }; } @@ -377,14 +387,24 @@ export function updateArticleIndexRecord(article) { let nextItems; if (existingIndex >= 0) { const existing = items[existingIndex]; + const firstPhoto = Array.isArray(article.photos) && article.photos.length > 0 ? article.photos[0] : null; + const hasPhotosProp = 'photos' in article; + const fullHash = article.fullHash ?? firstPhoto?.fullHash ?? (hasPhotosProp ? null : existing.fullHash); + const thumbHash = article.thumbHash ?? firstPhoto?.thumbHash ?? (hasPhotosProp ? null : existing.thumbHash); + const photos = article.photos ?? (hasPhotosProp ? [] : (existing.photos ?? [])); + const smallThumbBinary = article.smallThumbBinary ?? firstPhoto?.smallThumbBinary ?? (hasPhotosProp ? null : existing.smallThumbBinary); + nextItems = [...items]; nextItems[existingIndex] = { ...existing, ...record, categories: record.categories ?? existing.categories, - smallThumbBinary: article.smallThumbBinary ?? article.photos?.[0]?.smallThumbBinary ?? existing.smallThumbBinary, brand: article.brand ?? existing.brand, brandName: article.brand?.name ?? article.brandName ?? existing.brandName, + fullHash, + thumbHash, + photos, + smallThumbBinary, }; } else { nextItems = [...items, record]; diff --git a/src/automats/categoryViewAutomat.js b/src/automats/categoryViewAutomat.js index b2308ea..eed0ff8 100644 --- a/src/automats/categoryViewAutomat.js +++ b/src/automats/categoryViewAutomat.js @@ -352,6 +352,13 @@ export function updateArticleInCategoryViews(article) { // Update in-place const existing = item.data.articles[existingIndex]; const updatedArticles = [...item.data.articles]; + const firstPhoto = Array.isArray(article.photos) && article.photos.length > 0 ? article.photos[0] : null; + const hasPhotosProp = 'photos' in article; + const fullHash = article.fullHash ?? firstPhoto?.fullHash ?? (hasPhotosProp ? null : existing.fullHash); + const thumbHash = article.thumbHash ?? firstPhoto?.thumbHash ?? (hasPhotosProp ? null : existing.thumbHash); + const photos = article.photos ?? (hasPhotosProp ? [] : (existing.photos ?? [])); + const smallThumbBinary = article.smallThumbBinary ?? firstPhoto?.smallThumbBinary ?? (hasPhotosProp ? null : existing.smallThumbBinary); + updatedArticles[existingIndex] = { ...existing, ...article, @@ -365,6 +372,10 @@ export function updateArticleInCategoryViews(article) { brandName: article.brand?.name ?? article.brandName ?? existing.brandName, childCount: article.childCount ?? existing.childCount, isParent: Boolean(article.childCount > 0 || article.isParent || existing.isParent), + fullHash, + thumbHash, + photos, + smallThumbBinary, }; categoryViews.key(slug).set({ ...item.data, diff --git a/src/routes/artikel.jsx b/src/routes/artikel.jsx index 3e4961f..95d1417 100644 --- a/src/routes/artikel.jsx +++ b/src/routes/artikel.jsx @@ -22,6 +22,8 @@ import ChevronLeftIcon from '@mui/icons-material/ChevronLeft'; import articleSearchAutomat from '../automats/articleSearchAutomat'; import BackendError from '../components/BackendError'; import { formatPrice, getArticleGross } from '../utils/price'; +import { thumb } from '../api'; +import { getThumbHashDataUrl } from '../utils/thumbHashCache'; import { buildSearchUrl, queryFromParams, @@ -110,6 +112,15 @@ class ResultRow extends Component { const showChildBadge = isParent || childCount > 0; const price = getArticleGross(row, companyAutomat.state.current?.taxrate); + const firstPhoto = Array.isArray(row.photos) && row.photos.length > 0 ? row.photos[0] : null; + const fullHash = row.fullHash ?? firstPhoto?.fullHash ?? null; + const thumbHash = row.thumbHash ?? firstPhoto?.thumbHash ?? null; + const smallThumbBinary = row.smallThumbBinary ?? firstPhoto?.smallThumbBinary ?? null; + const thumbSrc = smallThumbBinary + ? `data:image/avif;base64,${smallThumbBinary}` + : (fullHash ? thumb.url(fullHash) : null); + const thumbHashUrl = thumbHash ? getThumbHashDataUrl(thumbHash) : null; + return ( - {row.smallThumbBinary && ( + {thumbSrc ? ( + ) : ( + thumbHashUrl && ( + + ) )}