mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
preload banners regardless of number
This commit is contained in:
+9
-6
@@ -12,6 +12,7 @@ import 'react-tooltip/dist/react-tooltip.css';
|
|||||||
import 'react-toastify/dist/ReactToastify.css';
|
import 'react-toastify/dist/ReactToastify.css';
|
||||||
import preloadImages from './utils/preloadImages';
|
import preloadImages from './utils/preloadImages';
|
||||||
import { ToastContainer } from 'react-toastify';
|
import { ToastContainer } from 'react-toastify';
|
||||||
|
import { importAll } from './components/ImageBanner';
|
||||||
|
|
||||||
|
|
||||||
const GlobalStyle = createGlobalStyle`
|
const GlobalStyle = createGlobalStyle`
|
||||||
@@ -60,18 +61,20 @@ export default function App() {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const isHomeRoute = location.pathname === "/";
|
const isHomeRoute = location.pathname === "/";
|
||||||
|
|
||||||
|
// preload banners
|
||||||
// preload images
|
|
||||||
const imageUrls = Array.from({ length: 14 }, (_, index) => `/assets/banners/banner-${index + 1}.jpg`);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
preloadImages([...imageUrls]);
|
const loadImages = async () => {
|
||||||
|
const images = await importAll(require.context('../public/assets/banners', false, /\.(png|jpe?g|svg)$/));
|
||||||
|
const imageUrls = images.map((image) => image.default);
|
||||||
|
preloadImages(imageUrls);
|
||||||
|
};
|
||||||
|
|
||||||
|
loadImages();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
||||||
// automatic dark mode without interefering with user's selected style
|
// automatic dark mode without interefering with user's selected style
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
if (isHomeRoute) return;
|
if (isHomeRoute) return;
|
||||||
|
|
||||||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ const ImageBanner = () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Helper function to import all images from a directory
|
export function importAll(r) {
|
||||||
function importAll(r) {
|
|
||||||
return r.keys().map(r);
|
return r.keys().map(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user