fix: AwarenessChangeEvent type

This commit is contained in:
Tom Moor
2023-05-22 23:10:05 -04:00
parent bb0cd891bd
commit e8b9a1b650
3 changed files with 10 additions and 10 deletions

View File

@@ -107,13 +107,11 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
presence.updateFromAwarenessChangeEvent(documentId, event);
event.states.forEach(({ user, scrollY }) => {
if (user) {
if (scrollY !== undefined && user.id === ui.observingUserId) {
window.scrollTo({
top: scrollY * window.innerHeight,
behavior: "smooth",
});
}
if (scrollY !== undefined && user?.id === ui.observingUserId) {
window.scrollTo({
top: scrollY * window.innerHeight,
behavior: "smooth",
});
}
});
});

View File

@@ -38,8 +38,10 @@ export default class PresenceStore {
event.states.forEach((state) => {
const { user, cursor } = state;
this.update(documentId, user.id, !!cursor);
existingUserIds = existingUserIds.filter((id) => id !== user.id);
if (user) {
this.update(documentId, user.id, !!cursor);
existingUserIds = existingUserIds.filter((id) => id !== user.id);
}
});
existingUserIds.forEach((userId) => {

View File

@@ -204,5 +204,5 @@ export type WebsocketEvent =
| WebsocketEntitiesEvent;
export type AwarenessChangeEvent = {
states: { user: { id: string }; cursor: any; scrollY: number | undefined }[];
states: { user?: { id: string }; cursor: any; scrollY: number | undefined }[];
};