Improve app loading state
This commit is contained in:
8 files changed
+140
-33
No files matched your search
@@ -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>
|
||||
|
||||
@@ -15,3 +15,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.appLoading {
|
||||
opacity: 0;
|
||||
}
|
||||
@@ -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 (
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user