Skip to content

Commit 2458ad7

Browse files
committed
feat: enhance profile page with additional user information and improved article loading states
- Expanded user profile data retrieval to include bio, designation, website URL, education, location, social links, skills, and verification status. - Updated ProfilePageAside component to display user skills. - Improved article loading experience in UserArticleFeed with error handling and empty state messaging. - Added Bengali translations for new article-related messages to enhance localization.
1 parent 524ebc4 commit 2458ad7

5 files changed

Lines changed: 59 additions & 9 deletions

File tree

src/app/[username]/(profile-page)/_components/ProfilePageAside.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ const ProfilePageAside: React.FC<ProfilePageAsideProps> = ({ profile }) => {
4343
<p className="my-2 text-sm text-muted-foreground">{profile?.bio}</p>
4444
)}
4545

46+
{profile?.skills && (
47+
<p className="my-2 text-sm">
48+
<span className="font-medium text-foreground">Skills: </span>
49+
<span className="text-muted-foreground">{profile.skills}</span>
50+
</p>
51+
)}
52+
4653
{/* User infos start */}
4754
<div className="flex flex-col mt-4 gap-2 md:gap-4">
4855
{profile?.website_url && (

src/app/[username]/(profile-page)/articles/UserArticleFeed.tsx

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
"use client";
22

3-
import { useInfiniteQuery, useQuery } from "@tanstack/react-query";
3+
import { useInfiniteQuery } from "@tanstack/react-query";
44
import * as articleActions from "@/backend/services/article.actions";
55
import React, { useMemo } from "react";
66
import ArticleCard from "@/components/ArticleCard";
77
import { readingTime } from "@/lib/utils";
88
import VisibilitySensor from "@/components/VisibilitySensor";
99
import getFileUrl from "@/utils/getFileUrl";
10+
import { useTranslation } from "@/i18n/use-translation";
11+
import Image from "next/image";
1012

1113
interface UserArticleFeedProps {
1214
userId: string;
1315
}
1416

1517
const UserArticleFeed: React.FC<UserArticleFeedProps> = ({ userId }) => {
18+
const { _t } = useTranslation();
19+
1620
const feedInfiniteQuery = useInfiniteQuery({
1721
queryKey: ["user-article-feed", userId],
1822
queryFn: ({ pageParam }) =>
@@ -42,22 +46,49 @@ const UserArticleFeed: React.FC<UserArticleFeedProps> = ({ userId }) => {
4246
});
4347

4448
const feedArticles = useMemo(() => {
45-
return feedInfiniteQuery.data?.pages.flatMap((page) => page?.nodes);
49+
return feedInfiniteQuery.data?.pages.flatMap((page) => page?.nodes) ?? [];
4650
}, [feedInfiniteQuery.data]);
4751

52+
const showEmpty =
53+
!feedInfiniteQuery.isPending &&
54+
!feedInfiniteQuery.isError &&
55+
feedArticles.length === 0;
56+
4857
return (
4958
<>
50-
{feedInfiniteQuery.isFetching && (
59+
{feedInfiniteQuery.isPending && (
5160
<div className="flex flex-col gap-10 pt-4">
5261
{Array.from({ length: 6 }).map((_, index) => (
5362
<div key={index} className="h-56 bg-muted animate-pulse mx-4" />
5463
))}
5564
</div>
5665
)}
5766

58-
{/* <pre>{JSON.stringify(feedArticles, null, 2)}</pre> */}
67+
{feedInfiniteQuery.isError && (
68+
<div className="py-10 px-4 text-center text-sm text-muted-foreground">
69+
{_t("Could not load articles.")}
70+
</div>
71+
)}
72+
73+
{showEmpty && (
74+
<div className="py-10 flex flex-col items-center justify-center gap-4 px-4">
75+
<Image
76+
src="/images/robots-drones-artificial-intelligence-1.png"
77+
alt=""
78+
width={220}
79+
height={220}
80+
className="mx-auto opacity-90"
81+
/>
82+
<h2 className="text-xl font-semibold text-center">
83+
{_t("No articles published yet")}
84+
</h2>
85+
<p className="text-sm text-muted-foreground text-center max-w-md">
86+
{_t("When this user publishes articles, they will show up here.")}
87+
</p>
88+
</div>
89+
)}
5990

60-
{feedArticles?.map((article) => (
91+
{feedArticles.map((article) => (
6192
<ArticleCard
6293
key={article?.id}
6394
id={article?.id ?? ""}

src/app/[username]/(profile-page)/articles/page.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ const Page: React.FC<PageProps> = async ({ params }) => {
1111
const username = sanitizedUsername(_params?.username);
1212
const profile = await getUserByUsername(username, ["id", "username"]);
1313

14+
if (!profile?.id) {
15+
return null;
16+
}
17+
1418
return (
1519
<main className="border rounded-bl-2xl rounded-br-2xl md:col-span-9 col-span-full mt-3">
16-
{/* <pre>{JSON.stringify(profile, null, 2)}</pre> */}
17-
<UserArticleFeed userId={profile?.id!} />
20+
<UserArticleFeed userId={profile.id} />
1821
</main>
1922
);
2023
};

src/app/[username]/(profile-page)/layout.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,21 @@ const layout: React.FC<ProfilePageLayoutProps> = async ({
4747
const _params = await params;
4848
const username = sanitizedUsername(_params?.username);
4949
const profile = await getUserByUsername(username, [
50-
// all fields
5150
"id",
5251
"name",
5352
"username",
5453
"email",
5554
"profile_photo",
55+
"bio",
56+
"designation",
57+
"website_url",
58+
"education",
59+
"location",
60+
"social_links",
61+
"skills",
62+
"is_verified",
5663
"created_at",
5764
"updated_at",
58-
"social_links",
5965
]);
6066

6167
if (!profile) {

src/i18n/bn.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@
110110
"Profile not found": "প্রোফাইল খুঁজে পাওয়া যায়নি",
111111
"The user you are looking for does not exist": "আপনি সেই ব্যবহারকারীর জন্য খুঁজে পাওয়া যায়নি",
112112
"No profile readme found": "কোনো প্রোফাইল readme পাওয়া যায়নি",
113+
"No articles published yet": "এখনো কোনো প্রকাশিত লেখা নেই",
114+
"When this user publishes articles, they will show up here.": "এই ব্যবহারকারী লেখা প্রকাশ করলে সেগুলো এখানে দেখা যাবে।",
115+
"Could not load articles.": "লেখাগুলো লোড করা যায়নি।",
113116
"Login Sessions": "লগইন সেশন সমূহ",
114117
"These are the login sessions of your account. You can use this to revoke access to your account": "এটি আপনার একাউন্ট এর লগইন সেশন তালিকা। আপনি অন্য ডিভাইস থেকে লগাউট করে দিতে পারবেন",
115118
"You are not logged in": "আপনি লগইন করেননি",

0 commit comments

Comments
 (0)