sveltekit-sync
Version:
Local-first sync engine for SvelteKit
46 lines (45 loc) • 1.14 kB
TypeScript
/**
* "Who's Here" Utility
*
* Simplified helper for displaying online users.
*/
import type { UsePresenceReturn } from '../hooks/usePresence.svelte.js';
import type { User } from '../presence.svelte.js';
export interface WhoIsHereReturn {
users: User[];
avatars: Array<{
user: User;
color: string;
}>;
count: number;
onlineCount: number;
isAlone: boolean;
}
/**
* Get information about who's online
*
* @param presence - The presence hook instance
* @returns Who's here information
*
* @example
* ```svelte
* <script>
* const presence = usePresence(channel, currentUser);
* const whoIsHere = useWhoIsHere(presence);
* </script>
*
* <div class="avatars">
* {#if whoIsHere.isAlone}
* <p>You're the only one here</p>
* {:else}
* <p>{whoIsHere.onlineCount} people online</p>
* {#each whoIsHere.avatars as { user, color }}
* <div class="avatar" style="background: {color}">
* {user.name[0]}
* </div>
* {/each}
* {/if}
* </div>
* ```
*/
export declare function useWhoIsHere(presence: UsePresenceReturn<any>): WhoIsHereReturn;