Skip to content

Commit

Permalink
Fix page reload breaking stuff and add few other things
Browse files Browse the repository at this point in the history
  • Loading branch information
prayag17 committed Feb 24, 2023
1 parent 899fcb0 commit 93b79c5
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 44 deletions.
3 changes: 2 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function App() {
const navigate = useNavigate();

const [serverReachable, setServerReachable] = useState(true);
const [checkingServer, setChecking] = useState(true);
const [checkingServer, setChecking] = useState(false);

const serverAvailable = async () => {
const server = await getServer();
Expand Down Expand Up @@ -154,6 +154,7 @@ function App() {
};

const pingServer = () => {
setChecking(true);
let data;
fetch(`${window.api.basePath}/System/Ping`, {
body: JSON.stringify(data),
Expand Down
2 changes: 1 addition & 1 deletion src/components/avatar/avatar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import "./avatar.module.scss";

export const AvatarCard = ({ userName, userId, userImageAvailable }) => {
return (
<ButtonBase className="card square">
<ButtonBase className="card square" sx={{ borderRadius: "10px" }}>
<div className="card-image-container">
{userImageAvailable ? (
<div
Expand Down
2 changes: 2 additions & 0 deletions src/components/avatar/avatar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
flex-direction: column;
gap: 0.5em;
margin-bottom: 0.5em;
overflow: hidden;
.card-image {
position: absolute;
inset: 0;
&-container {
font-size: 5em;
z-index: 0;
}
&-icon {
font-size: 1.5em !important;
Expand Down
114 changes: 77 additions & 37 deletions src/routes/home/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import { useState, useEffect } from "react";

import { EventEmitter as event } from "../../eventEmitter";
import { getServer } from "../../utils/store/servers";
import { getUser } from "../../utils/store/user";

import { theme } from "../../theme";
import "./home.module.scss";

Expand All @@ -22,6 +26,7 @@ import Divider from "@mui/material/Divider";
import Paper from "@mui/material/Paper";
import Typography from "@mui/material/Typography";
import useScrollTrigger from "@mui/material/useScrollTrigger";
import Tooltip from "@mui/material/Tooltip";

import Carousel from "react-material-ui-carousel";

Expand Down Expand Up @@ -135,18 +140,48 @@ export const Home = () => {
return userviews;
};

const authUser = async () => {
const server = await getServer();
const user = await getUser();
event.emit("create-jellyfin-api", server.Ip);
const auth = await api.authenticateUserByName(
user.Name,
user.Password,
);
sessionStorage.setItem("accessToken", auth.data.AccessToken);
event.emit("set-api-accessToken", window.api.basePath);
};

useEffect(() => {
currentUser().then((usr) => {
setUser(usr.data);
userLibs().then((libs) => {
setUserLibraries(libs.data.Items);
setSkeletonStateSideMenu(true);
// TODO Implement a better way to check and create api object when page reloaded. Hint: Maybe use session api or something (*route - home*)
if (!window.api) {
authUser().then(() => {
currentUser().then((usr) => {
setUser(usr.data);
userLibs().then((libs) => {
setUserLibraries(libs.data.Items);
setSkeletonStateSideMenu(true);
});
getLatestMedia(usr.data).then((media) => {
console.log("Using this");
setLatestMedia(media.data);
setSkeletonStateCarousel(true);
});
});
});
getLatestMedia(usr.data).then((media) => {
setLatestMedia(media.data);
setSkeletonStateCarousel(true);
} else {
currentUser().then((usr) => {
setUser(usr.data);
userLibs().then((libs) => {
setUserLibraries(libs.data.Items);
setSkeletonStateSideMenu(true);
});
getLatestMedia(usr.data).then((media) => {
setLatestMedia(media.data);
setSkeletonStateCarousel(true);
});
});
});
}
}, []);

return (
Expand Down Expand Up @@ -191,7 +226,7 @@ export const Home = () => {
>
<DrawerHeader
className="Mui-DrawerHeader"
sx={{ position: "relative", height: "20vh" }}
sx={{ position: "relative" }}
>
{/* <div>
<Avatar src={""}/>
Expand All @@ -216,39 +251,44 @@ export const Home = () => {
<List sx={{ border: "none" }}>
{userLibraries.map((library, index) => {
return (
<ListItem
disablePadding
<Tooltip
title={library.Name}
placement="right"
arrow
followCursor
key={index}
>
<ListItemButton
sx={{
minHeight: 48,
justifyContent:
drawerState
? "initial"
: "center",
px: 2.5,
}}
>
<ListItemIcon
<ListItem disablePadding>
<ListItemButton
sx={{
minWidth: 0,
mr: drawerState
? 3
: "auto",
minHeight: 48,
justifyContent:
"center",
drawerState
? "initial"
: "center",
px: 2.5,
}}
>
{
MediaCollectionTypeIconCollection[
library
.CollectionType
]
}
</ListItemIcon>
</ListItemButton>
</ListItem>
<ListItemIcon
sx={{
minWidth: 0,
mr: drawerState
? 3
: "auto",
justifyContent:
"center",
}}
>
{
MediaCollectionTypeIconCollection[
library
.CollectionType
]
}
</ListItemIcon>
</ListItemButton>
</ListItem>
</Tooltip>
);
})}
</List>
Expand Down
2 changes: 2 additions & 0 deletions src/routes/login/login.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
width: min(60vw, 45em);
}
&Card {
border-radius: $border-radius-default;
display: flex;
flex-flow: column;
flex: 1 1 0px;
overflow: hidden;
}
&Icon {
font-size: 5em;
Expand Down
25 changes: 21 additions & 4 deletions src/routes/login/root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Cookies, useCookies } from "react-cookie";
import { useNavigate, useParams, Link } from "react-router-dom";
import { EventEmitter as event } from "../../eventEmitter.js";

import { getServer } from "../../utils/store/servers.js";
import { saveUser } from "../../utils/store/user.js";

// import Icon from "mdi-material-ui";
Expand Down Expand Up @@ -220,11 +221,27 @@ export const UserLogin = () => {
return users;
// return {};
};

const createApi = async () => {
const server = await getServer();
event.emit("create-jellyfin-api", server.Ip);
};

useMemo(() => {
getUsers().then((users) => {
setUsers(users.data);
console.log(userList);
});
// 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 (
Expand Down
2 changes: 1 addition & 1 deletion src/utils/store/servers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const setServer = (data) => {

/**
* Get Server list
* @returns {object}
* @returns {object} server
*/
const getServer = async () => {
let server = await servers.get("server");
Expand Down

0 comments on commit 93b79c5

Please sign in to comment.