2024-09-08 21:35:32 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { useLiveQuery } from "dexie-react-hooks";
|
2024-09-11 22:10:16 +00:00
|
|
|
import { config } from "../../config";
|
2024-09-30 21:16:55 +00:00
|
|
|
import { getImageUrl } from "@/common/image-utils";
|
2024-09-08 21:35:32 +00:00
|
|
|
import useDatabase from "../hooks/use-database";
|
|
|
|
|
2024-10-01 20:10:30 +00:00
|
|
|
export default function BackgroundCover() {
|
2024-09-08 21:35:32 +00:00
|
|
|
const database = useDatabase();
|
|
|
|
const settings = useLiveQuery(() => database.getSettings());
|
|
|
|
|
2024-09-30 21:16:55 +00:00
|
|
|
if (settings == undefined || settings?.backgroundImage == undefined || settings?.backgroundImage == "") {
|
2024-09-08 21:35:32 +00:00
|
|
|
return null; // Don't render anything if the background image is not set
|
|
|
|
}
|
|
|
|
|
2024-09-09 07:47:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-10-01 20:10:30 +00:00
|
|
|
// Static background color
|
|
|
|
if (backgroundImage.startsWith("#")) {
|
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={`fixed -z-50 object-cover w-screen h-screen pointer-events-none select-none`}
|
|
|
|
style={{ backgroundColor: backgroundImage }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-09-08 21:35:32 +00:00
|
|
|
return (
|
|
|
|
// eslint-disable-next-line @next/next/no-img-element
|
|
|
|
<img
|
2024-09-09 07:47:41 +00:00
|
|
|
src={getImageUrl(backgroundImage)}
|
2024-09-08 21:35:32 +00:00
|
|
|
alt="Background image"
|
2024-09-11 17:39:46 +00:00
|
|
|
fetchPriority="high"
|
2024-09-11 19:10:27 +00:00
|
|
|
className={`fixed -z-50 object-cover w-screen h-screen blur-sm brightness-[33%] pointer-events-none select-none`}
|
2024-09-08 21:35:32 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|