diff --git a/src/App.jsx b/src/App.jsx index f148345..fd53659 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -3,7 +3,6 @@ import React, { useState, Suspense } from "react"; import { ThemeProvider } from "@mui/material/styles"; import { SnackbarProvider } from "notistack"; -import { useCookies, Cookies } from "react-cookie"; import { Routes, Route, @@ -118,12 +117,16 @@ const AnimationWrapper = () => { }; function App() { - const [userCookies] = useCookies(["user"]); const navigate = useNavigate(); const [serverReachable, setServerReachable] = useState(true); const [checkingServer, setChecking] = useState(false); + const createApi = async () => { + const server = await getServer(); + event.emit("create-jellyfin-api", server.Ip); + }; + const serverAvailable = async () => { const server = await getServer(); @@ -131,10 +134,10 @@ function App() { console.log("server not found"); return false; } else { - if (!window.api) { - console.log("Creating Jf api (without accessToken)"); - event.emit("create-jellyfin-api", server.Ip); - } + // if (!window.api) { + // console.log("Creating Jf api (without accessToken)"); + // event.emit("create-jellyfin-api", server.Ip); + // } return true; } }; @@ -194,7 +197,7 @@ function App() { sessionStorage.setItem("accessToken", auth.data.AccessToken); event.emit("set-api-accessToken", window.api.basePath); - navigate("/home"); + // navigate("/home"); }; const LogicalRoutes = () => { @@ -204,7 +207,7 @@ function App() { if (serverReachable == true) { userSaved().then((user_available) => { if (user_available == true) { - userLogin(); + navigate("/home"); } else { usersAvailable().then( (users_list_available) => { @@ -244,6 +247,17 @@ function App() { }; const location = useLocation(); + if (!window.api) { + console.log("WindowAPi not present"); + createApi().then( + userSaved().then((userSavedBool) => { + if (userSavedBool) { + userLogin(); + } + }), + ); + } + return ( diff --git a/src/components/card/card.jsx b/src/components/card/card.jsx index 9cfd016..fa16c0e 100644 --- a/src/components/card/card.jsx +++ b/src/components/card/card.jsx @@ -49,7 +49,9 @@ export const Card = ({ aspectRatio: cardOrientation == "landscape" ? "1.777" - : "0.666", + : cardOrientation == "portait" + ? "0.666" + : "1", }} > {imageTags && @@ -68,7 +70,10 @@ export const Card = ({ aspectRatio: cardOrientation == "landscape" ? "1.777" - : "0.666", + : cardOrientation == + "portait" + ? "0.666" + : "1", }} className="card-image" > @@ -87,7 +92,10 @@ export const Card = ({ aspectRatio: cardOrientation == "landscape" ? "1.777" - : "0.666", + : cardOrientation == + "portait" + ? "0.666" + : "1", }} className="card-image" > diff --git a/src/components/homeSection/latestMediaSection.jsx b/src/components/homeSection/latestMediaSection.jsx index 9947c57..b995979 100644 --- a/src/components/homeSection/latestMediaSection.jsx +++ b/src/components/homeSection/latestMediaSection.jsx @@ -60,7 +60,11 @@ export const LatestMediaSection = ({ latestMediaLib }) => { playedPercent={ item.UserData.PlayedPercentage } - cardOrientation="portait" + cardOrientation={ + item.PrimaryImageAspectRatio == 1 + ? "sqaure" + : "portait" + } > ); })} diff --git a/src/routes/home/root.jsx b/src/routes/home/root.jsx index 970acce..dccb929 100644 --- a/src/routes/home/root.jsx +++ b/src/routes/home/root.jsx @@ -69,7 +69,7 @@ const Home = () => { event.emit("set-api-accessToken", window.api.basePath); return true; }, - enabled: !window.api, + enabled: false, }); const user = useQuery({ @@ -633,7 +633,7 @@ const Home = () => { item.UserData .PlayedPercentage } - cardOrientation="landscape" + cardOrientation="sqaure" > ); }, diff --git a/src/routes/login/root.jsx b/src/routes/login/root.jsx index 7508e21..4a68ec1 100644 --- a/src/routes/login/root.jsx +++ b/src/routes/login/root.jsx @@ -1,7 +1,6 @@ /** @format */ import { useState, useEffect, useMemo } from "react"; -import { Cookies, useCookies } from "react-cookie"; import { useQuery } from "@tanstack/react-query"; import { useNavigate, useParams, Link } from "react-router-dom"; import { EventEmitter as event } from "../../eventEmitter.js"; @@ -30,6 +29,8 @@ import FormControlLabel from "@mui/material/FormControlLabel"; import Checkbox from "@mui/material/Checkbox"; import { AvatarCard, AvatarImage } from "../../components/avatar/avatar.jsx"; +import { CardScroller } from "../../components/cardScroller/cardScroller.jsx"; +import { Card } from "../../components/card/card.jsx"; import { AppBarBackOnly } from "../../components/appBar/backOnly.jsx"; // import { jellyfin } from "../../jellyfin"; @@ -38,6 +39,7 @@ import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api"; import "./login.module.scss"; +import { CardsSkeleton } from "../../components/skeleton/cards.jsx"; export const LoginWithImage = () => { const { userName, userId } = useParams(); @@ -88,7 +90,6 @@ export const LoginWithImage = () => { saveUser(userName, password.password); } event.emit("set-api-accessToken", window.api.basePath); - // setAccessToken(user.data.AccessToken) setLoading(false); navigate(`/home`); }; @@ -217,68 +218,52 @@ export const UserLogin = () => { const handleManualLogin = () => { navigate("/login/manual"); }; - const getUsers = async () => { - const users = await getUserApi(window.api).getPublicUsers(); - // console.log(users.data); - return users; - // return {}; - }; - - const createApi = async () => { - const server = await getServer(); - event.emit("create-jellyfin-api", server.Ip); - }; - - useMemo(() => { - // TODO Implement a better way to check and create api object when page reloaded. Hint: Maybe use session api or something (*route - login*) - if (!window.api) { - createApi().then(() => { - getUsers().then((users) => { - setUsers(users.data); - console.log(userList); - }); - }); - } else { - getUsers().then((users) => { - setUsers(users.data); - console.log(userList); - }); - } - }, []); + const users = useQuery({ + queryKey: ["login", "users"], + queryFn: async () => { + const users = await getUserApi(window.api).getPublicUsers(); + // console.log(users.data); + return users.data; + // return {}; + }, + }); return ( <> - + {/* Users - -
- {userList.map((item, index) => { - return ( - // - - {item.PrimaryImageTag ? ( - - ) : ( - - )} - - ); - })} -
+
*/} + {users.isLoading ? ( + + ) : ( + + {users.data.map((item, index) => { + return ( + // + + + + ); + })} + + )}