Skip to content

Commit

Permalink
chore: catch error in calling postSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
stevekaplan123 committed Dec 2, 2024
1 parent d307f74 commit 0acedb6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 10 additions & 6 deletions static/js/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ const SefariaEditor = (props) => {

setUnsavedChanges(true);
// Update debounced value after delay
const handler = setTimeout(() => {
const handler = setTimeout( () => {
saveDocument(currentDocument);
}, 500);

Expand Down Expand Up @@ -2629,7 +2629,7 @@ const SefariaEditor = (props) => {
if (node.text && props.divineNameReplacement) {
const newStr = replaceDivineNames(node.text, props.divineNameReplacement)
if (newStr != node.text) {
Transforms.insertText(editor, newStr, { at: path })
Transforms.insertText(editor, newStr, {at: path})
}
}
}
Expand All @@ -2640,8 +2640,8 @@ const SefariaEditor = (props) => {
const temp_select = editor.selection

Transforms.select(editor, {
anchor: {path: [0, 0], offset: 0},
focus: {path: [0, 0], offset: 0},
anchor: {path: [0, 0], offset: 0},
focus: {path: [0, 0], offset: 0},
});

Transforms.select(editor, temp_select)
Expand Down Expand Up @@ -2782,14 +2782,18 @@ const SefariaEditor = (props) => {
function getLastModified() {
return Sefaria.sheets._loadSheetByID[props.data.id]?.dateModified || props.data.dateModified;
}
function saveDocument(doc) {
async function saveDocument(doc) {
const lastModified = getLastModified();
const json = saveSheetContent(doc[0], lastModified);
if (!json) {
return
}
// console.log('saving...');
postSheet(json);
try {
await postSheet(json);
} catch(error) {
console.log(`Error: ${error.message}`)
}
}

const postSheet = async (sheet) => {
Expand Down
11 changes: 6 additions & 5 deletions static/js/sheets/SheetOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ const PublishModal = ({close, status, sheetID, postSheet}) => {
sheet.status = status === 'public' ? "unlisted" : "public";
sheet.lastModified = sheet.dateModified;
delete sheet._id;
postSheet(sheet, sheet.id).then(() => {
setPublishText(publishState.posted);
}).catch(error => {
setPublishText(error.message);
})
try {
await postSheet(sheet);
setPublishText(publishState.posted);
} catch (error) {
setPublishText(`Error: ${error.message}`);
}
}
useEffect( () => {
const toggle = async () => {
Expand Down

0 comments on commit 0acedb6

Please sign in to comment.