diff --git a/src/components/appBar/appBar.jsx b/src/components/appBar/appBar.jsx index 42a37eb..4a5454c 100644 --- a/src/components/appBar/appBar.jsx +++ b/src/components/appBar/appBar.jsx @@ -1,18 +1,20 @@ /** @format */ +import { useEffect } from "react"; import MuiAppBar from "@mui/material/AppBar"; import TextField from "@mui/material/TextField"; import IconButton from "@mui/material/IconButton"; -import InputAdornment from "@mui/material/InputAdornment"; import Toolbar from "@mui/material/Toolbar"; import Avatar from "@mui/material/Avatar"; import Box from "@mui/material/Box"; +import Typography from "@mui/material/Typography"; import { MdiMagnify } from "../icons/mdiMagnify"; import { theme } from "../../theme"; -import { useSelector } from "react-redux"; -import { useLocation } from "react-router-dom"; +import { useDispatch, useSelector } from "react-redux"; +import { useLocation, useNavigate } from "react-router-dom"; +import { removePage } from "../../utils/slice/appBar"; import { getUserApi } from "@jellyfin/sdk/lib/utils/api/user-api"; import { useQueryClient, useQuery } from "@tanstack/react-query"; @@ -20,13 +22,17 @@ import { useQueryClient, useQuery } from "@tanstack/react-query"; import "./appBar.module.scss"; import { MdiAccount } from "../icons/mdiAccount"; import { MdiHeartOutline } from "../icons/mdiHeartOutline"; +import { MdiArrowLeft } from "../icons/mdiArrowLeft"; export const AppBar = () => { + const dispatch = useDispatch(); + const navigate = useNavigate(); + const visible = useSelector((state) => state.appBar.visible); + const page = useSelector((state) => state.appBar.page); const backdropVisible = useSelector((state) => state.appBar.backdrop); const location = useLocation(); - console.log(location); const user = useQuery({ queryKey: ["appBar", "user"], @@ -36,6 +42,12 @@ export const AppBar = () => { }, }); + useEffect(() => { + if (location.pathname == "/home") { + dispatch(removePage()); + } + }); + return ( visible && ( { elevation={backdropVisible ? 6 : 0} > - + + {page != undefined && ( + <> + navigate(-1)} + > + + + + {page} + + + )} + { return ( - + {}} + > { }) )} - - {libraries.isLoading ? ( - - ) : ( - libraries.status == "success" && - libraries.data.Items.map((item, index) => { - return ( - - ); - }) - )} - + {libraries.isLoading ? ( + + ) : ( + + {libraries.status == "success" && + libraries.data.Items.map( + (item, index) => { + return ( + { + navigate( + `/library/${item.Id}`, + ); + }} + > + ); + }, + )} + + )} {upNextItems.isLoading ? ( ) : upNextItems.isSuccess && diff --git a/src/routes/library/root.jsx b/src/routes/library/root.jsx index 54fc733..1391e01 100644 --- a/src/routes/library/root.jsx +++ b/src/routes/library/root.jsx @@ -1,7 +1,12 @@ /** @format */ import { useState, useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; -import { showAppBar, setBackdrop } from "../../utils/slice/appBar"; +import { + showAppBar, + setBackdrop, + setPage, + removePage, +} from "../../utils/slice/appBar"; import { useParams } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; @@ -48,8 +53,27 @@ const LibraryView = () => { return result.data; }; + const fetchLib = async (libraryId) => { + const result = await getItemsApi(window.api).getItems({ + userId: user.data.Id, + ids: [libraryId], + }); + return result.data; + }; + + const currentLib = useQuery({ + queryKey: ["libraryView", "currentLib", id], + queryFn: () => fetchLib(id), + enabled: !!user.data, + }); + + if (currentLib.isSuccess) { + // console.log(currentLib.data.) + dispatch(setPage(currentLib.data.Items[0].Name)); + } + const items = useQuery({ - queryKey: ["libraryView", id], + queryKey: ["libraryView", "currentLibItems", id], queryFn: () => fetchLibItems(id), enabled: !!user.data, }); @@ -58,6 +82,10 @@ const LibraryView = () => { dispatch(setBackdrop(trigger)); }, [trigger]); + if (currentLib.isLoading || items.isLoading) { + return

Loading...

; + } + return ( { @@ -17,8 +18,15 @@ export const appBarSlice = createSlice({ setBackdrop: (state, action) => { state.backdrop = action.payload; }, + setPage: (state, action) => { + state.page = action.payload; + }, + removePage: (state) => { + state.page = undefined; + }, }, }); -export const { showAppBar, hideAppBar, setBackdrop } = appBarSlice.actions; +export const { showAppBar, hideAppBar, setBackdrop, setPage, removePage } = + appBarSlice.actions; export default appBarSlice.reducer;