Files
cinny/src/app/components/presence/PresenceRingAvatar.tsx
T

37 lines
995 B
TypeScript
Raw Normal View History

import React, { ReactNode } from 'react';
import { color } from 'folds';
import { Presence, useUserPresence } from '../../hooks/useUserPresence';
function presenceRingColor(presence: Presence | undefined, status?: string): string | null {
if (!presence || presence === Presence.Offline) return null;
if (presence === Presence.Unavailable) {
return status === 'dnd' ? color.Critical.Main : color.Warning.Main;
}
return color.Success.Main;
}
type PresenceRingAvatarProps = {
userId: string;
children: ReactNode;
};
export function PresenceRingAvatar({ userId, children }: PresenceRingAvatarProps) {
const presence = useUserPresence(userId);
const ringColor = presenceRingColor(presence?.presence, presence?.status);
if (!ringColor) return <>{children}</>;
return (
<div
style={{
display: 'inline-flex',
borderRadius: '50%',
boxShadow: `0 0 0 2px ${ringColor}`,
flexShrink: 0,
}}
>
{children}
</div>
);
}