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:
2025-08-03 20:22:15 +02:00
5 changed files with 28 additions and 25 deletions
+1 -1
View File
@@ -62,7 +62,7 @@ class VoteView(LoginRequiredMixin, View):
class NominateView(LoginRequiredMixin, View):
def get(self, request):
(profile,_) = Profile.objects.get_or_create(user=request.user)
profile.update_quota()
#profile.update_quota()
profile.save()
return TemplateResponse(request, "Nominate.html", {'end_time': os.getenv('DATE_NOM_END')})
def post(self, request):
+6 -15
View File
@@ -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>
+6 -2
View File
@@ -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",
@@ -15,8 +16,10 @@ export default function Nominations() {
const [isLoading, setIsLoading] = useState(false);
const [message, setMessage] = useState("");
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) {
try {
setIsAnimate(false);
@@ -25,6 +28,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 -7
View File
@@ -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({});
+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 };