Add sqaure cards #24, fix cards in login page

This commit is contained in:
prayag17 committed 2023-03-28 11:26:24 +05:30
1 parent aebea6a3b2
commit f12d92f42c
7 files changed
+68 -131

No files matched your search

+22 -8
View File
@@ -3,7 +3,6 @@
import React, { useState, Suspense } from "react"; import React, { useState, Suspense } from "react";
import { ThemeProvider } from "@mui/material/styles"; import { ThemeProvider } from "@mui/material/styles";
import { SnackbarProvider } from "notistack"; import { SnackbarProvider } from "notistack";
import { useCookies, Cookies } from "react-cookie";
import { import {
Routes, Routes,
Route, Route,
@@ -118,12 +117,16 @@ const AnimationWrapper = () => {
}; };
function App() { function App() {
const [userCookies] = useCookies(["user"]);
const navigate = useNavigate(); const navigate = useNavigate();
const [serverReachable, setServerReachable] = useState(true); const [serverReachable, setServerReachable] = useState(true);
const [checkingServer, setChecking] = useState(false); const [checkingServer, setChecking] = useState(false);
const createApi = async () => {
const server = await getServer();
event.emit("create-jellyfin-api", server.Ip);
};
const serverAvailable = async () => { const serverAvailable = async () => {
const server = await getServer(); const server = await getServer();
@@ -131,10 +134,10 @@ function App() {
console.log("server not found"); console.log("server not found");
return false; return false;
} else { } else {
if (!window.api) { // if (!window.api) {
console.log("Creating Jf api (without accessToken)"); // console.log("Creating Jf api (without accessToken)");
event.emit("create-jellyfin-api", server.Ip); // event.emit("create-jellyfin-api", server.Ip);
} // }
return true; return true;
} }
}; };
@@ -194,7 +197,7 @@ function App() {
sessionStorage.setItem("accessToken", auth.data.AccessToken); sessionStorage.setItem("accessToken", auth.data.AccessToken);
event.emit("set-api-accessToken", window.api.basePath); event.emit("set-api-accessToken", window.api.basePath);
navigate("/home"); // navigate("/home");
}; };
const LogicalRoutes = () => { const LogicalRoutes = () => {
@@ -204,7 +207,7 @@ function App() {
if (serverReachable == true) { if (serverReachable == true) {
userSaved().then((user_available) => { userSaved().then((user_available) => {
if (user_available == true) { if (user_available == true) {
userLogin(); navigate("/home");
} else { } else {
usersAvailable().then( usersAvailable().then(
(users_list_available) => { (users_list_available) => {
@@ -244,6 +247,17 @@ function App() {
}; };
const location = useLocation(); const location = useLocation();
if (!window.api) {
console.log("WindowAPi not present");
createApi().then(
userSaved().then((userSavedBool) => {
if (userSavedBool) {
userLogin();
}
}),
);
}
return ( return (
<SnackbarProvider maxSnack={5}> <SnackbarProvider maxSnack={5}>
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
+11 -3
View File
@@ -49,7 +49,9 @@ export const Card = ({
aspectRatio: aspectRatio:
cardOrientation == "landscape" cardOrientation == "landscape"
? "1.777" ? "1.777"
: "0.666", : cardOrientation == "portait"
? "0.666"
: "1",
}} }}
> >
{imageTags && {imageTags &&
@@ -68,7 +70,10 @@ export const Card = ({
aspectRatio: aspectRatio:
cardOrientation == "landscape" cardOrientation == "landscape"
? "1.777" ? "1.777"
: "0.666", : cardOrientation ==
"portait"
? "0.666"
: "1",
}} }}
className="card-image" className="card-image"
></CardMedia> ></CardMedia>
@@ -87,7 +92,10 @@ export const Card = ({
aspectRatio: aspectRatio:
cardOrientation == "landscape" cardOrientation == "landscape"
? "1.777" ? "1.777"
: "0.666", : cardOrientation ==
"portait"
? "0.666"
: "1",
}} }}
className="card-image" className="card-image"
></CardMedia> ></CardMedia>
@@ -60,7 +60,11 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
playedPercent={ playedPercent={
item.UserData.PlayedPercentage item.UserData.PlayedPercentage
} }
cardOrientation="portait" cardOrientation={
item.PrimaryImageAspectRatio == 1
? "sqaure"
: "portait"
}
></Card> ></Card>
); );
})} })}
+2 -2
View File
@@ -69,7 +69,7 @@ const Home = () => {
event.emit("set-api-accessToken", window.api.basePath); event.emit("set-api-accessToken", window.api.basePath);
return true; return true;
}, },
enabled: !window.api, enabled: false,
}); });
const user = useQuery({ const user = useQuery({
@@ -633,7 +633,7 @@ const Home = () => {
item.UserData item.UserData
.PlayedPercentage .PlayedPercentage
} }
cardOrientation="landscape" cardOrientation="sqaure"
></Card> ></Card>
); );
}, },
+28 -52
View File
@@ -1,7 +1,6 @@
/** @format */ /** @format */
import { useState, useEffect, useMemo } from "react"; import { useState, useEffect, useMemo } from "react";
import { Cookies, useCookies } from "react-cookie";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { useNavigate, useParams, Link } from "react-router-dom"; import { useNavigate, useParams, Link } from "react-router-dom";
import { EventEmitter as event } from "../../eventEmitter.js"; import { EventEmitter as event } from "../../eventEmitter.js";
@@ -30,6 +29,8 @@ import FormControlLabel from "@mui/material/FormControlLabel";
import Checkbox from "@mui/material/Checkbox"; import Checkbox from "@mui/material/Checkbox";
import { AvatarCard, AvatarImage } from "../../components/avatar/avatar.jsx"; 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 { AppBarBackOnly } from "../../components/appBar/backOnly.jsx";
// import { jellyfin } from "../../jellyfin"; // 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 { getBrandingApi } from "@jellyfin/sdk/lib/utils/api/branding-api";
import "./login.module.scss"; import "./login.module.scss";
import { CardsSkeleton } from "../../components/skeleton/cards.jsx";
export const LoginWithImage = () => { export const LoginWithImage = () => {
const { userName, userId } = useParams(); const { userName, userId } = useParams();
@@ -88,7 +90,6 @@ export const LoginWithImage = () => {
saveUser(userName, password.password); saveUser(userName, password.password);
} }
event.emit("set-api-accessToken", window.api.basePath); event.emit("set-api-accessToken", window.api.basePath);
// setAccessToken(user.data.AccessToken)
setLoading(false); setLoading(false);
navigate(`/home`); navigate(`/home`);
}; };
@@ -217,44 +218,28 @@ export const UserLogin = () => {
const handleManualLogin = () => { const handleManualLogin = () => {
navigate("/login/manual"); navigate("/login/manual");
}; };
const getUsers = async () => { const users = useQuery({
queryKey: ["login", "users"],
queryFn: async () => {
const users = await getUserApi(window.api).getPublicUsers(); const users = await getUserApi(window.api).getPublicUsers();
// console.log(users.data); // console.log(users.data);
return users; return users.data;
// return {}; // 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);
});
}
}, []);
return ( return (
<> <>
<AppBarBackOnly /> <AppBarBackOnly />
<Container maxWidth="md" className="centered"> <Container maxWidth="md" className="centered">
<Typography variant="h3" sx={{ marginBottom: "1em" }}> {/* <Typography variant="h3" sx={{ marginBottom: "1em" }}>
Users Users
</Typography> </Typography> */}
<div className="userList"> {users.isLoading ? (
{userList.map((item, index) => { <CardsSkeleton />
) : (
<CardScroller displayCards={5} title="Users">
{users.data.map((item, index) => {
return ( return (
// //
<Link <Link
@@ -263,22 +248,22 @@ export const UserLogin = () => {
className="userCard" className="userCard"
index={index} index={index}
> >
{item.PrimaryImageTag ? ( <Card
<AvatarCard key={index}
userName={item.Name} itemName={item.Name}
userId={item.Id} itemId={item.Id}
userImageAvailable={true} imageTags={
></AvatarCard> !!item.PrimaryImageTag
) : ( }
<AvatarCard // cardType="sqaure"
userName={item.Name} iconType="Person"
userImageAvailable={false} cardOrientation="sqaure"
></AvatarCard> />
)}
</Link> </Link>
); );
})} })}
</div> </CardScroller>
)}
<div className="buttons"> <div className="buttons">
<Button <Button
color="secondary" color="secondary"
@@ -375,15 +360,6 @@ export const UserLoginManual = () => {
setRememberMe(event.target.checked); setRememberMe(event.target.checked);
}; };
const createApi = async () => {
const server = await getServer();
event.emit("create-jellyfin-api", server.Ip);
};
if (!window.api) {
createApi();
}
return ( return (
<> <>
<AppBarBackOnly /> <AppBarBackOnly />
-2
View File
@@ -2,11 +2,9 @@
import { configureStore } from "@reduxjs/toolkit"; import { configureStore } from "@reduxjs/toolkit";
import sideBarReducer from "./utils/slice/sidemenu"; import sideBarReducer from "./utils/slice/sidemenu";
import homePageReducer from "./utils/slice/homePage";
export default configureStore({ export default configureStore({
reducer: { reducer: {
sidebar: sideBarReducer, sidebar: sideBarReducer,
homePage: homePageReducer,
}, },
}); });
-63
View File
@@ -1,63 +0,0 @@
/** @format */
import { createSlice } from "@reduxjs/toolkit";
export const homePageSlice = createSlice({
name: "homePage",
initialState: [
{
type: "libs",
name: "Libraries",
data: [],
// isLoading: libraries.isLoading,
isLoading: false,
},
{
type: "resumeVideo",
name: "Continue Watching",
data: [],
// isLoading: resumeItemsVideo.isLoading,
isLoading: false,
},
{
type: "resumeAudio",
name: "Continue Listnening",
data: [],
// isLoading: resumeItemsAudio.isLoading,
isLoading: false,
},
{
type: "nextup",
name: "Next Up",
data: [],
// isLoading: upNextItems.isLoading,
isLoading: false,
},
],
reducers: {
setData: (state, action) => {
switch (action.payload[0]) {
case "libs":
state[0].data = action.payload[1];
break;
case "resumeVideo":
state[1].data = action.payload[1];
break;
case "resumeAudio":
state[2].data = action.payload[1];
break;
case "nextup":
state[3].data = action.payload[1];
break;
default:
break;
}
},
addLatestMedia: (state, action) => {
state.push(action.payload);
},
},
});
export const { setData, addLatestMedia } = homePageSlice.actions;
export default homePageSlice.reducer;