Skip to content

Commit d81a0c9

Browse files
committed
feat: use useRemoteUsers
1 parent 532ad0c commit d81a0c9

File tree

3 files changed

+4
-30
lines changed

3 files changed

+4
-30
lines changed

assets/js/collaborative-editor/components/ActiveCollaborators.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cn } from '../../utils/cn';
2-
import { useAwareness } from '../hooks/useAwareness';
2+
import { useRemoteUsers } from '../hooks/useAwareness';
33
import { getAvatarInitials } from '../utils/avatar';
44

55
import { Tooltip } from './Tooltip';
@@ -9,7 +9,7 @@ interface ActiveCollaboratorsProps {
99
}
1010

1111
export function ActiveCollaborators({ className }: ActiveCollaboratorsProps) {
12-
const remoteUsers = useAwareness({ cached: true });
12+
const remoteUsers = useRemoteUsers();
1313

1414
if (remoteUsers.length === 0) {
1515
return null;

assets/js/collaborative-editor/components/CollaborationWidget.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
import { useSocket } from '../../react/contexts/SocketProvider';
77
import { cn } from '../../utils/cn';
8-
import { useAwareness } from '../hooks/useAwareness';
8+
import { useRemoteUsers } from '../hooks/useAwareness';
99
import { useSession } from '../hooks/useSession';
1010

1111
export function CollaborationWidget() {
1212
const { isConnected: socketConnected, connectionError } = useSocket();
1313
const { isConnected: yjsConnected, isSynced } = useSession();
1414

1515
// Get remote users only (local user is always excluded)
16-
const remoteUsers = useAwareness({ cached: true });
16+
const remoteUsers = useRemoteUsers();
1717

1818
const getStatusColor = () => {
1919
if (socketConnected && yjsConnected && isSynced) return 'bg-green-500';

assets/test/collaborative-editor/components/ActiveCollaborators.test.tsx

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -433,32 +433,6 @@ describe('ActiveCollaborators - Cache Behavior', () => {
433433
expect(screen.getByText('JD')).toBeInTheDocument();
434434
});
435435

436-
test('cached users appear with their last known state', () => {
437-
const now = Date.now();
438-
const fiveSecondsAgo = now - 5 * 1000;
439-
440-
// User active 5 seconds ago
441-
mockRemoteUsers = [
442-
createMockAwarenessUser({
443-
user: {
444-
id: 'user-1',
445-
name: 'Jane Smith',
446-
email: 'jane@example.com',
447-
color: '#00ff00',
448-
},
449-
lastSeen: fiveSecondsAgo,
450-
}),
451-
];
452-
453-
render(<ActiveCollaborators />);
454-
455-
// Should still show as active (green border) because < 12 seconds
456-
expect(screen.getByText('JS')).toBeInTheDocument();
457-
expect(screen.getByText('JS').closest('div')?.parentElement).toHaveClass(
458-
'border-green-500'
459-
);
460-
});
461-
462436
test('cached users eventually expire after threshold', () => {
463437
const now = Date.now();
464438
const thirtySecondsAgo = now - 30 * 1000; // Well over 12 seconds

0 commit comments

Comments
 (0)