Skip to content

Commit

Permalink
web: show error if saving takes more than 30 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr authored and ammarahm-ed committed May 10, 2024
1 parent 0e8ea3d commit 82cadd4
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions apps/web/src/components/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,38 @@ import { PanelGroup, Panel, PanelResizeHandle } from "react-resizable-panels";

const PDFPreview = React.lazy(() => import("../pdf-preview"));

function saveContent(noteId: string, ignoreEdit: boolean, content: string) {
async function saveContent(
noteId: string,
ignoreEdit: boolean,
content: string
) {
logger.debug("saving content", {
noteId,
ignoreEdit,
length: content.length
});
useEditorStore.getState().saveSessionContent(noteId, ignoreEdit, {
type: "tiptap",
data: content
});
await Promise.race([
useEditorStore.getState().saveSessionContent(noteId, ignoreEdit, {
type: "tiptap",
data: content
}),
new Promise((resolve) =>
setTimeout(() => {
const { hide } = showToast(
"error",
"Saving this note is taking too long. Copy your changes and restart the app to prevent data loss. If the problem persists, please report it to us at support@streetwriters.co.",
[
{
text: "Dismiss",
onClick: () => hide()
}
],
0
);
resolve(undefined);
}, 30 * 1000)
)
]);
}
const deferredSave = debounceWithId(saveContent, 100);

Expand Down

0 comments on commit 82cadd4

Please sign in to comment.