From f24143964f88432832dd605fa45cfcb35ccff8a4 Mon Sep 17 00:00:00 2001 From: Julien Oculi Date: Tue, 16 Jul 2024 16:15:54 +0200 Subject: [PATCH] feat(route): :sparkles: display profile page instead of "carnet" in member page --- routes/carnet/[id].tsx | 27 +++++++++++++++++++++++++++ routes/membres/[id]/index.tsx | 11 +++++++++-- routes/profil/index.tsx | 4 +++- src/members/mod.ts | 18 +++++++++++++++++- 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 routes/carnet/[id].tsx diff --git a/routes/carnet/[id].tsx b/routes/carnet/[id].tsx new file mode 100644 index 0000000..2f1b27d --- /dev/null +++ b/routes/carnet/[id].tsx @@ -0,0 +1,27 @@ +import { PageProps } from '$fresh/server.ts' +import { Markdown } from ':components/Markdown.tsx' +import { db } from ':src/db/mod.ts' +import { fetchCarnet } from ':src/members/mod.ts' + +export default async function Member(_: Request, { params }: PageProps) { + const uuid = params.id as ReturnType + const user = await db.resource.user.get({ uuid }).catch(() => undefined) + + if (!user) { + return

Membre inconnu, peut ĂȘtre serez vous le prochain

+ } + + const carnet = await fetchCarnet(user.login) + + return ( + + {carnet} + + ) +} diff --git a/routes/membres/[id]/index.tsx b/routes/membres/[id]/index.tsx index b9996a0..4ab9c33 100644 --- a/routes/membres/[id]/index.tsx +++ b/routes/membres/[id]/index.tsx @@ -2,7 +2,7 @@ import { PageProps } from '$fresh/server.ts' import { Markdown } from ':components/Markdown.tsx' import { MemberCard } from ':components/MemberCard.tsx' import { db } from ':src/db/mod.ts' -import { fetchCarnet, userToMemberCardProps } from ':src/members/mod.ts' +import { fetchProfile, userToMemberCardProps } from ':src/members/mod.ts' export default async function Member(_: Request, { params, url }: PageProps) { const uuid = params.id as ReturnType @@ -13,7 +13,7 @@ export default async function Member(_: Request, { params, url }: PageProps) { } const memberCardProps = await userToMemberCardProps(user) - const carnet = await fetchCarnet(user.login) + const carnet = await fetchProfile(user.login) return (
Portfolio +
+ + Carnet de bord +
- +
) diff --git a/src/members/mod.ts b/src/members/mod.ts index a587507..403fd58 100644 --- a/src/members/mod.ts +++ b/src/members/mod.ts @@ -3,6 +3,22 @@ import { db } from ':src/db/mod.ts' import { Db } from '@cohabit/resources-manager/db' import { Ref, User } from '@cohabit/resources-manager/models' +export async function fetchProfile(login: string): Promise { + try { + const response = await fetch( + `https://git.cohabit.fr/${login}/.profile/raw/branch/main/README.md`, + ) + + if (!response.ok) { + throw new Error(`[${response.status}] "${response.statusText}"`) + } + + return response.text() + } catch (error) { + return `# Profil introuvable\n\`\`\`js\n${String(error)}\n\`\`\`` + } +} + export async function fetchCarnet(login: string): Promise { try { const response = await fetch( @@ -38,7 +54,7 @@ export async function userToMemberCardProps(user: User) { export function dbToMemberCardProps( db: Db, ): AsyncIterableIterator { - const memberList = db.ressource.user + const memberList = db.resource.user .list() .map(userToMemberCardProps)