Merge pull request 'final checks' (#14) from mark into master
Reviewed-on: #14
This commit was merged in pull request #14.
This commit is contained in:
@@ -62,7 +62,7 @@ class VoteView(LoginRequiredMixin, View):
|
|||||||
class NominateView(LoginRequiredMixin, View):
|
class NominateView(LoginRequiredMixin, View):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
(profile,_) = Profile.objects.get_or_create(user=request.user)
|
(profile,_) = Profile.objects.get_or_create(user=request.user)
|
||||||
profile.update_quota()
|
#profile.update_quota()
|
||||||
profile.save()
|
profile.save()
|
||||||
return TemplateResponse(request, "Nominate.html", {'end_time': os.getenv('DATE_NOM_END')})
|
return TemplateResponse(request, "Nominate.html", {'end_time': os.getenv('DATE_NOM_END')})
|
||||||
def post(self, request):
|
def post(self, request):
|
||||||
|
|||||||
@@ -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,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",
|
||||||
@@ -15,8 +16,10 @@ export default function Nominations() {
|
|||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
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 +28,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,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({});
|
||||||
|
|||||||
@@ -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