Skip to content

Commit

Permalink
feat: add suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nalves599 committed Feb 20, 2025
1 parent 239560d commit eee5700
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
15 changes: 14 additions & 1 deletion src/app/(authenticated)/profile/connections/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import authOptions from "@/app/api/auth/[...nextauth]/authOptions";
import BlankPageWithMessage from "@/components/BlankPageMessage";
import List from "@/components/List";
import ConnectionTile from "@/components/user/ConnectionTile";
import { UserTile } from "@/components/user/UserTile";
import { UserService } from "@/services/UserService";
import { getServerSession } from "next-auth";

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

const connections = await UserService.getConnections(session.cannonToken);
const { connections, suggestions } = (await UserService.getConnections(
session.cannonToken,
)) || { connections: [], suggestions: [] };
if (!connections) {
return <BlankPageWithMessage message="Connections not found!" />;
}
Expand All @@ -28,6 +31,16 @@ export default async function Connections() {
</p>
)}
</List>
{!!suggestions.length && (
<List
title="Suggestions"
description="People who are connected with you"
>
{suggestions.map((u) => (
<UserTile key={u.id} user={u} />
))}
</List>
)}
</div>
);
}
8 changes: 5 additions & 3 deletions src/app/(authenticated)/users/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export default async function UserProfile({

const achievements = await AchievementService.getAchievements();
const userAchievements = achievements?.filter((a) =>
a.users?.includes(userProfile.id)
a.users?.includes(userProfile.id),
);

const connections = await UserService.getConnections(session.cannonToken);
const { connections } = (await UserService.getConnections(
session.cannonToken,
)) || { connections: [] };
const connection = connections?.find((c) => c.to === userProfile.id);

async function handleNotesUpdate(notes: string) {
Expand All @@ -51,7 +53,7 @@ export default async function UserProfile({
await UserService.updateConnection(
session.cannonToken,
userProfile.id,
notes
notes,
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ export const UserService = (() => {
return false;
};

type ConnectionsResponse = { connections: Connection[]; suggestions: User[] };

const getConnections = async (
cannonToken: string,
): Promise<Connection[] | null> => {
): Promise<ConnectionsResponse | null> => {
try {
const resp = await fetch(`${usersEndpoint}/me/connections`, {
headers: {
Expand All @@ -294,7 +296,7 @@ export const UserService = (() => {
tags: ["updated-connection"],
},
});
if (resp.ok) return (await resp.json()) as Connection[];
if (resp.ok) return (await resp.json()) as ConnectionsResponse;
} catch (err) {
console.error(err);
}
Expand Down

0 comments on commit eee5700

Please sign in to comment.