This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
scoresaber-reloadedv3/apps/frontend/src/components/background-image.tsx
Liam e0833d17f1
All checks were successful
Deploy Frontend / deploy (push) Successful in 4m3s
j
2024-10-04 16:43:12 +01:00

38 lines
1.2 KiB
TypeScript

"use client";
import { useLiveQuery } from "dexie-react-hooks";
import { config } from "../../config";
import { getImageUrl } from "@/common/image-utils";
import useDatabase from "../hooks/use-database";
export default function BackgroundImage() {
const database = useDatabase();
const settings = useLiveQuery(() => database.getSettings());
if (settings == undefined || settings?.backgroundImage == undefined || settings?.backgroundImage == "") {
return null; // Don't render anything if the background image is not set
}
let backgroundImage = settings.backgroundImage;
let prependWebsiteUrl = false;
// Remove the prepending slash
if (backgroundImage.startsWith("/")) {
prependWebsiteUrl = true;
backgroundImage = backgroundImage.substring(1);
}
if (prependWebsiteUrl) {
backgroundImage = config.siteUrl + "/" + backgroundImage;
}
return (
// eslint-disable-next-line @next/next/no-img-element
<img
src={getImageUrl(backgroundImage)}
alt="Background image"
fetchPriority="high"
className={`fixed -z-50 object-cover w-screen h-screen blur-sm brightness-[33%] pointer-events-none select-none`}
/>
);
}