Refactor page components to use NavigationWrapper and integrate Prisma for data fetching. Update EventsSection and LeaderboardSection to accept props for events and leaderboard data, enhancing performance and user experience. Implement user authentication in ProfilePage and AdminPage, ensuring secure access to user data.
This commit is contained in:
25
lib/preferences.ts
Normal file
25
lib/preferences.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function getBackgroundImage(
|
||||
page: "home" | "events" | "leaderboard",
|
||||
defaultImage: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
const sitePreferences = await prisma.sitePreferences.findUnique({
|
||||
where: { id: "global" },
|
||||
});
|
||||
|
||||
if (!sitePreferences) {
|
||||
return defaultImage;
|
||||
}
|
||||
|
||||
const imageKey = `${page}Background` as keyof typeof sitePreferences;
|
||||
const customImage = sitePreferences[imageKey];
|
||||
|
||||
return customImage || defaultImage;
|
||||
} catch (error) {
|
||||
console.error("Error fetching background image:", error);
|
||||
return defaultImage;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user