Skip to content

Commit 05bc8a5

Browse files
committed
refactor: remove CanvasBackups.tsx component and integrate BackupsDialog
- Deleted the CanvasBackups component and its associated files to streamline the codebase. - Updated the MainMenu to use the new BackupsDialog component for managing canvas backups. - Introduced new styles for the BackupsDialog to enhance the user interface and experience.
1 parent 77c09f2 commit 05bc8a5

File tree

8 files changed

+150
-241
lines changed

8 files changed

+150
-241
lines changed

src/frontend/src/CustomEmbeddableRenderer.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
ControlButton,
88
HtmlEditor,
99
Editor,
10-
CanvasBackups
1110
} from './pad';
1211
import { ActionButton } from './pad/buttons';
1312

@@ -38,8 +37,6 @@ export const renderCustomEmbeddable = (
3837
/>;
3938
case 'dashboard':
4039
return <Dashboard element={element} appState={appState} excalidrawAPI={excalidrawAPI} />;
41-
case 'backups':
42-
return <CanvasBackups element={element} appState={appState} excalidrawAPI={excalidrawAPI} />;
4340
default:
4441
return null;
4542
}

src/frontend/src/pad/backups/CanvasBackups.tsx

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/frontend/src/pad/backups/index.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/frontend/src/pad/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ export * from './controls/StateIndicator';
44
export * from './containers/Dashboard';
55
export * from './buttons';
66
export * from './editors';
7-
export * from './backups';
87

98
// Default exports
109
export { default as ControlButton } from './controls/ControlButton';
1110
export { default as StateIndicator } from './controls/StateIndicator';
1211
export { default as Dashboard } from './containers/Dashboard';
13-
export { default as CanvasBackups } from './backups/CanvasBackups';

src/frontend/src/styles/BackupsModal.scss renamed to src/frontend/src/styles/BackupsDialog.scss

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
11
.backups-modal {
2+
.Island {
3+
padding-top: 15px !important;
4+
padding-bottom: 20px !important;
5+
}
6+
7+
&__wrapper {
8+
position: absolute;
9+
top: 0;
10+
left: 0;
11+
width: 100%;
12+
height: 100%;
13+
z-index: 5;
14+
background-color: rgba(0, 0, 0, 0.2);
15+
backdrop-filter: blur(1px);
16+
}
17+
18+
&__title-container {
19+
display: flex;
20+
align-items: center;
21+
}
22+
223
&__content {
324
padding: 20px;
425
max-height: 80vh;
@@ -33,7 +54,7 @@
3354
}
3455

3556
&__title {
36-
margin: 0 0 1rem;
57+
margin: 0;
3758
font-size: 1.2rem;
3859
font-weight: 500;
3960
color: #ffffff;
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import React, { useState, useCallback } from "react";
2+
import { Dialog } from "@atyrode/excalidraw";
3+
import { useCanvasBackups, CanvasBackup } from "../api/hooks";
4+
import "../styles/BackupsDialog.scss";
5+
6+
interface BackupsModalProps {
7+
excalidrawAPI?: any;
8+
onClose?: () => void;
9+
}
10+
11+
const BackupsModal: React.FC<BackupsModalProps> = ({
12+
excalidrawAPI,
13+
onClose,
14+
}) => {
15+
const [modalIsShown, setModalIsShown] = useState(true);
16+
const { data, isLoading, error } = useCanvasBackups();
17+
const [selectedBackup, setSelectedBackup] = useState<CanvasBackup | null>(null);
18+
19+
// Functions from CanvasBackups.tsx
20+
const handleBackupSelect = (backup: CanvasBackup) => {
21+
setSelectedBackup(backup);
22+
};
23+
24+
const handleRestoreBackup = () => {
25+
if (selectedBackup && excalidrawAPI) {
26+
// Load the backup data into the canvas
27+
excalidrawAPI.updateScene(selectedBackup.data);
28+
setSelectedBackup(null);
29+
handleClose();
30+
}
31+
};
32+
33+
const handleCancel = () => {
34+
setSelectedBackup(null);
35+
};
36+
37+
// Format date function from CanvasBackups.tsx
38+
const formatDate = (dateString: string): string => {
39+
const date = new Date(dateString);
40+
return date.toLocaleString(undefined, {
41+
year: 'numeric',
42+
month: 'short',
43+
day: 'numeric',
44+
hour: '2-digit',
45+
minute: '2-digit'
46+
});
47+
};
48+
49+
const handleClose = useCallback(() => {
50+
setModalIsShown(false);
51+
if (onClose) {
52+
onClose();
53+
}
54+
}, [onClose]);
55+
56+
// Dialog content
57+
const dialogContent = (
58+
<div className="backups-modal__content">
59+
{isLoading ? (
60+
<div className="backups-modal__loading">Loading backups...</div>
61+
) : error ? (
62+
<div className="backups-modal__error">Error loading backups</div>
63+
) : !data || data.backups.length === 0 ? (
64+
<div className="backups-modal__empty">No backups available</div>
65+
) : selectedBackup ? (
66+
<div className="backups-modal__confirmation">
67+
<p>Restore canvas from backup #{data.backups.findIndex(b => b.id === selectedBackup.id) + 1} created on {formatDate(selectedBackup.timestamp)}?</p>
68+
<p className="backups-modal__warning">This will replace your current canvas!</p>
69+
<div className="backups-modal__actions">
70+
<button
71+
className="backups-modal__button backups-modal__button--restore"
72+
onClick={handleRestoreBackup}
73+
>
74+
Restore
75+
</button>
76+
<button
77+
className="backups-modal__button backups-modal__button--cancel"
78+
onClick={handleCancel}
79+
>
80+
Cancel
81+
</button>
82+
</div>
83+
</div>
84+
) : (
85+
<ul className="backups-modal__list">
86+
{data.backups.map((backup, index) => (
87+
<li
88+
key={backup.id}
89+
className="backups-modal__item"
90+
onClick={() => handleBackupSelect(backup)}
91+
>
92+
<div className="backups-modal__item-content">
93+
<span className="backups-modal__number">#{index + 1}</span>
94+
<span className="backups-modal__timestamp">{formatDate(backup.timestamp)}</span>
95+
</div>
96+
<button className="backups-modal__restore-button">Restore</button>
97+
</li>
98+
))}
99+
</ul>
100+
)}
101+
</div>
102+
);
103+
104+
return (
105+
<>
106+
{modalIsShown && (
107+
<div className="backups-modal__wrapper">
108+
<Dialog
109+
className="backups-modal"
110+
size="small"
111+
onCloseRequest={handleClose}
112+
title={
113+
<div className="backups-modal__title-container">
114+
<h2 className="backups-modal__title">Canvas Backups</h2>
115+
</div>
116+
}
117+
closeOnClickOutside={false}
118+
children={dialogContent}
119+
/>
120+
</div>
121+
)}
122+
</>
123+
);
124+
};
125+
126+
export default BackupsModal;

0 commit comments

Comments
 (0)