import { useSyncExternalStore } from 'react' import { USER_COLORS } from '@/lib/collab/colors' import type { UserProfile } from '@/lib/collab/types' import { User } from '@/client/features/collab/components/user' import { UserAvatar } from '@/client/features/collab/components/user-avatar' import { getCurrentUser, getCurrentUserSource, setLocalUser, subscribeCurrentUserStore } from '@/client/features/collab/host-state' export function LocalUserSettings() { const source = useSyncExternalStore( subscribeCurrentUserStore, getCurrentUserSource, getCurrentUserSource ) const profile = useSyncExternalStore(subscribeCurrentUserStore, getCurrentUser, getCurrentUser) if (source === 'external') return null if (source === 'cloudflare-access') return if (profile) return return (

Local user

Couldn’t resolve your user identity. Reload Moi to try again.

) } type AccessUserProps = { profile: UserProfile | undefined } // Behind Cloudflare Access the profile is inherited, so there is nothing to edit. // Access profiles carry no name, so the label is the email, as in workspaces. function AccessUser({ profile }: AccessUserProps) { return (

Cloudflare Access user

{profile ? 'This server uses your Cloudflare Access account. You appear by your email, with a color picked from your Access user ID.' : 'This server uses Cloudflare Access, but this page wasn’t opened through it. Open Moi at its Cloudflare Access address to appear in workspaces.'}

{profile && }
) } type LocalUserEditorProps = { profile: UserProfile } function LocalUserEditor({ profile }: LocalUserEditorProps) { return (

Local user

Change your collaboration color here. Edit your name in Settings.

Color
{USER_COLORS.map(color => ( ))}

Your user is saved in this browser and shared across tabs. The playground below uses its own sample users.

) }