Skip to content

Commit d45d070

Browse files
Fixes broken profile page (#1111)
1 parent 126ddf5 commit d45d070

File tree

3 files changed

+13
-40
lines changed

3 files changed

+13
-40
lines changed

app/(app)/[username]/_usernameClient.tsx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LinkIcon } from "@heroicons/react/20/solid";
88
import { api } from "@/server/trpc/react";
99
import { useRouter, useSearchParams } from "next/navigation";
1010
import type { Session } from "next-auth";
11-
import { Tabs } from "@/components/Tabs";
11+
import { Heading } from "@/components/ui-components/heading";
1212
import { toast } from "sonner";
1313

1414
type Props = {
@@ -71,20 +71,8 @@ const Profile = ({ profile, isOwner, session }: Props) => {
7171
}
7272
};
7373

74-
const selectedTab =
75-
tabFromParams && ["groups", "articles"].includes(tabFromParams)
76-
? tabFromParams
77-
: "articles";
78-
79-
const [ARTICLES] = ["articles"];
80-
const tabs = [
81-
{
82-
name: `Articles (${posts.length})`,
83-
value: ARTICLES,
84-
href: `?tab=${ARTICLES}`,
85-
current: selectedTab === ARTICLES,
86-
},
87-
];
74+
const ARTICLES = "articles";
75+
const selectedTab = tabFromParams === ARTICLES ? ARTICLES : ARTICLES;
8876

8977
return (
9078
<>
@@ -121,11 +109,11 @@ const Profile = ({ profile, isOwner, session }: Props) => {
121109
</main>
122110
{accountLocked ? (
123111
<div className="mt-8 flex items-center justify-between border-b pb-4 text-3xl font-extrabold tracking-tight text-neutral-900 dark:text-neutral-50 sm:text-4xl">
124-
<h1>Account locked 🔒</h1>
112+
<Heading level={1}>Account locked 🔒</Heading>
125113
</div>
126114
) : (
127-
<div className="mx-auto mt-4 dark:bg-neutral-900 sm:max-w-2xl lg:max-w-5xl">
128-
<Tabs tabs={tabs} />
115+
<div className="mx-auto mt-4 sm:max-w-2xl lg:max-w-5xl">
116+
<Heading level={1}>{`Articles (${posts.length})`}</Heading>
129117
</div>
130118
)}
131119
{(() => {
@@ -179,10 +167,6 @@ const Profile = ({ profile, isOwner, session }: Props) => {
179167
)}
180168
</div>
181169
);
182-
case GROUPS:
183-
return (
184-
<p className="py-4 font-medium">Groups are coming soon!</p>
185-
);
186170
default:
187171
return null;
188172
}

app/(app)/[username]/page.tsx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ export default async function Page({
8080
),
8181
orderBy: (posts, { desc }) => [desc(posts.published)],
8282
},
83-
BannedUsers: {
84-
columns: {
85-
id: true,
86-
},
87-
},
8883
},
8984
where: (users, { eq }) => eq(users.username, username),
9085
});
@@ -93,22 +88,16 @@ export default async function Page({
9388
notFound();
9489
}
9590

96-
const accountLocked = !!profile.BannedUsers;
91+
const bannedUser = await db.query.banned_users.findFirst({
92+
where: (bannedUsers, { eq }) => eq(bannedUsers.userId, profile.id),
93+
});
94+
95+
const accountLocked = !!bannedUser;
9796
const session = await getServerAuthSession();
9897
const isOwner = session?.user?.id === profile.id;
9998

100-
type MakeOptional<Type, Key extends keyof Type> = Omit<Type, Key> &
101-
Partial<Type>;
102-
103-
type Profile = typeof profile;
104-
const cleanedProfile: MakeOptional<Profile, "BannedUsers"> = {
105-
...profile,
106-
};
107-
108-
delete cleanedProfile.BannedUsers;
109-
11099
const shapedProfile = {
111-
...cleanedProfile,
100+
...profile,
112101
posts: accountLocked
113102
? []
114103
: profile.posts.map((post) => ({

components/Tabs/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function Tabs(props: Props) {
2929
<select
3030
id="tabs"
3131
name="tabs"
32-
className="block w-full rounded-md border-neutral-300 bg-white focus:border-neutral-500 focus:ring-neutral-500 dark:bg-neutral-900"
32+
className="block w-full rounded-md border-neutral-300 bg-white focus:border-neutral-500 focus:ring-neutral-500 dark:bg-neutral-950"
3333
defaultValue={tabs.find((tab) => tab.current)?.name || tabs[0].name}
3434
onChange={(e) => {
3535
router.push(e.target.value);

0 commit comments

Comments
 (0)