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
+83 -146

No files matched your search

+22 -8
View File
@@ -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 (
<SnackbarProvider maxSnack={5}>
<ThemeProvider theme={theme}>
+11 -3
View File
@@ -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"
></CardMedia>
@@ -87,7 +92,10 @@ export const Card = ({
aspectRatio:
cardOrientation == "landscape"
? "1.777"
: "0.666",
: cardOrientation ==
"portait"
? "0.666"
: "1",
}}
className="card-image"
></CardMedia>
@@ -60,7 +60,11 @@ export const LatestMediaSection = ({ latestMediaLib }) => {
playedPercent={
item.UserData.PlayedPercentage
}
cardOrientation="portait"
cardOrientation={
item.PrimaryImageAspectRatio == 1
? "sqaure"
: "portait"
}
></Card>
);
})}
+2 -2
View File
@@ -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"
></Card>
);
},
+43 -67
View File
@@ -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 (
<>
<AppBarBackOnly />
<Container maxWidth="md" className="centered">
<Typography variant="h3" sx={{ marginBottom: "1em" }}>
{/* <Typography variant="h3" sx={{ marginBottom: "1em" }}>
Users
</Typography>
<div className="userList">
{userList.map((item, index) => {
return (
//
<Link
to={`/login/withImg/${item.Name}/${item.Id}/`}
key={item.Id}
className="userCard"
index={index}
>
{item.PrimaryImageTag ? (
<AvatarCard
userName={item.Name}
userId={item.Id}
userImageAvailable={true}
></AvatarCard>
) : (
<AvatarCard
userName={item.Name}
userImageAvailable={false}
></AvatarCard>
)}
</Link>
);
})}
</div>
</Typography> */}
{users.isLoading ? (
<CardsSkeleton />
) : (
<CardScroller displayCards={5} title="Users">
{users.data.map((item, index) => {
return (
//
<Link
to={`/login/withImg/${item.Name}/${item.Id}/`}
key={item.Id}
className="userCard"
index={index}
>
<Card
key={index}
itemName={item.Name}
itemId={item.Id}
imageTags={
!!item.PrimaryImageTag
}
// cardType="sqaure"
iconType="Person"
cardOrientation="sqaure"
/>
</Link>
);
})}
</CardScroller>
)}
<div className="buttons">
<Button
color="secondary"
@@ -375,15 +360,6 @@ export const UserLoginManual = () => {
setRememberMe(event.target.checked);
};
const createApi = async () => {
const server = await getServer();
event.emit("create-jellyfin-api", server.Ip);
};
if (!window.api) {
createApi();
}
return (
<>
<AppBarBackOnly />
-2
View File
@@ -2,11 +2,9 @@
import { configureStore } from "@reduxjs/toolkit";
import sideBarReducer from "./utils/slice/sidemenu";
import homePageReducer from "./utils/slice/homePage";
export default configureStore({
reducer: {
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;