|
1 | 1 | import { getServerProfileForUser } from '@/services/profile.service'; |
2 | 2 | import { getServerIdFromMessageId } from '@/services/server.service'; |
3 | | -import { ServerUserProfile } from '@/types/dbtypes'; |
| 3 | +import { Role, ServerUser, ServerUserProfile, User } from '@/types/dbtypes'; |
4 | 4 | import { useSupabaseClient } from '@supabase/auth-helpers-react'; |
5 | 5 | import { memo, useEffect, useState } from 'react'; |
6 | 6 | import UserIcon from '../icons/UserIcon'; |
7 | 7 | import { SearchBar } from './Styles'; |
8 | 8 |
|
9 | 9 | // TODO: Once DMs are implemented, this component will need to be updated to handle DMs as well. |
10 | | -function WrappedComponent({ userId, messageId }: { userId: string, messageId: number }) { |
11 | | - const supabase = useSupabaseClient(); |
12 | | - const [user, setUser] = useState<ServerUserProfile | null>(null); |
13 | | - |
14 | | - useEffect(() => { |
15 | | - async function handleAsync() { |
16 | | - const { data: serverId } = await getServerIdFromMessageId(supabase, messageId); |
17 | | - const { data, error } = await getServerProfileForUser(supabase, userId, serverId!); |
18 | | - |
19 | | - if (error) { |
20 | | - console.error(error); |
21 | | - } |
22 | | - |
23 | | - setUser(data); |
24 | | - console.log(data); |
25 | | - } |
26 | | - |
27 | | - handleAsync(); |
28 | | - }, [messageId, userId, supabase]); |
29 | | - |
| 10 | +function WrappedComponent({ profile, server_user, roles }: { profile: User, server_user: ServerUser, roles: Role[] }) { |
30 | 11 | return ( |
31 | 12 | <div className="flex flex-col space-y-2 items-center p-3"> |
32 | | - { user ? ( |
33 | | - <> |
34 | | - <UserIcon user={user} className='!w-9 !h-9'/> |
35 | | - { user.server_user.nickname && <h2 className='text-lg'> |
36 | | - {user.server_user.nickname} |
37 | | - </h2> } |
38 | | - <h2 className={user.server_user.nickname ? 'text-base' : 'text-lg'}>{user.username}</h2> |
39 | | - <hr/> |
40 | | - <h2 className='text-sm text-gray-400 text-left w-full'>Roles</h2> |
41 | | - <div className='flex flex-col w-full items-center space-y-1'> |
42 | | - { user.roles.map(role => ( |
43 | | - <span |
44 | | - key={role.id} |
45 | | - className='text-sm text-gray-400 py-1 px-2 border-2 border-solid w-full rounded-sm' |
46 | | - style={{ |
47 | | - border: `1px solid #${!!role.color ? role.color : 'cacacacc'}`, |
48 | | - color: `#${!!role.color ? role.color : 'cacacacc'}`, |
49 | | - }} |
50 | | - > |
51 | | - {role.name} |
52 | | - </span> |
53 | | - )) } |
54 | | - </div> |
55 | | - <hr/> |
56 | | - <form> |
57 | | - <input |
58 | | - type="text" |
59 | | - className={`${SearchBar}`} |
60 | | - placeholder={`Message @${user.username}`} |
61 | | - /> |
62 | | - </form> |
63 | | - </> |
64 | | - ): <h2>Loading...</h2>} |
65 | | - |
| 13 | + <UserIcon user={profile} className='!w-9 !h-9'/> |
| 14 | + { server_user.nickname && <h2 className='text-lg'> |
| 15 | + {server_user.nickname} |
| 16 | + </h2> } |
| 17 | + <h2 className={server_user.nickname ? 'text-base' : 'text-lg'}>{profile.username}</h2> |
| 18 | + <hr/> |
| 19 | + <h2 className='text-sm text-gray-400 text-left w-full'>Roles</h2> |
| 20 | + <div className='flex flex-col w-full items-center space-y-1'> |
| 21 | + { roles.map(role => ( |
| 22 | + <span |
| 23 | + key={role.id} |
| 24 | + className='text-sm text-gray-400 py-1 px-2 border-2 border-solid w-full rounded-sm' |
| 25 | + style={{ |
| 26 | + border: `1px solid #${!!role.color ? role.color : 'cacacacc'}`, |
| 27 | + color: `#${!!role.color ? role.color : 'cacacacc'}`, |
| 28 | + }} |
| 29 | + > |
| 30 | + {role.name} |
| 31 | + </span> |
| 32 | + )) } |
| 33 | + </div> |
| 34 | + <hr/> |
| 35 | + <form> |
| 36 | + <input |
| 37 | + type="text" |
| 38 | + className={`${SearchBar}`} |
| 39 | + placeholder={`Message @${profile.username}`} |
| 40 | + /> |
| 41 | + </form> |
66 | 42 | </div> |
67 | 43 | ); |
68 | 44 | } |
|
0 commit comments