From 0e62bafa45b4ba908976d1a7c89e9c4a3c01e0b5 Mon Sep 17 00:00:00 2001 From: Gib Date: Fri, 13 Jun 2025 19:19:52 -0500 Subject: [PATCH] Trying to figure out avatar urls. Not easy. --- src/components/status/TechTable.tsx | 51 ++++++++++++++++++++++++-- src/components/ui/avatar.tsx | 56 +++++++++++++++++++++++++++-- src/lib/hooks/status.ts | 19 ++++++++-- 3 files changed, 119 insertions(+), 7 deletions(-) diff --git a/src/components/status/TechTable.tsx b/src/components/status/TechTable.tsx index 00784c9..90966fe 100755 --- a/src/components/status/TechTable.tsx +++ b/src/components/status/TechTable.tsx @@ -5,17 +5,28 @@ import { useState, useEffect, useCallback, useRef } from 'react'; import { useAuth, useTVMode } from '@/components/context'; import { getRecentUsersWithStatuses, + getSignedUrl, updateStatuses, updateUserStatus, type UserWithStatus, } from '@/lib/hooks'; -import { Drawer, DrawerTrigger, Loading } from '@/components/ui'; +import { + Avatar, + AvatarImage, + AvatarFallback, + BasedAvatarImage, + BasedAvatarFallback, + Drawer, + DrawerTrigger, + Loading +} from '@/components/ui'; import { SubmitButton } from '@/components/default'; import { toast } from 'sonner'; import { HistoryDrawer } from '@/components/status'; import type { Profile } from '@/utils/supabase'; import type { RealtimeChannel } from '@supabase/supabase-js'; import { makeConditionalClassName } from '@/lib/utils'; +import { User } from 'lucide-react'; type TechTableProps = { initialStatuses: UserWithStatus[]; @@ -47,6 +58,22 @@ export const TechTable = ({ } }, []); + const fetchAvatarUrl = useCallback(async (url: string) => { + try { + const avatarResponse = await getSignedUrl({ + bucket: 'avatars', + url, + transform: { width: 128, height: 128 }, + }); + if (!avatarResponse.success) { + throw new Error(avatarResponse.error); + } + return avatarResponse.data; + } catch (error) { + console.error('Error fetching avatar URL:', error); + } + }, []); + // Initial load useEffect(() => { const loadData = async () => { @@ -225,7 +252,7 @@ export const TechTable = ({ /> )} - Name + Technician )} - {userWithStatus.user.full_name ?? 'Unknown User'} +
+ + {userWithStatus.user.avatar_url ? ( + + ): ( + + )} + +

{userWithStatus.user.full_name ?? 'Unknown User'}

+

{userWithStatus.avatar_url}

+
diff --git a/src/components/ui/avatar.tsx b/src/components/ui/avatar.tsx index 52e6be0..d1ba2c9 100644 --- a/src/components/ui/avatar.tsx +++ b/src/components/ui/avatar.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import * as AvatarPrimitive from '@radix-ui/react-avatar'; +import { User } from 'lucide-react'; import { cn } from '@/lib/utils'; @@ -21,6 +22,25 @@ function Avatar({ ); } +type BasedAvatarImageProps = React.ComponentProps & { + fullName: string; +}; + +function BasedAvatarImage({ + fullName, + className, + ...props +}: BasedAvatarImageProps) { + return ( + n[0]).join('').toUpperCase()} + {...props} + /> + ); +} + function AvatarImage({ className, ...props @@ -34,10 +54,42 @@ function AvatarImage({ ); } +type BasedAvatarFallbackProps = +React.ComponentProps & { + fullName?: string | null; +}; + +function BasedAvatarFallback({ + fullName = null, + className, + ...props +}: BasedAvatarFallbackProps) { + return ( + + {fullName ? ( + fullName + .split(' ') + .map((n) => n[0]) + .join('') + .toUpperCase() + ) : ( + + )} + + ); +} + function AvatarFallback({ className, ...props -}: React.ComponentProps) { +}: React.ComponentProps) { return (