From 3eadd5c15d1b1c1d4e0ecdbbf74cf6abe017c820 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 3 Aug 2025 19:45:21 +0200 Subject: [PATCH 1/3] no more update quota --- backend/playlist/views/static.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/playlist/views/static.py b/backend/playlist/views/static.py index 4f8dc3f..1f9d5e2 100644 --- a/backend/playlist/views/static.py +++ b/backend/playlist/views/static.py @@ -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): -- 2.52.0 From 67d8dac8c0673f5a9ee1ede84834ce1e00c1a364 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 3 Aug 2025 19:59:01 +0200 Subject: [PATCH 2/3] quota context hook --- frontend/src/app/layout.tsx | 21 ++++++--------------- frontend/src/app/nominations/page.tsx | 4 +++- frontend/src/components/Quota.tsx | 10 +++------- frontend/src/contexts/QuotaContext.tsx | 12 ++++++++++++ 4 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 frontend/src/contexts/QuotaContext.tsx diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx index 183cf27..2d0767c 100644 --- a/frontend/src/app/layout.tsx +++ b/frontend/src/app/layout.tsx @@ -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>; -}) { +function LayoutContent({ children }: { children: React.ReactNode }) { return ( <> {children} {/* */} - + ); } @@ -49,11 +42,9 @@ export default function RootLayout({ - + + + diff --git a/frontend/src/app/nominations/page.tsx b/frontend/src/app/nominations/page.tsx index 3a3bd3f..a0a2669 100644 --- a/frontend/src/app/nominations/page.tsx +++ b/frontend/src/app/nominations/page.tsx @@ -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); diff --git a/frontend/src/components/Quota.tsx b/frontend/src/components/Quota.tsx index 7c52f7a..90aa678 100644 --- a/frontend/src/components/Quota.tsx +++ b/frontend/src/components/Quota.tsx @@ -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>; -}) { +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({}); diff --git a/frontend/src/contexts/QuotaContext.tsx b/frontend/src/contexts/QuotaContext.tsx new file mode 100644 index 0000000..5b1fc2e --- /dev/null +++ b/frontend/src/contexts/QuotaContext.tsx @@ -0,0 +1,12 @@ +"use client"; +import { createContext, useContext } from "react"; + +interface QuotaContextType { + quota: number; + setQuota: React.Dispatch>; +} +const QuotaContext = createContext({} as QuotaContextType); + +export const useQuota = () => useContext(QuotaContext); + +export { QuotaContext }; -- 2.52.0 From 421a00466756728e09f32af97842cfab5507eeb5 Mon Sep 17 00:00:00 2001 From: Mark Hoekveen Date: Sun, 3 Aug 2025 20:21:13 +0200 Subject: [PATCH 3/3] small regex update --- frontend/src/app/nominations/page.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/nominations/page.tsx b/frontend/src/app/nominations/page.tsx index a0a2669..c06082f 100644 --- a/frontend/src/app/nominations/page.tsx +++ b/frontend/src/app/nominations/page.tsx @@ -16,7 +16,9 @@ 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 { -- 2.52.0