Skip to content

Commit 57ef73a

Browse files
committed
chore: ability to view profile logged out
1 parent 52a7aa3 commit 57ef73a

File tree

6 files changed

+45
-30
lines changed

6 files changed

+45
-30
lines changed

apps/web/src/app/(profile)/profile/[handle]/(user)/(characters)/characters/CharacterView.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,21 @@ export default function CharacterView({
5353
nestedItem
5454
/>
5555
))}
56-
<FolderView.Item
57-
newItem
58-
nestedItem
59-
onClick={() => {
60-
setParentFolderId(folder.id)
61-
toggleCreateFolderModal()
62-
}}
63-
/>
56+
{owner && (
57+
<FolderView.Item
58+
newItem
59+
nestedItem
60+
onClick={() => {
61+
setParentFolderId(folder.id)
62+
toggleCreateFolderModal()
63+
}}
64+
/>
65+
)}
6466
</FolderView.Item>
6567
))}
66-
<FolderView.Item newItem onClick={toggleCreateFolderModal} />
68+
{owner && (
69+
<FolderView.Item newItem onClick={toggleCreateFolderModal} />
70+
)}
6771
</FolderView.Shelf>
6872
<FolderView.Contents>
6973
<div className="mb-4 flex w-full gap-x-2.5">

apps/web/src/app/(profile)/profile/[handle]/(user)/(characters)/characters/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ export default async function Page({ params }: AsyncProps) {
2222
const { handle } = await params
2323
const characters = await fetchUserCharacters(handle)
2424
const { folders, id } = await fetchUser(handle)
25-
const self = await fetchUserData()
25+
const self = await fetchUserData().catch(() => {})
2626
return (
2727
<MarginClamp>
2828
<CharacterView
2929
handle={handle}
3030
characters={characters}
3131
folders={folders}
32-
owner={self.id === id}
32+
owner={self ? self.id === id : false}
3333
/>
3434
</MarginClamp>
3535
)

apps/web/src/app/(profile)/profile/[handle]/(user)/(overview)/OverviewContent.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import Image from "next/image"
24
import React from "react"
35
import { Button } from "@mav/ui/components/buttons"
@@ -7,13 +9,14 @@ import { sanitize } from "isomorphic-dompurify"
79
import type { DashboardPanel, UserType } from "@/types/users"
810
import CommentPanel from "./panels/Comments/CommentPanel"
911
import InformationPanel from "./panels/InformationPanel"
12+
import { useAuth, type User } from "@/app/context/AuthContext"
1013

11-
function renderPanel(panel: DashboardPanel, userData: UserType) {
14+
function renderPanel(panel: DashboardPanel, userData: UserType, self?: User | null) {
1215
switch (panel.type) {
1316
case "customHTML":
1417
return null
1518
case "comments":
16-
return <CommentPanel comments={userData.comments} user={userData} />
19+
return <CommentPanel comments={userData.comments} user={userData} self={self} />
1720
case "information":
1821
return <InformationPanel user={userData} />
1922
default:
@@ -30,6 +33,7 @@ export default function OverviewContent({
3033
panels: DashboardPanel[]
3134
userData: UserType
3235
}) {
36+
const { user: self } = useAuth()
3337
const customHTMLPanel = panels.find((panel) => panel.type === "customHTML")
3438
const htmlContent = customHTMLPanel?.settings?.html
3539
? sanitize(customHTMLPanel.settings.html)
@@ -57,7 +61,7 @@ export default function OverviewContent({
5761
.filter((panel) => panel.position.row === 2)
5862
.map((panel, index) => (
5963
<div key={index} className="p-4">
60-
{renderPanel(panel, userData)}
64+
{renderPanel(panel, userData, self)}
6165
</div>
6266
))}
6367
</div>
@@ -66,7 +70,7 @@ export default function OverviewContent({
6670
.filter((panel) => panel.position.row === 3)
6771
.map((panel, index) => (
6872
<div key={index} className="p-4">
69-
{renderPanel(panel, userData)}
73+
{renderPanel(panel, userData, self)}
7074
</div>
7175
))}
7276
</div>

apps/web/src/app/(profile)/profile/[handle]/(user)/(overview)/panels/Comments/CommentPanel.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,33 @@ import { UserComment, UserCommentInput } from "@mav/ui/components/comments"
99
import { Group } from "@mav/ui/components/layouts"
1010
import type { Comments, UserType } from "@/types/users"
1111
import CommentThread from "./Thread"
12+
import { type User } from "@/app/context/AuthContext"
13+
1214

1315
export default function CommentPanel({
1416
comments,
15-
user
17+
user,
18+
self
1619
}: {
1720
comments: Comments[]
18-
user: UserType
21+
user: UserType,
22+
self: User
1923
}) {
2024
return (
2125
<Group title="Comments" potentialActions={<Button>Filter</Button>}>
22-
<div className="my-5">
23-
<UserCommentInput
24-
postComment={postComment}
25-
imgTag={<img />}
26-
avatar={user?.avatarUrl || USER_DEFAULT_AVATAR}
27-
commentType="user"
28-
redirectRoute={`/@${user.handle}`}
29-
username={user.handle}
30-
/>
31-
</div>
26+
{self && (
27+
<div className="my-5">
28+
<UserCommentInput
29+
postComment={postComment}
30+
imgTag={<img />}
31+
avatar={user?.avatarUrl || USER_DEFAULT_AVATAR}
32+
commentType="user"
33+
redirectRoute={`/@${user.handle}`}
34+
username={user.handle}
35+
/>
36+
</div>
37+
)}
38+
3239

3340
<div className="grid gap-y-4">
3441
{comments.map((comment) => (

apps/web/src/app/(profile)/profile/[handle]/(user)/layout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export default async function MainProfileLayout(
1010
) {
1111
const { handle } = await props.params
1212

13-
const self = await fetchUserData()
14-
const user = handle === self.handle ? self : await fetchUser(handle)
13+
const self = await fetchUserData().catch(() => {})
14+
const user = await fetchUser(handle)
1515

1616
return (
1717
<AppLayout>
@@ -23,6 +23,7 @@ export default async function MainProfileLayout(
2323
followingCount={user.following.length}
2424
profileBio={user?.bio || ""}
2525
bannerUrl={user?.bannerUrl || undefined}
26+
isOwnProfile={self ? self.handle === user.handle : false}
2627
/>
2728
{props.children}
2829
</AppLayout>

apps/web/src/utils/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,5 @@ export const postComment = async (
296296
if (!data) throw new Error("Unable to post comment");
297297

298298
return redirect(redirectRoute);
299-
300299
};
301300

0 commit comments

Comments
 (0)