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); presence.updateFromAwarenessChangeEvent(documentId, event);
event.states.forEach(({ user, scrollY }) => { event.states.forEach(({ user, scrollY }) => {
if (user) { if (scrollY !== undefined && user?.id === ui.observingUserId) {
if (scrollY !== undefined && user.id === ui.observingUserId) { window.scrollTo({
window.scrollTo({ top: scrollY * window.innerHeight,
top: scrollY * window.innerHeight, behavior: "smooth",
behavior: "smooth", });
});
}
} }
}); });
}); });

View File

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

View File

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