pl-fe: fix avatars on gotosocial

Signed-off-by: Nicole Mikołajczyk <git@mkljczk.pl>
This commit is contained in:
Nicole Mikołajczyk
2025-04-02 12:35:05 +02:00
parent 1869eee9c5
commit 311b584b2e
2 changed files with 15 additions and 8 deletions

View File

@ -74,7 +74,6 @@ const StillImage: React.FC<IStillImage> = ({
className={clsx(baseClassName, {
'invisible group-hover:visible': hoverToPlay,
})}
crossOrigin='anonymous'
/>
{hoverToPlay && (

View File

@ -1,12 +1,14 @@
import clsx from 'clsx';
import { FastAverageColor } from 'fast-average-color';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { defineMessages, useIntl } from 'react-intl';
import StillImage, { IStillImage } from 'pl-fe/components/still-image';
import Icon from './icon';
const COLOR_CACHE = new Map<string, string>();
const AVATAR_SIZE = 42;
const messages = defineMessages({
@ -33,12 +35,19 @@ const Avatar = (props: IAvatar) => {
const handleLoadFailure = () => setIsAvatarMissing(true);
const handleLoad = (e: React.SyntheticEvent<HTMLImageElement>) => {
const color = fac.getColor(e.currentTarget);
if (!color.error) {
setColor(color.hex);
useEffect(() => {
if (COLOR_CACHE.has(src)) {
setColor(COLOR_CACHE.get(src));
return;
}
};
fac.getColorAsync(src).then(color => {
if (!color.error) {
COLOR_CACHE.set(src, color.hex);
setColor(color.hex);
}
}).catch(() => setColor(undefined));
}, [src]);
const style: React.CSSProperties = React.useMemo(() => ({
width: size,
@ -73,7 +82,6 @@ const Avatar = (props: IAvatar) => {
src={src}
alt={alt || intl.formatMessage(messages.avatar)}
onError={handleLoadFailure}
onLoad={handleLoad}
/>
);
};