final checks #14
@@ -8,26 +8,19 @@ import AuthStatus from "muzak/components/AuthStatus";
|
||||
import NavigationBar from "muzak/components/NavigationBar";
|
||||
import Quota from "muzak/components/Quota";
|
||||
import { AnimationContext } from "muzak/contexts/AnimationContext";
|
||||
import { QuotaContext } from "muzak/contexts/QuotaContext";
|
||||
|
||||
const nunito = Nunito({
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
function LayoutContent({
|
||||
children,
|
||||
quota,
|
||||
setQuota,
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
quota: number | null;
|
||||
setQuota: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
}) {
|
||||
function LayoutContent({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<>
|
||||
<AuthStatus />
|
||||
{children}
|
||||
{/* <NavigationBar /> */}
|
||||
<Quota quota={quota} setQuota={setQuota} />
|
||||
<Quota />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -49,11 +42,9 @@ export default function RootLayout({
|
||||
<body className={`bg-game-show ${isAnimate ? "animate" : ""} h-screen`}>
|
||||
<AuthProvider {...oidcConfig}>
|
||||
<AnimationContext.Provider value={{ isAnimate, setIsAnimate }}>
|
||||
<LayoutContent
|
||||
children={children}
|
||||
quota={quota}
|
||||
setQuota={setQuota}
|
||||
/>
|
||||
<QuotaContext.Provider value={{ quota, setQuota }}>
|
||||
<LayoutContent children={children} />
|
||||
</QuotaContext.Provider>
|
||||
</AnimationContext.Provider>
|
||||
</AuthProvider>
|
||||
</body>
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useState } from "react";
|
||||
import { Nunito } from "next/font/google";
|
||||
import { api } from "muzak/data/fetcher";
|
||||
import { useAnimation } from "muzak/contexts/AnimationContext";
|
||||
import { useQuota } from "muzak/contexts/QuotaContext";
|
||||
|
||||
const nunito = Nunito({
|
||||
weight: "900",
|
||||
@@ -16,7 +17,7 @@ export default function Nominations() {
|
||||
const [message, setMessage] = useState("");
|
||||
const isSpotifyURL =
|
||||
/^https:\/\/open\.spotify\.com\/track\/[a-zA-Z0-9]{22}/.test(songURL);
|
||||
|
||||
const { quota, setQuota } = useQuota();
|
||||
async function nominate(spotifyLink: string) {
|
||||
try {
|
||||
setIsAnimate(false);
|
||||
@@ -25,6 +26,7 @@ export default function Nominations() {
|
||||
});
|
||||
console.log("Nomination successful:", response);
|
||||
setIsAnimate(true);
|
||||
setQuota(quota - 1);
|
||||
return { success: true, data: response.data };
|
||||
} catch (error) {
|
||||
console.error("Nomination failed:", error);
|
||||
|
||||
@@ -3,18 +3,14 @@ import { useAuth } from "react-oidc-context";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Nunito } from "next/font/google";
|
||||
import { api, Profile } from "muzak/data/fetcher";
|
||||
import { useQuota } from "muzak/contexts/QuotaContext";
|
||||
const nunito = Nunito({
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export default function Quota({
|
||||
quota,
|
||||
setQuota,
|
||||
}: {
|
||||
quota: number | null;
|
||||
setQuota: React.Dispatch<React.SetStateAction<number | null>>;
|
||||
}) {
|
||||
export default function Quota() {
|
||||
const auth = useAuth();
|
||||
const { quota, setQuota } = useQuota();
|
||||
async function getProfile() {
|
||||
if (!auth.isLoading && !auth.error && auth.isAuthenticated) {
|
||||
const { data: profile } = await api?.profiles?.me({});
|
||||
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user