Skip to content

Commit eee5700

Browse files
committed
feat: add suggestions
1 parent 239560d commit eee5700

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/app/(authenticated)/profile/connections/page.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
22
import BlankPageWithMessage from "@/components/BlankPageMessage";
33
import List from "@/components/List";
44
import ConnectionTile from "@/components/user/ConnectionTile";
5+
import { UserTile } from "@/components/user/UserTile";
56
import { UserService } from "@/services/UserService";
67
import { getServerSession } from "next-auth";
78

89
export default async function Connections() {
910
const session = (await getServerSession(authOptions))!;
1011

11-
const connections = await UserService.getConnections(session.cannonToken);
12+
const { connections, suggestions } = (await UserService.getConnections(
13+
session.cannonToken,
14+
)) || { connections: [], suggestions: [] };
1215
if (!connections) {
1316
return <BlankPageWithMessage message="Connections not found!" />;
1417
}
@@ -28,6 +31,16 @@ export default async function Connections() {
2831
</p>
2932
)}
3033
</List>
34+
{!!suggestions.length && (
35+
<List
36+
title="Suggestions"
37+
description="People who are connected with you"
38+
>
39+
{suggestions.map((u) => (
40+
<UserTile key={u.id} user={u} />
41+
))}
42+
</List>
43+
)}
3144
</div>
3245
);
3346
}

src/app/(authenticated)/users/[id]/page.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ export default async function UserProfile({
3939

4040
const achievements = await AchievementService.getAchievements();
4141
const userAchievements = achievements?.filter((a) =>
42-
a.users?.includes(userProfile.id)
42+
a.users?.includes(userProfile.id),
4343
);
4444

45-
const connections = await UserService.getConnections(session.cannonToken);
45+
const { connections } = (await UserService.getConnections(
46+
session.cannonToken,
47+
)) || { connections: [] };
4648
const connection = connections?.find((c) => c.to === userProfile.id);
4749

4850
async function handleNotesUpdate(notes: string) {
@@ -51,7 +53,7 @@ export default async function UserProfile({
5153
await UserService.updateConnection(
5254
session.cannonToken,
5355
userProfile.id,
54-
notes
56+
notes,
5557
);
5658
}
5759

src/services/UserService.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,11 @@ export const UserService = (() => {
281281
return false;
282282
};
283283

284+
type ConnectionsResponse = { connections: Connection[]; suggestions: User[] };
285+
284286
const getConnections = async (
285287
cannonToken: string,
286-
): Promise<Connection[] | null> => {
288+
): Promise<ConnectionsResponse | null> => {
287289
try {
288290
const resp = await fetch(`${usersEndpoint}/me/connections`, {
289291
headers: {
@@ -294,7 +296,7 @@ export const UserService = (() => {
294296
tags: ["updated-connection"],
295297
},
296298
});
297-
if (resp.ok) return (await resp.json()) as Connection[];
299+
if (resp.ok) return (await resp.json()) as ConnectionsResponse;
298300
} catch (err) {
299301
console.error(err);
300302
}

0 commit comments

Comments
 (0)