diff --git a/src/components/appBar/appBar.jsx b/src/components/appBar/appBar.jsx index a6a605f..eb1f2a6 100644 --- a/src/components/appBar/appBar.jsx +++ b/src/components/appBar/appBar.jsx @@ -1,6 +1,8 @@ /** @format */ import { useEffect, useState } from "react"; +import { AnimatePresence, motion } from "framer-motion"; + import { relaunch } from "@tauri-apps/api/process"; import MuiAppBar from "@mui/material/AppBar"; @@ -12,6 +14,7 @@ import Box from "@mui/material/Box"; import ListItemIcon from "@mui/material/ListItemIcon"; import Menu from "@mui/material/Menu"; import MenuItem from "@mui/material/MenuItem"; +import CircularProgress from "@mui/material/CircularProgress"; import useScrollTrigger from "@mui/material/useScrollTrigger"; import { MdiMagnify } from "../icons/mdiMagnify"; @@ -33,6 +36,10 @@ import { useDrawerStore } from "../../utils/store/drawer"; import { delServer } from "../../utils/storage/servers"; import { delUser } from "../../utils/storage/user"; import { MdiDelete } from "../icons/mdiDelete"; +import { MdiCogSync } from "../icons/mdiCogSync"; +import { useAppLoadingStore } from "../../utils/store/appLoading"; +import { MdiCheck } from "../icons/mdiCheck"; +import { MdiAlertDecagram } from "../icons/mdiAlertDecagram"; export const AppBar = () => { const navigate = useNavigate(); @@ -72,6 +79,11 @@ export const AppBar = () => { setDrawerOpen(true); }; + const [syncLoading, syncSuccess, syncError] = useAppLoadingStore( + (state) => [state.isLoading, state.isSuccess, state.isError], + ); + console.log([syncLoading, syncSuccess, syncError]); + useEffect(() => { if ( location.pathname.includes("login") || @@ -150,6 +162,52 @@ export const AppBar = () => { + + {syncLoading && ( + + + + {syncSuccess ? ( + + ) : syncError ? ( + + ) : ( + + )} + + + )} + diff --git a/src/components/buttons/likeButton.jsx b/src/components/buttons/likeButton.jsx index ec40208..090a9ab 100644 --- a/src/components/buttons/likeButton.jsx +++ b/src/components/buttons/likeButton.jsx @@ -9,11 +9,16 @@ import { pink } from "@mui/material/colors"; import { MdiHeart } from "../icons/mdiHeart"; import { MdiHeartOutline } from "../icons/mdiHeartOutline"; import { useSnackbar } from "notistack"; +import { useAppLoadingStore } from "../../utils/store/appLoading"; const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => { const queryClient = useQueryClient(); const { enqueueSnackbar } = useSnackbar(); + const [setIsLoading, setIsSuccess, setIsError] = useAppLoadingStore( + (state) => [state.setIsLoading, state.setIsSuccess, state.setIsError], + ); + const handleLiking = async () => { let result; console.log(isFavorite); @@ -32,25 +37,46 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => { const mutation = useMutation({ mutationFn: handleLiking, onMutate: () => { + setIsLoading(true); + setIsError(false); + setIsSuccess(false); + queryClient.cancelQueries(queryKey); const currentLatestMedia = queryClient.getQueryData(queryKey); - queryClient.setQueryData(queryKey, (oldMedia) => - oldMedia.map((oitem) => { - if (oitem.Id == itemId) { - return { - ...oitem, - UserData: { - ...oitem.UserData, - IsFavorite: !isFavorite, - }, - }; - } - return oitem; - }), - ); + queryClient.setQueryData(queryKey, (oldMedia) => { + try { + oldMedia.Items.map((oitem) => { + if (oitem.Id == itemId) { + return { + ...oitem, + UserData: { + ...oitem.UserData, + IsFavorite: !isFavorite, + }, + }; + } + return oitem; + }); + } catch (error) { + oldMedia.map((oitem) => { + if (oitem.Id == itemId) { + return { + ...oitem, + UserData: { + ...oitem.UserData, + IsFavorite: !isFavorite, + }, + }; + } + return oitem; + }); + } + }); return { currentLatestMedia }; }, onError: (error, a, context) => { + setIsLoading(false); + setIsError(true); enqueueSnackbar( `An error occured while updating "${itemName}"`, { @@ -61,12 +87,20 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => { console.error(error); }, onSuccess: () => { + setIsLoading(false); + setIsSuccess(true); console.log("Successfully updated", itemId); queryClient.invalidateQueries(queryKey); }, }); return ( - + { + e.stopPropagation(); + mutation.mutate(); + }} + disabled={mutation.isLoading} + > {isFavorite ? ( ) : ( diff --git a/src/components/buttons/markPlayedButton.jsx b/src/components/buttons/markPlayedButton.jsx index 482d770..81ce848 100644 --- a/src/components/buttons/markPlayedButton.jsx +++ b/src/components/buttons/markPlayedButton.jsx @@ -10,11 +10,16 @@ import { green } from "@mui/material/colors"; import { getPlaystateApi } from "@jellyfin/sdk/lib/utils/api/playstate-api"; import { MdiCheck } from "../icons/mdiCheck"; import { useSnackbar } from "notistack"; +import { useAppLoadingStore } from "../../utils/store/appLoading"; const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => { const queryClient = useQueryClient(); const { enqueueSnackbar } = useSnackbar(); + const [setIsLoading, setIsSuccess, setIsError] = useAppLoadingStore( + (state) => [state.setIsLoading, state.setIsSuccess, state.setIsError], + ); + const handleMarking = async () => { if (!isPlayed) { await getPlaystateApi(window.api).markPlayedItem({ @@ -31,25 +36,45 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => { const mutation = useMutation({ mutationFn: handleMarking, onMutate: () => { + setIsLoading(true); + setIsError(false); + setIsSuccess(false); queryClient.cancelQueries(queryKey); const previousData = queryClient.getQueryData(queryKey); - queryClient.setQueryData(queryKey, (oldMedia) => - oldMedia.map((oitem) => { - if (oitem.Id == itemId) { - return { - ...oitem, - UserData: { - ...oitem.UserData, - Played: !isPlayed, - }, - }; - } - return oitem; - }), - ); + queryClient.setQueryData(queryKey, (oldMedia) => { + try { + oldMedia.Items.map((oitem) => { + if (oitem.Id == itemId) { + return { + ...oitem, + UserData: { + ...oitem.UserData, + Played: !isPlayed, + }, + }; + } + return oitem; + }); + } catch (error) { + oldMedia.map((oitem) => { + if (oitem.Id == itemId) { + return { + ...oitem, + UserData: { + ...oitem.UserData, + Played: !isPlayed, + }, + }; + } + return oitem; + }); + } + }); return { previousData }; }, onError: (error, a, context) => { + setIsLoading(false); + setIsError(true); enqueueSnackbar( `An error occured while updating "${itemName}"`, { @@ -60,12 +85,20 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => { console.error(error); }, onSuccess: () => { + setIsLoading(false); + setIsSuccess(true); console.log("Successfully updated", itemId); queryClient.invalidateQueries(queryKey); }, }); return ( - + { + e.stopPropagation(); + mutation.mutate(); + }} + disabled={mutation.isLoading} + > { + return ( + + + + ); +}; diff --git a/src/routes/home/index.jsx b/src/routes/home/index.jsx index e82a2d8..9ad62d9 100644 --- a/src/routes/home/index.jsx +++ b/src/routes/home/index.jsx @@ -292,8 +292,7 @@ const Home = () => { } queryKey={[ "home", - "resume", - "video", + "upNext", ]} isPlayed={ item.UserData.Played @@ -393,7 +392,7 @@ const Home = () => { queryKey={[ "home", "resume", - "video", + "audio", ]} isPlayed={ item.UserData.Played diff --git a/src/routes/library/index.jsx b/src/routes/library/index.jsx index 0bde7ef..89d6d3e 100644 --- a/src/routes/library/index.jsx +++ b/src/routes/library/index.jsx @@ -968,6 +968,50 @@ const LibraryView = () => { ? "square" : "portrait" } + isFavorite={ + item.UserData.IsFavorite + } + queryKey={[ + "libraryView", + "currentLibItems", + id, + `page: ${page}`, + [ + currentViewType, + + sortAscending + ? SortOrder.Ascending + : SortOrder.Descending, + , + sortBy, + [ + isPlayed, + isUnPlayed, + isResumable, + isFavorite, + isLiked, + isUnliked, + ], + [ + hasSubtitles, + hasTrailer, + hasSpecialFeature, + hasThemeSong, + hasThemeVideo, + ], + [ + isBluRay, + isDVD, + isHD, + is4K, + is3D, + ], + ], + ]} + isPlayed={ + item.UserData.Played + } + userId={user.data.Id} > ); diff --git a/src/routes/login/index.jsx b/src/routes/login/index.jsx index 84681e3..efece58 100644 --- a/src/routes/login/index.jsx +++ b/src/routes/login/index.jsx @@ -284,13 +284,10 @@ export const UserLogin = () => { key={index} itemName={item.Name} itemId={item.Id} - imageTags={ - !!item.PrimaryImageTag - } disableOverlay - iconType="User" - cardOrientation="sqaure" - onClickEvent={() => + itemType="User" + cardType="square" + onClick={() => navigate( `/login/withImg/${item.Name}/${item.Id}/`, ) diff --git a/src/utils/store/appLoading.js b/src/utils/store/appLoading.js new file mode 100644 index 0000000..1cf27f5 --- /dev/null +++ b/src/utils/store/appLoading.js @@ -0,0 +1,14 @@ +/** @format */ + +import { create } from "zustand"; + +export const useAppLoadingStore = create((set) => ({ + isLoading: false, + isSuccess: false, + isError: false, + setIsLoading: (loading) => + set((state) => ({ ...state, isLoading: loading })), + setIsSuccess: (success) => + set((state) => ({ ...state, isSuccess: success })), + setIsError: (error) => set((state) => ({ ...state, isError: error })), +}));