session link with mobile voting
This commit is contained in:
@@ -6,6 +6,7 @@ import { useRouter, usePathname } from "next/navigation";
|
||||
import { api, Session } from "muzak/data/fetcher";
|
||||
import { getUser } from "muzak/data/fetcher";
|
||||
import { useSession } from "muzak/contexts/SessionContext";
|
||||
import getSessionId from "muzak/data/session";
|
||||
|
||||
export default function SessionChecker() {
|
||||
const auth = useAuth();
|
||||
@@ -15,30 +16,31 @@ export default function SessionChecker() {
|
||||
const [link, setLink] = useState("/lobby");
|
||||
const { sessionId, setSessionId } = useSession();
|
||||
|
||||
async function getSessions() {
|
||||
if (!auth.isLoading && !auth.error && auth.isAuthenticated) {
|
||||
const { data: sessions } = await api?.sessions?.list({});
|
||||
console.log(sessions);
|
||||
if (sessions?.length > 0) {
|
||||
setIsSession(true);
|
||||
const user = getUser();
|
||||
setSessionId(sessions[0].session_id);
|
||||
if (sessions[0].host === user?.profile?.email) {
|
||||
setLink("/lobby");
|
||||
} else {
|
||||
setLink("/session");
|
||||
}
|
||||
} else {
|
||||
setIsSession(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// async function getSessions() {
|
||||
// if (!auth.isLoading && !auth.error && auth.isAuthenticated) {
|
||||
// const { data: sessions } = await api?.sessions?.list({});
|
||||
// console.log(sessions);
|
||||
// if (sessions?.length > 0) {
|
||||
// setIsSession(true);
|
||||
// const user = getUser();
|
||||
// setSessionId(sessions[0].session_id);
|
||||
// if (sessions[0].host === user?.profile?.email) {
|
||||
// setLink("/lobby");
|
||||
// } else {
|
||||
// setLink("/session");
|
||||
// }
|
||||
// } else {
|
||||
// setIsSession(false);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
useEffect(() => {
|
||||
getSessions();
|
||||
getSessionId();
|
||||
console.log("hheufheufh");
|
||||
}, [auth]);
|
||||
|
||||
if (isSession) {
|
||||
if (sessionId) {
|
||||
return (
|
||||
<Link
|
||||
href={link}
|
||||
|
||||
Reference in New Issue
Block a user