Improve app loading state

This commit is contained in:
Prayag Prajapati committed 2023-08-28 16:13:04 +05:30
1 parent 7df0f3f9d3
commit f65e32cd49
8 files changed
+140 -33

No files matched your search

+16
View File
@@ -71,6 +71,7 @@ import { delUser, getUser } from "./utils/storage/user.js";
import axios from "axios";
import { useBackdropStore } from "./utils/store/backdrop.js";
import { useAppLoadingStore } from "./utils/store/appLoading.js";
const jellyfin = new Jellyfin({
clientInfo: {
@@ -131,6 +132,21 @@ function App() {
const [serverReachable, setServerReachable] = useState(true);
const [setIsAppLoading, setIsAppSuccess, setIsAppError] =
useAppLoadingStore((state) => [
state.setIsLoading,
state.setIsSuccess,
state.setIsError,
]);
useEffect(() => {
const appLoadingStateTimer = setInterval(() => {
setIsAppSuccess(false);
setIsAppError(false);
}, 8000);
return () => clearInterval(appLoadingStateTimer);
}, [setIsAppSuccess, setIsAppError]);
const { enqueueSnackbar } = useSnackbar();
const createApi = async () => {
+100 -15
View File
@@ -40,6 +40,7 @@ import { MdiCogSync } from "../icons/mdiCogSync";
import { useAppLoadingStore } from "../../utils/store/appLoading";
import { MdiCheck } from "../icons/mdiCheck";
import { MdiAlertDecagram } from "../icons/mdiAlertDecagram";
import { green, red } from "@mui/material/colors";
export const AppBar = () => {
const navigate = useNavigate();
@@ -61,7 +62,7 @@ export const AppBar = () => {
const trigger = useScrollTrigger({
disableHysteresis: true,
threshold: 0,
threshold: 20,
});
const [anchorEl, setAnchorEl] = useState(null);
@@ -82,7 +83,6 @@ export const AppBar = () => {
const [syncLoading, syncSuccess, syncError] = useAppLoadingStore(
(state) => [state.isLoading, state.isSuccess, state.isError],
);
console.log([syncLoading, syncSuccess, syncError]);
useEffect(() => {
if (
@@ -162,9 +162,10 @@ export const AppBar = () => {
</IconButton>
</Box>
<Box sx={{ display: "flex", gap: 2 }}>
<AnimatePresence>
{syncLoading && (
<AnimatePresence mode="wait">
{syncLoading ? (
<Box
key={`laoding`}
component={motion.div}
position="relative"
display="inline-flex"
@@ -172,10 +173,9 @@ export const AppBar = () => {
animate={{ opacity: 1 }}
exit={{
opacity: 0,
transition: {
delay: 10,
duration: 5,
},
}}
transition={{
duration: 0.2,
}}
>
<CircularProgress
@@ -197,17 +197,102 @@ export const AppBar = () => {
justifyContent: "center",
}}
>
{syncSuccess ? (
<MdiCheck />
) : syncError ? (
<MdiAlertDecagram />
) : (
<MdiCogSync />
)}
<MdiCogSync />
</IconButton>
</Box>
) : syncSuccess ? (
<Box
key={`success`}
component={motion.div}
position="relative"
display="inline-flex"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{
opacity: 0,
transition: {
delay: 0.4,
},
}}
transition={{
duration: 0.2,
}}
sx={{
background: green[500],
borderRadius: "1000px",
}}
>
<CircularProgress
sx={{
opacity: syncLoading
? 1
: 0,
}}
/>
<IconButton
sx={{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<MdiCheck />
</IconButton>
</Box>
) : syncError ? (
<Box
key={`error`}
component={motion.div}
position="relative"
display="inline-flex"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{
opacity: 0,
transition: {
delay: 0.4,
},
}}
transition={{
duration: 0.2,
}}
sx={{
background: red[900],
borderRadius: "1000px",
}}
>
<CircularProgress
sx={{
opacity: syncLoading
? 1
: 0,
}}
/>
<IconButton
sx={{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
<MdiAlertDecagram />
</IconButton>
</Box>
) : (
<></>
)}
</AnimatePresence>
<IconButton>
<MdiHeartOutline />
</IconButton>
+4
View File
@@ -15,3 +15,7 @@
}
}
}
.appLoading {
opacity: 0;
}
+4 -4
View File
@@ -75,8 +75,6 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
return { currentLatestMedia };
},
onError: (error, a, context) => {
setIsLoading(false);
setIsError(true);
enqueueSnackbar(
`An error occured while updating "${itemName}"`,
{
@@ -85,12 +83,14 @@ const LikeButton = ({ itemId, isFavorite, queryKey, userId, itemName }) => {
);
queryClient.setQueryData(queryKey, context.previousData);
console.error(error);
setIsError(true);
setIsLoading(false);
},
onSuccess: () => {
setIsLoading(false);
setIsSuccess(true);
console.log("Successfully updated", itemId);
queryClient.invalidateQueries(queryKey);
setIsSuccess(true);
setIsLoading(false);
},
});
return (
+4 -4
View File
@@ -73,8 +73,6 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
return { previousData };
},
onError: (error, a, context) => {
setIsLoading(false);
setIsError(true);
enqueueSnackbar(
`An error occured while updating "${itemName}"`,
{
@@ -83,12 +81,14 @@ const MarkPlayedButton = ({ itemId, isPlayed, queryKey, userId, itemName }) => {
);
queryClient.setQueryData(queryKey, context.previousData);
console.error(error);
setIsError(true);
setIsLoading(false);
},
onSuccess: () => {
setIsLoading(false);
setIsSuccess(true);
console.log("Successfully updated", itemId);
queryClient.invalidateQueries(queryKey);
setIsSuccess(true);
setIsLoading(false);
},
});
return (
+10 -7
View File
@@ -83,13 +83,16 @@ const CarouselSlide = ({ item }) => {
punch={1}
/>
)}
<motion.img
<img
className="hero-carousel-background-image"
src={
!!item.ParentBackdropItemId
? `${window.api.basePath}/Items/${item.ParentBackdropItemId}/Images/Backdrop`
: `${window.api.basePath}/Items/${item.Id}/Images/Backdrop`
}
style={{
opacity: 0,
}}
onLoad={(e) =>
(e.target.style.opacity = 1)
}
@@ -107,8 +110,8 @@ const CarouselSlide = ({ item }) => {
initial={{
transform:
animationDirection == "right"
? "translateX(40px)"
: "translateX(-40px)",
? "translateX(20%)"
: "translateX(-20%)",
opacity: 0,
}}
animate={{
@@ -118,8 +121,8 @@ const CarouselSlide = ({ item }) => {
exit={{
transform:
animationDirection == "right"
? "translateX(-40px)"
: "translateX(40px)",
? "translateX(-20%)"
: "translateX(20%)",
opacity: 0,
}}
@@ -140,7 +143,7 @@ const CarouselSlide = ({ item }) => {
{!item.ImageTags.Logo ? (
item.Name
) : (
<motion.img
<img
className="hero-carousel-text-logo"
src={
window.api.basePath +
@@ -151,7 +154,7 @@ const CarouselSlide = ({ item }) => {
}
style={{
opacity: 0,
transition: "opacity 250ms",
transition: "opacity 0.2s",
}}
onLoad={(e) =>
(e.target.style.opacity = 1)
+1 -2
View File
@@ -63,11 +63,10 @@
right: 0;
bottom: 0;
background-position: center;
opacity: 0;
object-fit: cover;
width: 100%;
height: 100%;
transition: opacity $transition-time-fast;
transition: opacity 0.5s;
}
&-icon {
position: absolute;
+1 -1
View File
@@ -905,7 +905,7 @@ const LibraryView = () => {
</Stack>
</Toolbar>
</AppBar>
{items.isLoading || items.isFetching ? (
{items.isLoading ? (
<Box
sx={{
position: "absolute",