mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
af18aef42a
- Remove auto-refresh timer from Random Albums (caused 100ms progress interval + 30 concurrent fetches every 30s, eventually freezing the app) - Limit concurrent image fetches to 5 (was unbounded) - Cap in-memory object URL cache at 150 entries with revokeObjectURL eviction - Add cancellation flag to useCachedUrl to prevent setState on unmounted components - Fix hardcoded "Neueste" page title in New Releases (now uses i18n) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
24 lines
816 B
TypeScript
24 lines
816 B
TypeScript
import React, { useEffect, useState } from 'react';
|
|
import { getCachedUrl } from '../utils/imageCache';
|
|
|
|
interface CachedImageProps extends React.ImgHTMLAttributes<HTMLImageElement> {
|
|
src: string;
|
|
cacheKey: string;
|
|
}
|
|
|
|
export function useCachedUrl(fetchUrl: string, cacheKey: string): string {
|
|
const [resolved, setResolved] = useState('');
|
|
useEffect(() => {
|
|
if (!fetchUrl) { setResolved(''); return; }
|
|
let cancelled = false;
|
|
getCachedUrl(fetchUrl, cacheKey).then(url => { if (!cancelled) setResolved(url); });
|
|
return () => { cancelled = true; };
|
|
}, [fetchUrl, cacheKey]);
|
|
return resolved || fetchUrl;
|
|
}
|
|
|
|
export default function CachedImage({ src, cacheKey, ...props }: CachedImageProps) {
|
|
const resolvedSrc = useCachedUrl(src, cacheKey);
|
|
return <img src={resolvedSrc} {...props} />;
|
|
}
|