Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[photobook][web] Preserve saved books after restore failures (#14341)

Anandaf1f8ae1314b
diff --git a/web/apps/photobook/src/components/RestoreErrorDialog.tsx b/web/apps/photobook/src/components/RestoreErrorDialog.tsx
new file mode 100644
index 0000000000..7f372dcc8c
--- /dev/null
+++ b/web/apps/photobook/src/components/RestoreErrorDialog.tsx
@@ -0,0 +1,84 @@
+import { accentGreen, accentGreenHover } from "@/theme/buttons";
+import { uiColors } from "@/theme/colors";
+import {
+ dialogActionSx,
+ dialogDescriptionSx,
+ dialogHeaderSx,
+ dialogPaperSx,
+ dialogTitleSx,
+} from "@/theme/dialogs";
+import { Box, Button, Dialog, Typography } from "@mui/material";
+import { ErrorIcon } from "./icons";
+
+export default function RestoreErrorDialog() {
+ return (
+ <Dialog
+ open
+ maxWidth={false}
+ aria-labelledby="restore-error-title"
+ aria-describedby="restore-error-description"
+ slotProps={{
+ paper: { role: "alertdialog", sx: dialogPaperSx },
+ backdrop: { sx: { bgcolor: "rgba(0,0,0,0.5)" } },
+ }}
+ >
+ <Box sx={{ position: "relative", p: "48px 16px 16px" }}>
+ <Box
+ sx={{
+ display: "flex",
+ flexDirection: "column",
+ alignItems: "center",
+ gap: "16px",
+ }}
+ >
+ <Box
+ aria-hidden="true"
+ sx={{
+ width: 126,
+ height: 121,
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ mb: "8px",
+ color: uiColors.danger,
+ }}
+ >
+ <ErrorIcon sx={{ fontSize: 72 }} />
+ </Box>
+ <Box sx={dialogHeaderSx}>
+ <Typography
+ component="h2"
+ id="restore-error-title"
+ sx={dialogTitleSx}
+ >
+ Couldn&apos;t open photobook
+ </Typography>
+ <Typography
+ id="restore-error-description"
+ sx={dialogDescriptionSx}
+ >
+ Your saved book hasn&apos;t been changed.
+ <br />
+ Reload to try again.
+ </Typography>
+ </Box>
+ <Button
+ variant="contained"
+ fullWidth
+ disableElevation
+ autoFocus
+ onClick={() => window.location.reload()}
+ sx={{
+ ...dialogActionSx,
+ color: "#FFFFFF",
+ bgcolor: accentGreen,
+ "&:hover": { bgcolor: accentGreenHover },
+ }}
+ >
+ Reload
+ </Button>
+ </Box>
+ </Box>
+ </Dialog>
+ );
+}
diff --git a/web/apps/photobook/src/context/BookContext.tsx b/web/apps/photobook/src/context/BookContext.tsx
index 614cd1e2bf..3053da2b9d 100644
--- a/web/apps/photobook/src/context/BookContext.tsx
+++ b/web/apps/photobook/src/context/BookContext.tsx
@@ -1,3 +1,4 @@
+import RestoreErrorDialog from "@/components/RestoreErrorDialog";
import {
isBlankPage,
isRequiredBlankPage,
@@ -138,6 +139,7 @@ function buildEnteOriginalDownloadJob(
export function BookProvider({ children }: { children: React.ReactNode }) {
const [appView, setAppViewState] = useState<AppView>("edit");
const [loading, setLoading] = useState(true);
+ const [restoreFailed, setRestoreFailed] = useState(false);
const [photos, setPhotos] = useState<Photo[]>([]);
const photosRef = useRef<Photo[]>(photos);
photosRef.current = photos;
@@ -283,7 +285,13 @@ export function BookProvider({ children }: { children: React.ReactNode }) {
new Map(),
);
useEffect(() => {
- if (loading || processingPhotos || resettingRef.current) return;
+ if (
+ loading ||
+ restoreFailed ||
+ processingPhotos ||
+ resettingRef.current
+ )
+ return;
const saveTimeout = setTimeout(() => {
saveTimeoutRef.current = null;
autosaveRef.current = autosaveRef.current
@@ -301,7 +309,15 @@ export function BookProvider({ children }: { children: React.ReactNode }) {
saveTimeoutRef.current = saveTimeout;
return () => clearTimeout(saveTimeout);
- }, [book, photos, appView, currentSpreadIndex, loading, processingPhotos]);
+ }, [
+ book,
+ photos,
+ appView,
+ currentSpreadIndex,
+ loading,
+ restoreFailed,
+ processingPhotos,
+ ]);
useEffect(() => {
void (async () => {
@@ -342,6 +358,7 @@ export function BookProvider({ children }: { children: React.ReactNode }) {
}
} catch (e) {
console.error("Failed to restore session:", e);
+ setRestoreFailed(true);
} finally {
setLoading(false);
}
@@ -1463,6 +1480,8 @@ export function BookProvider({ children }: { children: React.ReactNode }) {
}
}, []);
+ if (restoreFailed) return <RestoreErrorDialog />;
+
return (
<BookContext.Provider
value={{