mirror of
https://github.com/alexmickelson/canvasManagement.git
synced 2026-03-26 15:48:32 -06:00
working on concurrency bug
This commit is contained in:
@@ -48,7 +48,7 @@ export default function EditLecture({ lectureDay }: { lectureDay: string }) {
|
|||||||
} else {
|
} else {
|
||||||
if (lecture) {
|
if (lecture) {
|
||||||
console.log(
|
console.log(
|
||||||
"client not authoritative, updating client with server data"
|
"client not authoritative, updating client with server lecture"
|
||||||
);
|
);
|
||||||
textUpdate(lectureToString(lecture), true);
|
textUpdate(lectureToString(lecture), true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,11 +35,17 @@ export default function EditAssignment({
|
|||||||
useAssignmentQuery(moduleName, assignmentName);
|
useAssignmentQuery(moduleName, assignmentName);
|
||||||
const updateAssignment = useUpdateAssignmentMutation();
|
const updateAssignment = useUpdateAssignmentMutation();
|
||||||
|
|
||||||
const { clientIsAuthoritative, text, textUpdate, monacoKey } =
|
const {
|
||||||
useAuthoritativeUpdates({
|
clientIsAuthoritative,
|
||||||
serverUpdatedAt: serverDataUpdatedAt,
|
text,
|
||||||
startingText: localAssignmentMarkdown.toMarkdown(assignment),
|
textUpdate,
|
||||||
});
|
monacoKey,
|
||||||
|
serverUpdatedAt,
|
||||||
|
clientDataUpdatedAt,
|
||||||
|
} = useAuthoritativeUpdates({
|
||||||
|
serverUpdatedAt: serverDataUpdatedAt,
|
||||||
|
startingText: localAssignmentMarkdown.toMarkdown(assignment),
|
||||||
|
});
|
||||||
|
|
||||||
const [error, setError] = useState("");
|
const [error, setError] = useState("");
|
||||||
const [showHelp, setShowHelp] = useState(false);
|
const [showHelp, setShowHelp] = useState(false);
|
||||||
@@ -79,7 +85,11 @@ export default function EditAssignment({
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"client not authoritative, updating client with server data"
|
"client not authoritative, updating client with server assignment",
|
||||||
|
"client updated",
|
||||||
|
clientDataUpdatedAt,
|
||||||
|
"server updated",
|
||||||
|
serverUpdatedAt
|
||||||
);
|
);
|
||||||
textUpdate(localAssignmentMarkdown.toMarkdown(assignment), true);
|
textUpdate(localAssignmentMarkdown.toMarkdown(assignment), true);
|
||||||
}
|
}
|
||||||
@@ -96,10 +106,12 @@ export default function EditAssignment({
|
|||||||
}, [
|
}, [
|
||||||
assignment,
|
assignment,
|
||||||
assignmentName,
|
assignmentName,
|
||||||
|
clientDataUpdatedAt,
|
||||||
clientIsAuthoritative,
|
clientIsAuthoritative,
|
||||||
courseName,
|
courseName,
|
||||||
moduleName,
|
moduleName,
|
||||||
router,
|
router,
|
||||||
|
serverUpdatedAt,
|
||||||
text,
|
text,
|
||||||
textUpdate,
|
textUpdate,
|
||||||
updateAssignment,
|
updateAssignment,
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export default function EditPage({
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"client not authoritative, updating client with server data"
|
"client not authoritative, updating client with server page"
|
||||||
);
|
);
|
||||||
textUpdate(localPageMarkdownUtils.toMarkdown(page), true);
|
textUpdate(localPageMarkdownUtils.toMarkdown(page), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ export default function EditQuiz({
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
console.log(
|
||||||
"client not authoritative, updating client with server data"
|
"client not authoritative, updating client with server quiz"
|
||||||
);
|
);
|
||||||
textUpdate(quizMarkdownUtils.toMarkdown(quiz), true);
|
textUpdate(quizMarkdownUtils.toMarkdown(quiz), true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,11 +13,6 @@ export function useAuthoritativeUpdates({
|
|||||||
useState(serverUpdatedAt);
|
useState(serverUpdatedAt);
|
||||||
const [updateMonacoKey, setUpdateMonacoKey] = useState(1);
|
const [updateMonacoKey, setUpdateMonacoKey] = useState(1);
|
||||||
|
|
||||||
const clientIsAuthoritative = useMemo(
|
|
||||||
() => serverUpdatedAt <= clientDataUpdatedAt,
|
|
||||||
[clientDataUpdatedAt, serverUpdatedAt]
|
|
||||||
);
|
|
||||||
|
|
||||||
// console.log("client is authoritative", clientIsAuthoritative);
|
// console.log("client is authoritative", clientIsAuthoritative);
|
||||||
const textUpdate = useCallback((t: string, updateMonaco: boolean = false) => {
|
const textUpdate = useCallback((t: string, updateMonaco: boolean = false) => {
|
||||||
setText(t);
|
setText(t);
|
||||||
@@ -27,11 +22,13 @@ export function useAuthoritativeUpdates({
|
|||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
clientIsAuthoritative,
|
clientIsAuthoritative: serverUpdatedAt <= clientDataUpdatedAt,
|
||||||
|
serverUpdatedAt,
|
||||||
|
clientDataUpdatedAt,
|
||||||
textUpdate,
|
textUpdate,
|
||||||
text,
|
text,
|
||||||
monacoKey: updateMonacoKey,
|
monacoKey: updateMonacoKey,
|
||||||
}),
|
}),
|
||||||
[clientIsAuthoritative, text, textUpdate, updateMonacoKey]
|
[clientDataUpdatedAt, serverUpdatedAt, text, textUpdate, updateMonacoKey]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user