working on concurrency bug

This commit is contained in:
2024-11-18 13:01:27 -07:00
parent d689b4b684
commit cdd71a672f
5 changed files with 25 additions and 16 deletions

View File

@@ -48,7 +48,7 @@ export default function EditLecture({ lectureDay }: { lectureDay: string }) {
} else {
if (lecture) {
console.log(
"client not authoritative, updating client with server data"
"client not authoritative, updating client with server lecture"
);
textUpdate(lectureToString(lecture), true);
} else {

View File

@@ -35,8 +35,14 @@ export default function EditAssignment({
useAssignmentQuery(moduleName, assignmentName);
const updateAssignment = useUpdateAssignmentMutation();
const { clientIsAuthoritative, text, textUpdate, monacoKey } =
useAuthoritativeUpdates({
const {
clientIsAuthoritative,
text,
textUpdate,
monacoKey,
serverUpdatedAt,
clientDataUpdatedAt,
} = useAuthoritativeUpdates({
serverUpdatedAt: serverDataUpdatedAt,
startingText: localAssignmentMarkdown.toMarkdown(assignment),
});
@@ -79,7 +85,11 @@ export default function EditAssignment({
});
} else {
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);
}
@@ -96,10 +106,12 @@ export default function EditAssignment({
}, [
assignment,
assignmentName,
clientDataUpdatedAt,
clientIsAuthoritative,
courseName,
moduleName,
router,
serverUpdatedAt,
text,
textUpdate,
updateAssignment,

View File

@@ -72,7 +72,7 @@ export default function EditPage({
});
} else {
console.log(
"client not authoritative, updating client with server data"
"client not authoritative, updating client with server page"
);
textUpdate(localPageMarkdownUtils.toMarkdown(page), true);
}

View File

@@ -111,7 +111,7 @@ export default function EditQuiz({
});
} else {
console.log(
"client not authoritative, updating client with server data"
"client not authoritative, updating client with server quiz"
);
textUpdate(quizMarkdownUtils.toMarkdown(quiz), true);
}

View File

@@ -13,11 +13,6 @@ export function useAuthoritativeUpdates({
useState(serverUpdatedAt);
const [updateMonacoKey, setUpdateMonacoKey] = useState(1);
const clientIsAuthoritative = useMemo(
() => serverUpdatedAt <= clientDataUpdatedAt,
[clientDataUpdatedAt, serverUpdatedAt]
);
// console.log("client is authoritative", clientIsAuthoritative);
const textUpdate = useCallback((t: string, updateMonaco: boolean = false) => {
setText(t);
@@ -27,11 +22,13 @@ export function useAuthoritativeUpdates({
return useMemo(
() => ({
clientIsAuthoritative,
clientIsAuthoritative: serverUpdatedAt <= clientDataUpdatedAt,
serverUpdatedAt,
clientDataUpdatedAt,
textUpdate,
text,
monacoKey: updateMonacoKey,
}),
[clientIsAuthoritative, text, textUpdate, updateMonacoKey]
[clientDataUpdatedAt, serverUpdatedAt, text, textUpdate, updateMonacoKey]
);
}