final checks #14

Merged
guus merged 3 commits from mark into master 2025-08-03 20:22:17 +02:00
4 changed files with 24 additions and 23 deletions
Showing only changes of commit 67d8dac8c0 - Show all commits
+6 -15
View File
@@ -8,26 +8,19 @@ import AuthStatus from "muzak/components/AuthStatus";
import NavigationBar from "muzak/components/NavigationBar"; import NavigationBar from "muzak/components/NavigationBar";
import Quota from "muzak/components/Quota"; import Quota from "muzak/components/Quota";
import { AnimationContext } from "muzak/contexts/AnimationContext"; import { AnimationContext } from "muzak/contexts/AnimationContext";
import { QuotaContext } from "muzak/contexts/QuotaContext";
const nunito = Nunito({ const nunito = Nunito({
subsets: ["latin"], subsets: ["latin"],
}); });
function LayoutContent({ function LayoutContent({ children }: { children: React.ReactNode }) {
children,
quota,
setQuota,
}: {
children: React.ReactNode;
quota: number | null;
setQuota: React.Dispatch<React.SetStateAction<number | null>>;
}) {
return ( return (
<> <>
<AuthStatus /> <AuthStatus />
{children} {children}
{/* <NavigationBar /> */} {/* <NavigationBar /> */}
<Quota quota={quota} setQuota={setQuota} /> <Quota />
</> </>
); );
} }
@@ -49,11 +42,9 @@ export default function RootLayout({
<body className={`bg-game-show ${isAnimate ? "animate" : ""} h-screen`}> <body className={`bg-game-show ${isAnimate ? "animate" : ""} h-screen`}>
<AuthProvider {...oidcConfig}> <AuthProvider {...oidcConfig}>
<AnimationContext.Provider value={{ isAnimate, setIsAnimate }}> <AnimationContext.Provider value={{ isAnimate, setIsAnimate }}>
<LayoutContent <QuotaContext.Provider value={{ quota, setQuota }}>
children={children} <LayoutContent children={children} />
quota={quota} </QuotaContext.Provider>
setQuota={setQuota}
/>
</AnimationContext.Provider> </AnimationContext.Provider>
</AuthProvider> </AuthProvider>
</body> </body>
+3 -1
View File
@@ -3,6 +3,7 @@ import { useState } from "react";
import { Nunito } from "next/font/google"; import { Nunito } from "next/font/google";
import { api } from "muzak/data/fetcher"; import { api } from "muzak/data/fetcher";
import { useAnimation } from "muzak/contexts/AnimationContext"; import { useAnimation } from "muzak/contexts/AnimationContext";
import { useQuota } from "muzak/contexts/QuotaContext";
const nunito = Nunito({ const nunito = Nunito({
weight: "900", weight: "900",
@@ -16,7 +17,7 @@ export default function Nominations() {
const [message, setMessage] = useState(""); const [message, setMessage] = useState("");
const isSpotifyURL = const isSpotifyURL =
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}/.test(songURL); /^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}/.test(songURL);
const { quota, setQuota } = useQuota();
async function nominate(spotifyLink: string) { async function nominate(spotifyLink: string) {
try { try {
setIsAnimate(false); setIsAnimate(false);
@@ -25,6 +26,7 @@ export default function Nominations() {
}); });
console.log("Nomination successful:", response); console.log("Nomination successful:", response);
setIsAnimate(true); setIsAnimate(true);
setQuota(quota - 1);
return { success: true, data: response.data }; return { success: true, data: response.data };
} catch (error) { } catch (error) {
console.error("Nomination failed:", error); console.error("Nomination failed:", error);
+3 -7
View File
@@ -3,18 +3,14 @@ import { useAuth } from "react-oidc-context";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { Nunito } from "next/font/google"; import { Nunito } from "next/font/google";
import { api, Profile } from "muzak/data/fetcher"; import { api, Profile } from "muzak/data/fetcher";
import { useQuota } from "muzak/contexts/QuotaContext";
const nunito = Nunito({ const nunito = Nunito({
subsets: ["latin"], subsets: ["latin"],
}); });
export default function Quota({ export default function Quota() {
quota,
setQuota,
}: {
quota: number | null;
setQuota: React.Dispatch<React.SetStateAction<number | null>>;
}) {
const auth = useAuth(); const auth = useAuth();
const { quota, setQuota } = useQuota();
async function getProfile() { async function getProfile() {
if (!auth.isLoading && !auth.error && auth.isAuthenticated) { if (!auth.isLoading && !auth.error && auth.isAuthenticated) {
const { data: profile } = await api?.profiles?.me({}); const { data: profile } = await api?.profiles?.me({});
+12
View File
@@ -0,0 +1,12 @@
"use client";
import { createContext, useContext } from "react";
interface QuotaContextType {
quota: number;
setQuota: React.Dispatch<React.SetStateAction<number>>;
}
const QuotaContext = createContext<QuotaContextType>({} as QuotaContextType);
export const useQuota = () => useContext(QuotaContext);
export { QuotaContext };