nominate animation
This commit is contained in:
+24
-14
@@ -1,6 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
import { useState } from "react";
|
import { useState, createContext, useContext } from "react";
|
||||||
import { AuthProvider } from "react-oidc-context";
|
import { AuthProvider } from "react-oidc-context";
|
||||||
import { oidcConfig, userManager } from "muzak/config/auth";
|
import { oidcConfig, userManager } from "muzak/config/auth";
|
||||||
import { Source_Sans_3, Nunito } from "next/font/google";
|
import { Source_Sans_3, Nunito } from "next/font/google";
|
||||||
@@ -8,10 +8,22 @@ 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";
|
||||||
|
|
||||||
const sourceSans = Source_Sans_3({
|
interface AnimationContextType {
|
||||||
weight: ["400"],
|
isAnimate: boolean;
|
||||||
subsets: ["latin"],
|
setIsAnimate: React.Dispatch<React.SetStateAction<boolean>>;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const AnimationContext = createContext<AnimationContextType | undefined>(
|
||||||
|
undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const useAnimation = () => {
|
||||||
|
const context = useContext(AnimationContext);
|
||||||
|
if (context === undefined) {
|
||||||
|
throw new Error("useAnimation must be used within an AnimationProvider");
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
|
|
||||||
const nunito = Nunito({
|
const nunito = Nunito({
|
||||||
subsets: ["latin"],
|
subsets: ["latin"],
|
||||||
@@ -52,16 +64,14 @@ export default function RootLayout({
|
|||||||
<html lang="en" className={nunito.className}>
|
<html lang="en" className={nunito.className}>
|
||||||
<body className={`bg-game-show ${isAnimate ? "animate" : ""} h-screen`}>
|
<body className={`bg-game-show ${isAnimate ? "animate" : ""} h-screen`}>
|
||||||
<AuthProvider {...oidcConfig}>
|
<AuthProvider {...oidcConfig}>
|
||||||
<LayoutContent
|
<AnimationContext.Provider value={{ isAnimate, setIsAnimate }}>
|
||||||
children={children}
|
<LayoutContent
|
||||||
quota={quota}
|
children={children}
|
||||||
setQuota={setQuota}
|
quota={quota}
|
||||||
/>
|
setQuota={setQuota}
|
||||||
|
/>
|
||||||
|
</AnimationContext.Provider>
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
<button
|
|
||||||
className={`absolute top-1 left-1 ${isAnimate ? "pause" : "play"}`}
|
|
||||||
onClick={toggleAnimation}
|
|
||||||
></button>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,30 +2,32 @@
|
|||||||
import { useState } from "react";
|
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 "../layout";
|
||||||
|
|
||||||
const nunito = Nunito({
|
const nunito = Nunito({
|
||||||
weight: "900",
|
weight: "900",
|
||||||
subsets: ["latin"],
|
subsets: ["latin"],
|
||||||
});
|
});
|
||||||
|
|
||||||
async function nominate(spotifyLink: string) {
|
|
||||||
console.log(spotifyLink);
|
|
||||||
try {
|
|
||||||
const response = await api.tracks.nominate({
|
|
||||||
spotify_link: spotifyLink,
|
|
||||||
});
|
|
||||||
console.log("Nomination successful:", response);
|
|
||||||
return { success: true, data: response.data };
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Nomination failed:", error);
|
|
||||||
return { success: false, error };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Nominations() {
|
export default function Nominations() {
|
||||||
|
const { isAnimate, setIsAnimate } = useAnimation();
|
||||||
const [songURL, setSongURL] = useState("");
|
const [songURL, setSongURL] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [message, setMessage] = useState("");
|
const [message, setMessage] = useState("");
|
||||||
|
async function nominate(spotifyLink: string) {
|
||||||
|
try {
|
||||||
|
setIsAnimate(false);
|
||||||
|
const response = await api.tracks.nominate({
|
||||||
|
spotify_link: spotifyLink,
|
||||||
|
});
|
||||||
|
console.log("Nomination successful:", response);
|
||||||
|
setIsAnimate(true);
|
||||||
|
return { success: true, data: response.data };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Nomination failed:", error);
|
||||||
|
return { success: false, error };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
<main className="flex min-h-screen flex-col items-center justify-between p-24">
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.bg-game-show.animate {
|
.bg-game-show.animate {
|
||||||
animation: rotate_bg 5s cubic-bezier(0.55, 0.45, 0.45, 0.55) infinite;
|
animation: rotate_bg 1.5s ease-in-out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes rotate_bg {
|
@keyframes rotate_bg {
|
||||||
|
|||||||
Reference in New Issue
Block a user