Skip to content

Commit 9fff854

Browse files
committed
mini profiles are free now
1 parent 00ca546 commit 9fff854

4 files changed

Lines changed: 38 additions & 61 deletions

File tree

components/forms/MiniProfile.tsx

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,44 @@
11
import { getServerProfileForUser } from '@/services/profile.service';
22
import { getServerIdFromMessageId } from '@/services/server.service';
3-
import { ServerUserProfile } from '@/types/dbtypes';
3+
import { Role, ServerUser, ServerUserProfile, User } from '@/types/dbtypes';
44
import { useSupabaseClient } from '@supabase/auth-helpers-react';
55
import { memo, useEffect, useState } from 'react';
66
import UserIcon from '../icons/UserIcon';
77
import { SearchBar } from './Styles';
88

99
// 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[] }) {
3011
return (
3112
<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>
6642
</div>
6743
);
6844
}

components/home/Chat.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useOnlinePresenceRef } from '@/context/ChatCtx';
21
import ChannelMessageIcon from '../icons/ChannelMessageIcon';
32
import { useRef, useEffect } from 'react';
43
import styles from '@/styles/Chat.module.css';

components/home/Message.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { editMessage } from '@/services/message.service';
88
import { useSupabaseClient, useUser } from '@supabase/auth-helpers-react';
99
import MessageContent from './MessageContent';
1010
import DeleteMsgModal from '@/components/home/DeleteMsgModal';
11-
import { MiniProfile } from '../forms/MiniProfile';
1211
import { MessageWithServerProfile } from '@/types/dbtypes';
1312
import { MessageHeader } from './MessageHeader';
1413

@@ -73,6 +72,7 @@ export default function Message({
7372
<MessageHeader
7473
profile={message.profile}
7574
server_user={message.author}
75+
roles={message.roles}
7676
message_id={message.id}
7777
message_color={messageColor}
7878
display_time={displayTime}

components/home/MessageHeader.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ServerUser, User } from '@/types/dbtypes';
1+
import { Role, ServerUser, User } from '@/types/dbtypes';
22
import { Tooltip } from 'react-tooltip';
33
import { MiniProfile } from '../forms/MiniProfile';
44
import UserIcon from '../icons/UserIcon';
@@ -9,19 +9,21 @@ export function MessageHeader({
99
message_id,
1010
message_color,
1111
display_time,
12-
edited
12+
edited,
13+
roles
1314
}: {
1415
profile: User,
1516
server_user: ServerUser,
1617
message_id: number,
1718
message_color: string,
1819
display_time: string,
19-
edited: boolean
20+
edited: boolean,
21+
roles: Role[],
2022
}) {
2123
return (
2224
<div className="flex-grow flex flex-row">
2325
<Tooltip id={profile.id} className='z-20 !w-12' clickable noArrow>
24-
<MiniProfile userId={profile.id} messageId={message_id} />
26+
<MiniProfile profile={profile} server_user={server_user} roles={roles} />
2527
</Tooltip>
2628
<UserIcon user={profile} />
2729
<div className="flex-grow flex items-center">

0 commit comments

Comments
 (0)