This commit is contained in:
seb
2026-10-10 00:25:09 +02:00
parent f2f60d5766
commit 2c36a705c4
3 changed files with 28 additions and 13 deletions

View File

@@ -1,10 +1,11 @@
import { PureComponent } from 'react'; import { PureComponent } from 'react';
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import { thumbHashToDataURL } from 'thumbhash'; import { thumbHashToDataURL, thumbHashToRGBA } from 'thumbhash';
export default class ThumbHashImage extends PureComponent { export default class ThumbHashImage extends PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
//move this to where it'S loaded
const bytes = Uint8Array.from(atob(props.thumbHash), (c) => c.charCodeAt(0)); const bytes = Uint8Array.from(atob(props.thumbHash), (c) => c.charCodeAt(0));
this.url = thumbHashToDataURL(bytes); this.url = thumbHashToDataURL(bytes);
} }

View File

@@ -16,11 +16,11 @@ export default class BrandThumb extends PureComponent {
} = this.props; } = this.props;
const pic = brand?.pics?.[0]; const pic = brand?.pics?.[0];
if (!pic?.thumbHash) { if (!pic?.thumbHash && !pic?.fullHash) {
return fallback; return fallback;
} }
const { thumbHash, thumbW, thumbH } = pic; const { thumbHash, fullHash, thumbW, thumbH } = pic;
const ratio = thumbW && thumbH ? thumbW / thumbH : 1; const ratio = thumbW && thumbH ? thumbW / thumbH : 1;
// Contain-fit inside a square `size x size` box, preserving aspect ratio. // Contain-fit inside a square `size x size` box, preserving aspect ratio.
let innerW = size; let innerW = size;
@@ -58,6 +58,7 @@ export default class BrandThumb extends PureComponent {
component="span" component="span"
sx={{ sx={{
display: 'block', display: 'block',
position: 'relative',
width: innerW, width: innerW,
height: innerH, height: innerH,
borderRadius: size >= 24 ? '4px' : '3px', borderRadius: size >= 24 ? '4px' : '3px',
@@ -69,12 +70,29 @@ export default class BrandThumb extends PureComponent {
boxShadow: SHADOW_THUMB_RING, boxShadow: SHADOW_THUMB_RING,
}} }}
> >
<ThumbHashImage {thumbHash ? (
thumbHash={thumbHash} <ThumbHashImage
width={innerW} thumbHash={thumbHash}
height={innerH} width={innerW}
sx={{ width: innerW, height: innerH, flexShrink: 0 }} height={innerH}
/> sx={{ width: innerW, height: innerH, flexShrink: 0 }}
/>
) : null}
{fullHash ? (
<Box
component="img"
src={`/api/smallthumb/${encodeURIComponent(fullHash)}`}
alt=""
draggable={false}
sx={{
position: 'absolute',
inset: 0,
width: '100%',
height: '100%',
display: 'block',
}}
/>
) : null}
</Box> </Box>
</Box> </Box>
); );

View File

@@ -79,10 +79,6 @@ class ArtikelMarkenPage extends PureComponent {
<ArtikelMarkeNew rowRef={this.createRowRef} /> <ArtikelMarkeNew rowRef={this.createRowRef} />
</PanelTile> </PanelTile>
<PanelTile wide={2} minHeight={0} title="Test">
{brands[0] ? <ArtikelMarke brand={brands[0]}/> : null}
<ArtikelMarke disabled />
</PanelTile>
</PanelTileGrid> </PanelTileGrid>
); );
} }