Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopped writing to resources that are not editable #17

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,10 @@ const ScriptureChunkEditorSlate = memo(
/** When the contents are changed, update the chapter chunk */
const onChange = useCallback(
(value: CustomDescendant[]) => {
// Normalizing when loading a resource fires an onChange because the text is not generated with empty text between elements.
// Let's just skip writing on uneditable texts and fix the other problem another time
if (!editable) return;

// Don't try to send update for chapter -1 when loading
// If we ever decide to send writes by book, this could become a problem.
// Filter out changes that are just selection changes - thanks to the Slate tutorial https://docs.slatejs.org/walkthroughs/06-saving-to-a-database
Expand All @@ -834,7 +838,13 @@ const ScriptureChunkEditorSlate = memo(
contents: value,
});
},
[editor, updateScrChapterChunk, chunkIndex, scrChapterChunk],
[
editor,
editable,
updateScrChapterChunk,
chunkIndex,
scrChapterChunk,
],
);

// Focus the editor when we close the search bar
Expand Down