Move to Tauri and rust

This commit is contained in:
Prayag Prajapati committed 2023-01-19 22:10:04 +05:30
1 parent 7a50c0f167
commit 8d3c30f4d0
77 files changed
+7861 -975

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
/** @format */
.hero-carousel {
position: relative;
overflow: hidden;
isolation: isolate;
&-slide {
position: relative;
height: 70vh;
border-radius: 10px !important;
overflow: hidden;
margin: 0 auto;
}
&-background {
&-container {
position: absolute;
z-index: 0;
top: 0;
left: 0;
right: 0;
bottom: 0;
mask-image: linear-gradient(
to right,
transparent 20%,
black 50%
);
-webkit-mask-image: linear-gradient(
to right,
transparent 20%,
rgb(0 0 0 / 0.5) 50%,
black 90%
);
}
&-image {
position: absolute;
background-size: cover;
z-index: 0;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
&-icon {
position: absolute;
font-size: 10em !important;
left: 70%;
top: 50%;
transform: translate(-50%, -50%);
color: $clr-accent-default;
&-container {
position: absolute;
background: $clr-accent-dark;
z-index: 0;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
}
}
&-text {
display: -webkit-box;
overflow: hidden;
-webkit-line-clamp: 2;
}
&-detail {
position: relative;
z-index: 0;
display: flex;
height: 70vh;
width: 70%;
padding: 0 2em 2em 2em;
flex-direction: column;
justify-content: center;
align-items: flex-start;
}
&-indicator {
width: 100%;
height: 5px;
border-radius: 0;
}
}
.home-section {
&-heading {
display: flex;
align-items: center;
justify-content: flex-start;
gap: 0.35em;
position: relative;
margin-bottom: 0.25em !important;
&-decoration {
width: 0.75em;
height: 3px;
background: white;
}
}
}
+526
View File
@@ -0,0 +1,526 @@
/** @format */
import { useState, useEffect } from "react";
import { Cookies } from "react-cookie";
import { theme } from "../../theme";
import "./home.module.scss";
import { styled } from "@mui/material/styles";
import Box from "@mui/material/Box";
import Skeleton from "@mui/material/Skeleton";
import Button from "@mui/material/Button";
import MuiAppBar from "@mui/material/AppBar";
import MuiDrawer from "@mui/material/Drawer";
import List from "@mui/material/List";
import ListItem from "@mui/material/ListItem";
import ListItemText from "@mui/material/ListItemText";
import ListItemIcon from "@mui/material/ListItemIcon";
import ListItemButton from "@mui/material/ListItemButton";
import IconButton from "@mui/material/IconButton";
import Toolbar from "@mui/material/Toolbar";
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 Carousel from "react-material-ui-carousel";
// Custom Components
import { CardLandscape, CardPotrait } from "../../components/card/card";
import { CardScroller } from "../../components/cardScroller/cardScroller";
// Icons
import {
MediaCollectionTypeIconCollection,
MediaTypeIconCollection,
} from "../../components/utils/iconsCollection.jsx";
import MenuIcon from "mdi-material-ui/Menu";
import Close from "mdi-material-ui/Close";
import { getLibraryApi } from "@jellyfin/sdk/lib/utils/api/library-api";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import { getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api/user-library-api";
const drawerWidth = 320;
const openedMixin = (theme) => ({
width: drawerWidth,
transition: theme.transitions.create("width", {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
overflowX: "hidden",
});
const closedMixin = (theme) => ({
transition: theme.transitions.create("width", {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
overflowX: "hidden",
width: `calc(${theme.spacing(7)} + 1px)`,
[theme.breakpoints.up("sm")]: {
width: `calc(${theme.spacing(8)} + 1px)`,
},
});
const DrawerHeader = styled("div")(({ theme }) => ({
display: "flex",
alignItems: "center",
justifyContent: "flex-end",
padding: theme.spacing(0, 1),
// necessary for content to be below app bar
...theme.mixins.toolbar,
}));
const Drawer = styled(MuiDrawer, {
shouldForwardProp: (prop) => prop !== "open",
})(({ theme, open }) => ({
width: drawerWidth,
flexShrink: 0,
whiteSpace: "nowrap",
boxSizing: "border-box",
backgroundColor: theme.palette.primary.background.dark,
...(open && {
...openedMixin(theme),
"& .MuiDrawer-paper": openedMixin(theme),
}),
...(!open && {
...closedMixin(theme),
"& .MuiDrawer-paper": closedMixin(theme),
}),
}));
const AppBar = styled(MuiAppBar, {
shouldForwardProp: (prop) => prop !== "open",
})(({ theme, open }) => ({
zIndex: theme.zIndex.drawer + 1,
transition: theme.transitions.create(["width", "margin"], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
backgroundColor: "transparent",
backgroundImage: "none",
...(open && {
marginLeft: drawerWidth,
width: `calc(100% - ${drawerWidth}px)`,
transition: theme.transitions.create(["width", "margin"], {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.enteringScreen,
}),
}),
}));
export const Home = () => {
const [skeletonStateSideMenu, setSkeletonStateSideMenu] = useState(false);
const [skeletonStateCarousel, setSkeletonStateCarousel] = useState(false);
const [userLibraries, setUserLibraries] = useState([]);
const [latestMovies, setLatestMovies] = useState([]);
const [user, setUser] = useState({
Name: "",
});
const [latestMedia, setLatestMedia] = useState([]);
const [drawerState, setDrawerState] = useState(false);
const cookies = new Cookies();
const scrollTrigger = useScrollTrigger({ threshold: 5 });
const handleDrawerOpen = () => {
setDrawerState(true);
};
const handleDrawerClose = () => {
setDrawerState(false);
};
const handleLogout = async () => {
await window.api.logout();
console.log("logged out user");
};
const currentUser = async () => {
const user = await getUserApi(window.api).getCurrentUser();
return user;
};
const userLibs = async (user) => {
const userLibs = await getLibraryApi(window.api).getMediaFolders();
return userLibs;
};
const getLatestMedia = async (user) => {
const media = await getUserLibraryApi(window.api).getLatestMedia({
userId: user.Id,
fields: "Overview",
enableUserData: true,
});
return media;
};
const getLatestMovies = async (user) => {
const media = await getUserLibraryApi(window.api).getLatestMedia({
userId: user.Id,
fields: ["PrimaryImageAspectRatio", "Overview"],
enableUserData: true,
includeItemTypes: ["Movie"],
});
return media;
};
useEffect(() => {
currentUser().then((usr) => {
setUser(usr.data);
userLibs(usr.data).then((libs) => {
setUserLibraries(libs.data.Items);
setSkeletonStateSideMenu(true);
// console.log(userLibraries);
});
getLatestMedia(usr.data).then((media) => {
setLatestMedia(media.data);
setSkeletonStateCarousel(true);
});
getLatestMovies(usr.data).then((media) => {
setLatestMovies(media.data);
});
});
for (let lib of latestMovies) {
console.log(lib);
}
}, []);
return (
<>
<Box
sx={{
display: "flex",
}}
>
<AppBar
position="fixed"
open={drawerState}
color="primary"
elevation={0}
>
<Toolbar>
<IconButton
color="inherit"
aria-label="open drawer"
onClick={handleDrawerOpen}
edge="start"
sx={{
marginRight: 5,
...(drawerState && { display: "none" }),
}}
>
<MenuIcon />
</IconButton>
</Toolbar>
</AppBar>
<Drawer
variant="permanent"
open={drawerState}
PaperProps={{
sx: {
backgroundColor: "inherit",
border: "none",
},
}}
>
<DrawerHeader
className="Mui-DrawerHeader"
sx={{ position: "relative", height: "20vh" }}
>
{/* <div>
<Avatar src={""}/>
<Typography variant="h3">
{user["Name"]}
</Typography>
</div> */}
<IconButton
onClick={handleDrawerClose}
sx={{
position: "absolute",
top: "10%",
right: "5%",
opacity: drawerState ? 1 : 0,
}}
>
<Close />
</IconButton>
</DrawerHeader>
<Divider />
{skeletonStateSideMenu ? (
<List sx={{ border: "none" }}>
{userLibraries.map((library, index) => {
return (
<ListItem
disablePadding
key={index}
>
<ListItemButton
sx={{
minHeight: 48,
justifyContent:
drawerState
? "initial"
: "center",
px: 2.5,
}}
>
<ListItemIcon
sx={{
minWidth: 0,
mr: drawerState
? 3
: "auto",
justifyContent:
"center",
}}
>
{
MediaCollectionTypeIconCollection[
library
.CollectionType
]
}
</ListItemIcon>
<ListItemText
primary={
library.Name
}
sx={{
opacity: drawerState
? 1
: 0,
}}
/>
</ListItemButton>
</ListItem>
);
})}
</List>
) : (
<>
<Skeleton
height={50}
variant="rectangular"
animation="wave"
></Skeleton>
<br />
<Skeleton
height={50}
variant="rectangular"
animation="wave"
></Skeleton>
<br />
<Skeleton
height={50}
variant="rectangular"
animation="wave"
></Skeleton>
</>
)}
</Drawer>
{/* <h1>Hey {userId} this is WIP Home</h1> */}
<Box
component="main"
className="scrollY"
sx={{ flexGrow: 1, p: 3 }}
>
<DrawerHeader />
<Carousel
className="hero-carousel"
autoPlay={true}
animation="fade"
height="70vh"
IndicatorIcon={
<div className="hero-carousel-indicator"></div>
}
activeIndicatorIconButtonProps={{
style: {
background: "rgb(255 255 255)",
},
}}
indicatorIconButtonProps={{
style: {
background: "rgb(255 255 255 / 0.3)",
borderRadius: "2px",
width: "100%",
flexShrink: "1",
},
}}
indicatorContainerProps={{
style: {
display: "flex",
gap: "1em",
},
}}
sx={{
marginBottom: "1.5em",
}}
interval={10000}
>
{skeletonStateCarousel ? (
latestMedia.map((item, index) => {
// console.log(item);
return (
<Paper
className="hero-carousel-slide"
sx={{
background:
theme.palette
.primary
.background
.dark,
}}
key={index}
>
<div className="hero-carousel-background-container">
{item.ImageBlurHashes
.Backdrop ? (
<div
className="hero-carousel-background-image"
style={{
backgroundImage: `url(${
window
.api
.basePath +
"/Items/" +
item.Id +
"/Images/Backdrop"
})`,
}}
></div>
) : (
<div className="hero-carousel-background-image empty"></div>
)}
<div className="hero-carousel-background-icon-container">
{
MediaTypeIconCollection[
item
.MediaType
]
}
</div>
</div>
<Box className="hero-carousel-detail">
<Typography
variant="h3"
className="hero-carousel-text"
>
{item.Name}
</Typography>
<Typography
variant="subtitle1"
className="hero-carousel-text"
>
{item.Overview}
</Typography>
</Box>
</Paper>
);
})
) : (
<Paper
className="hero-carousel-slide"
sx={{
background:
theme.palette.primary
.background.dark,
}}
>
<div className="hero-carousel-background">
<Skeleton
variant="rectangular"
height="100%"
animation="wave"
></Skeleton>
</div>
<Box className="hero-carousel-detail">
<Typography
variant="h3"
className="hero-carousel-text"
>
<Skeleton
variant="text"
sx={{ fontSize: "5rem" }}
width={300}
animation="wave"
></Skeleton>
</Typography>
<Typography
variant="p"
className="hero-carousel-text"
>
<Skeleton
variant="text"
sx={{ fontSize: "3rem" }}
width={400}
animation="wave"
></Skeleton>
</Typography>
</Box>
</Paper>
)}
</Carousel>
<Box className="home-section">
<Typography
variant="h4"
color="textPrimary"
className="home-section-heading"
>
<div className="home-section-heading-decoration"></div>{" "}
Libraries
</Typography>
<CardScroller displayCards={4}>
{userLibraries.map((library, index) => {
return (
<CardLandscape
key={index}
itemName={library.Name}
itemId={library.Id}
imageTags={library.imageTags}
iconType={
library.CollectionType
}
></CardLandscape>
);
})}
</CardScroller>
</Box>
<Box className="home-section">
<Typography
variant="h4"
color="textPrimary"
className="home-section-heading"
>
<div className="home-section-heading-decoration"></div>{" "}
Latest Movies
</Typography>
<CardScroller displayCards={7}>
{latestMovies.map((movie, index) => {
return (
<CardPotrait
key={index}
itemName={movie.Name}
itemId={movie.Id}
imageTags={movie.imageTags}
iconType={movie.MediaType}
></CardPotrait>
);
})}
</CardScroller>
</Box>
<Button variant="contained" onClick={handleLogout}>
Logout
</Button>
</Box>
</Box>
</>
);
};
+30
View File
@@ -0,0 +1,30 @@
/** @format */
.user {
&List {
display: flex;
gap: 1em;
width: min(60vw, 45em);
}
&Card {
display: flex;
flex-flow: column;
flex: 1 1 0px;
}
&Icon {
font-size: 5em;
display: flex;
justify-content: center;
align-items: center;
background: $clr-accent-dark;
}
}
.buttons {
display: flex;
gap: 1em;
width: 100%;
.userEventButton {
flex: 1 1 0 !important;
}
}
+390
View File
@@ -0,0 +1,390 @@
/** @format */
import { useState, useEffect } from "react";
import { Cookies, useCookies } from "react-cookie";
import { useNavigate, useParams, Link } from "react-router-dom";
import { EventEmitter as event } from "../../eventEmitter.js";
import { motion } from "framer-motion";
// import Icon from "mdi-material-ui";
import EyeOffOutline from "mdi-material-ui/EyeOffOutline";
import EyeOutline from "mdi-material-ui/EyeOutline";
import ChevronRight from "mdi-material-ui/ChevronRight";
import Container from "@mui/material/Container";
import Grid from "@mui/material/Grid";
import Typography from "@mui/material/Typography";
import OutlinedInput from "@mui/material/OutlinedInput";
import FormControl from "@mui/material/FormControl";
import InputAdornment from "@mui/material/InputAdornment";
import InputLabel from "@mui/material/InputLabel";
import IconButton from "@mui/material/IconButton";
import Avatar from "@mui/material/Avatar";
import LoadingButton from "@mui/lab/LoadingButton";
import Button from "@mui/material/Button";
import { useSnackbar } from "notistack";
import { AvatarCard, AvatarImage } from "../../components/avatar/avatar.jsx";
import { AppBarBackOnly } from "../../components/appBar/backOnly.jsx";
// import { jellyfin } from "../../jellyfin";
// import getSystemApi from "@jellyfin/sdk";
import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api";
import "./login.module.scss";
export const LoginWithImage = () => {
const { userName, userId } = useParams();
const [password, setPassword] = useState({
showpass: false,
});
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();
const handlePassword = (prop) => (event) => {
setPassword({
...password,
[prop]: event.target.value,
});
};
const handleShowPassword = () => {
setPassword({
...password,
showpass: !password.showpass,
});
};
const authUser = async () => {
try {
const auth = await api.authenticateUserByName(
userName,
password.password,
);
return auth;
} catch (error) {
enqueueSnackbar("Incorrect Password!", { variant: "error" });
setLoading(false);
console.error(error);
}
};
const handleLogin = async () => {
setLoading(true);
const user = await authUser();
sessionStorage.setItem("accessToken", user.data.AccessToken);
event.emit("set-api-accessToken", window.api.basePath);
// setAccessToken(user.data.AccessToken)
setLoading(false);
navigate(`/home`);
};
return (
<>
<AppBarBackOnly />
<Container maxWidth="xs" className="centered">
<Grid
container
direction="column"
justifyContent="center"
alignItems="center"
spacing={2}
>
<Grid item marginBottom={2}>
<Typography
textAlign="center"
variant="h3"
color="textPrimary"
>
Login
<br />
</Typography>
</Grid>
<Grid item>
<AvatarImage userId={userId} />
<Typography
color="textPrimary"
textAlign="center"
variant="h4"
>
{userName}
</Typography>
</Grid>
<Grid item minWidth="100%">
<br />
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="user-password">
Password:
</InputLabel>
<OutlinedInput
id="user-password"
type={
password.showpass
? "text"
: "password"
}
variant="outlined"
onChange={handlePassword("password")}
label="Password:"
endAdornment={
<InputAdornment position="end">
<IconButton
onClick={
handleShowPassword
}
aria-label="toggle password visibility"
>
{password.showpass ? (
<EyeOffOutline />
) : (
<EyeOutline />
)}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
</Grid>
<Grid item minWidth="100%">
<LoadingButton
variant="contained"
endIcon={<ChevronRight />}
onClick={handleLogin}
loading={loading}
loadingPosition="end"
size="large"
fullWidth
>
Login
</LoadingButton>
</Grid>
</Grid>
</Container>
</>
);
};
export const UserLogin = () => {
const [userList, setUsers] = useState([]);
const navigate = useNavigate();
const cookies = new Cookies();
const currentServer = cookies.get("currentServer");
const serverList = cookies.get("servers");
const handleChangeServer = () => {
navigate("/servers/list");
};
const handleManualLogin = () => {
navigate("/login/manual");
};
const getUsers = async () => {
const users = await getUserApi(window.api).getPublicUsers();
// console.log(users.data);
return users;
// return {};
};
useEffect(() => {
getUsers().then((users) => {
setUsers(users.data);
});
});
return (
<>
<AppBarBackOnly />
<Container maxWidth="md" className="centered">
<h1 color="white">WIP-user login</h1>
<div className="userList">
{userList.map((item, index) => {
return (
//
<Link
to={`/login/withImg/${item.Name}/${item.Id}/`}
key={item.Id}
className="userCard"
index={index}
>
{item.ImageTags == undefined ? (
<AvatarCard
userName={item.Name}
userId={item.Id}
userImageAvailable={false}
></AvatarCard>
) : (
<AvatarCard
userName={item.Name}
userImageAvailable={true}
></AvatarCard>
)}
</Link>
);
})}
</div>
<div className="buttons">
<Button
color="secondary"
variant="contained"
className="userEventButton"
onClick={handleChangeServer}
>
Change Server
</Button>
<Button
variant="contained"
className="userEventButton"
onClick={handleManualLogin}
>
Manual Login
</Button>
</div>
</Container>
</>
);
};
export const UserLoginManual = () => {
const [loading, setLoading] = useState(false);
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();
const [password, setPassword] = useState({
showpass: false,
});
const [userName, setUserName] = useState("");
const handleUsername = (event) => {
setUserName(event.target.value);
};
const handlePassword = (prop) => (event) => {
setPassword({
...password,
[prop]: event.target.value,
});
};
const handleShowPassword = () => {
setPassword({
...password,
showpass: !password.showpass,
});
};
const authUser = async () => {
try {
const auth = await api.authenticateUserByName(
userName,
password.password,
);
return auth;
} catch (error) {
enqueueSnackbar("Incorrect Username or Password!", {
variant: "error",
});
setLoading(false);
console.error(error);
}
};
const handleLogin = async () => {
setLoading(true);
const user = await authUser();
sessionStorage.setItem("accessToken", user.data.AccessToken);
event.emit("set-api-accessToken", window.api.basePath);
// setAccessToken(user.data.AccessToken)
setLoading(false);
navigate(`/home`);
};
return (
<>
<AppBarBackOnly />
<Container maxWidth="xs" className="centered">
<Grid
container
spacing={2}
direction="column"
justifyContent="center"
alignItems="center"
>
<Grid item xl={5} md={6} sx={{ marginBottom: "1em" }}>
<Typography variant="h3" color="textPrimary">
Login
</Typography>
</Grid>
<Grid sx={{ width: "100%" }} item xl={5} md={6}>
<FormControl
sx={{ width: "100%" }}
variant="outlined"
>
<InputLabel htmlFor="user-name">
Username:
</InputLabel>
<OutlinedInput
fullWidth
id="user-name"
type="text"
variant="outlined"
label="Username:"
onChange={handleUsername}
/>
</FormControl>
</Grid>
<Grid sx={{ width: "100%" }} item xl={5} md={6}>
<FormControl
sx={{ width: "100%" }}
variant="outlined"
>
<InputLabel htmlFor="user-password">
Password:
</InputLabel>
<OutlinedInput
fullWidth
id="user-password"
type={
password.showpass
? "text"
: "password"
}
variant="outlined"
onChange={handlePassword("password")}
label="Password:"
endAdornment={
<InputAdornment position="end">
<IconButton
onClick={
handleShowPassword
}
aria-label="toggle password visibility"
>
{password.showpass ? (
<EyeOffOutline />
) : (
<EyeOutline />
)}
</IconButton>
</InputAdornment>
}
/>
</FormControl>
</Grid>
<Grid item xl={5} md={6} sx={{ width: "100%" }}>
<LoadingButton
variant="contained"
endIcon={<ChevronRight />}
onClick={handleLogin}
loading={loading}
loadingPosition="end"
size="large"
sx={{ width: "100%" }}
>
Login
</LoadingButton>
</Grid>
</Grid>
</Container>
</>
);
};
+238
View File
@@ -0,0 +1,238 @@
/** @format */
import { useState, useEffect } from "react";
import { Cookies, useCookies } from "react-cookie";
import { Navigate } from "react-router-dom";
import { v4 as uuidv4 } from "uuid";
import { EventEmitter as event } from "../../../eventEmitter.js";
import { getSystemApi } from "@jellyfin/sdk/lib/utils/api/system-api";
// MUI
import TextField from "@mui/material/TextField";
import Typography from "@mui/material/Typography";
import Grid from "@mui/material/Grid";
import ListItem from "@mui/material/ListItem";
import ListItemText from "@mui/material/ListItemText";
import Button from "@mui/material/Button";
import LinearProgress from "@mui/material/LinearProgress";
import Container from "@mui/material/Container";
import { useSnackbar } from "notistack";
// Svgs
import { ReactComponent as JellyplayerLogo } from "../../../assets/logo.svg";
// SCSS
import "./server.module.scss";
export const ServerList = () => {
const [renderServerList, setRenderServerList] = useState(false);
const [serverListRender, setServerListRender] = useState([]);
const cookies = new Cookies();
const currentServer = cookies.get("currentServer");
const serverList = cookies.get("servers");
let currentServerIp = "";
serverList.map((item, index) => {
currentServerIp = item[currentServer];
// console.log(item);
});
const createServerListRender = async () => {
let serverListKeys = [];
serverList.map((item, index) => {
serverListKeys.push(Object.keys(item));
// for (let item in servers) {
// if (item != "currentServer") {
// setServerList([...serverList, JSON.parse(servers[item])]);
// serverList.push(JSON.parse(servers[item]));
// }
// }
});
return serverListKeys;
// console.log(serverListRender);
// localStorage.setItem("servers", serverList);
};
const ServerList = (props) => {
const startRender = props.startRender;
if (startRender) {
return serverList.map((item, index) => {
let serverIndex = serverListRender[index];
let itm = item[serverIndex];
console.log(itm.serverAddress);
console.log("serverIndex : ", serverIndex);
return (
<div
key={index}
className="server"
style={{ color: "white" }}
>
{/* <Typography></Typography> */}
hello {itm.serverAddress} This is WIP
</div>
);
});
} else if (!startRender) {
return <h1>Hfjsi</h1>;
}
};
// const serverList = createServerList();
useEffect(() => {
createServerListRender().then((serverListKeys) => {
console.log("ServerListKeys : ", serverListKeys);
setServerListRender(serverListKeys);
setRenderServerList(true);
});
// console.log(serverList);
}, []);
return (
<>
<Container maxWidth="md" className="centered">
<Typography color="textPrimary" variant="h3">
Select Server:
</Typography>
<div className="serverList">
<ServerList
startRender={renderServerList}
></ServerList>
{/*
{serverList.map((item, index) => {
// let serverIndex = serverListRender[index];
// let itm = item[serverIndex];
// console.log(itm.serverAddress);
// console.log("serverIndex : ", serverIndex);
return (
// <></>
<div key={index} className="server">
hello{" "}
{
item[serverListRender[index]]
.serverAddress
}{" "}
</div>
);
})} */}
</div>
</Container>
</>
);
};
export const ServerSetup = (props) => {
const [serverIp, setServerIp] = useState("");
const [checkingServer, setServerCheckState] = useState(false);
const [isJfServer, setIsJfServerState] = useState(false);
const { enqueueSnackbar } = useSnackbar();
const [serverlistCookies, setServerList] = useCookies(["servers"]);
const [currentServer, setCurrentServer] = useCookies(["currentServer"]);
const cookies = new Cookies();
const addServer = async () => {
event.emit("create-jellyfin-api", serverIp);
let sysInfo = await getSystemApi(window.api).getPublicSystemInfo();
sysInfo = sysInfo.data;
let initServerList = cookies.get("servers");
if (initServerList == null) {
initServerList = [];
} else {
initServerList = JSON.parse(initServerList);
}
let serverConf = {
serverName: sysInfo.ServerName,
id: sysInfo.Id,
jellyfinVersion: sysInfo.Version,
serverAddress: serverIp,
};
let jfId = sysInfo.Id;
let server = {};
server[sysInfo.Id] = serverConf;
server = JSON.stringify([...initServerList, server]);
setServerList("servers", server, { path: "/" });
setCurrentServer("currentServer", sysInfo.Id, { path: "/" });
setIsJfServerState(true);
};
const handleAddServer = () => {
let data;
setServerCheckState(true);
fetch(`${serverIp}/System/Ping`, {
body: JSON.stringify(data),
})
.then((res) => res.json())
.then((data) => {
if (data == "Jellyfin Server") {
console.log(true);
setServerCheckState(false);
addServer();
return true;
} else {
setServerCheckState(false);
enqueueSnackbar(
"The server address does not seem be a jellyfin server",
{ variant: "error" },
);
return false;
}
})
.catch((error) => {
setServerCheckState(false);
enqueueSnackbar(
"Unable to verify whether the give address is a valid Jellyfin server",
{ variant: "error" },
);
console.error(error);
});
};
return (
<>
{checkingServer && <LinearProgress />}
{isJfServer && <Navigate to="/login" />}
<Container
maxWidth="md"
className={
checkingServer
? "centered serverContainer loading"
: "centered serverContainer"
}
>
<Grid
container
spacing={2}
direction="column"
justifyContent="center"
alignItems="center"
>
<Grid item xl={5} md={6} sx={{ marginBottom: "1em" }}>
<JellyplayerLogo className="logo" />
</Grid>
<Grid item xl={5} md={6} sx={{ width: "100%" }}>
<TextField
className="textbox"
label="Server Address:"
variant="outlined"
// inputRef={serverIp}
onChange={(event) => {
setServerIp(event.target.value);
}}
helperText="Add your server adddress with https:// or http://"
></TextField>
</Grid>
<Grid item xl={5} md={6} sx={{ width: "100%" }}>
<Button
variant="contained"
sx={{ width: "100%" }}
size="large"
onClick={handleAddServer}
>
Add Server
</Button>
</Grid>
</Grid>
</Container>
</>
);
};
@@ -0,0 +1,22 @@
/** @format */
.logo {
width: min(60vw, 45em);
height: auto;
margin-bottom: 2em;
}
.serverContainer {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 1.5em;
.textbox,
.button {
width: 100% !important;
}
.button {
padding: 1em;
border-radius: 100px;
}
}