Skip to content

Commit a1f12cd

Browse files
committed
refactor: Modularize ViewProfile component with rendering helpers and type handling
1 parent a0dbc4d commit a1f12cd

File tree

1 file changed

+35
-38
lines changed

1 file changed

+35
-38
lines changed

apps/web/src/components/Account/index.tsx

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ const ViewProfile: NextPage = () => {
4141
AccountFeedType.Collects.toLowerCase()
4242
];
4343

44-
const feedType = type
45-
? lowerCaseAccountFeedType.includes(type as string)
46-
? type.toString().toUpperCase()
47-
: AccountFeedType.Feed
48-
: AccountFeedType.Feed;
44+
const getFeedType = (type: string | undefined) => {
45+
return type && lowerCaseAccountFeedType.includes(type.toLowerCase())
46+
? type.toUpperCase()
47+
: AccountFeedType.Feed;
48+
};
49+
50+
const feedType = getFeedType(Array.isArray(type) ? type[0] : type);
4951

5052
const { data, error, loading } = useAccountQuery({
5153
skip: address ? !address : !username,
@@ -81,14 +83,30 @@ const ViewProfile: NextPage = () => {
8183
const isSuspended = isStaff ? false : accountDetails?.isSuspended;
8284
const isDeleted = isAccountDeleted(account);
8385

86+
const renderAccountDetails = () => {
87+
if (isDeleted) return <DeletedDetails account={account} />;
88+
if (isSuspended) return <SuspendedDetails account={account} />;
89+
return (
90+
<Details
91+
isSuspended={accountDetails?.isSuspended || false}
92+
account={account}
93+
/>
94+
);
95+
};
96+
97+
const renderEmptyState = () => (
98+
<EmptyState
99+
icon={<NoSymbolIcon className="size-8" />}
100+
message={isDeleted ? "Account Deleted" : "Account Suspended"}
101+
/>
102+
);
103+
84104
return (
85105
<>
86106
<MetaTags
87107
creator={getAccount(account).name}
88108
description={account.metadata?.bio || ""}
89-
title={`${getAccount(account).name} (${
90-
getAccount(account).usernameWithPrefix
91-
}) • ${APP_NAME}`}
109+
title={`${getAccount(account).name} (${getAccount(account).usernameWithPrefix}) • ${APP_NAME}`}
92110
/>
93111
<Cover
94112
cover={
@@ -99,46 +117,25 @@ const ViewProfile: NextPage = () => {
99117
}
100118
/>
101119
<GridLayout>
102-
<GridItemFour>
103-
{isDeleted ? (
104-
<DeletedDetails account={account} />
105-
) : isSuspended ? (
106-
<SuspendedDetails account={account} />
107-
) : (
108-
<Details
109-
isSuspended={accountDetails?.isSuspended || false}
110-
account={account}
111-
/>
112-
)}
113-
</GridItemFour>
120+
<GridItemFour>{renderAccountDetails()}</GridItemFour>
114121
<GridItemEight className="space-y-5">
115-
{isDeleted ? (
116-
<EmptyState
117-
icon={<NoSymbolIcon className="size-8" />}
118-
message="Account Deleted"
119-
/>
120-
) : isSuspended ? (
121-
<EmptyState
122-
icon={<NoSymbolIcon className="size-8" />}
123-
message="Account Suspended"
124-
/>
122+
{isDeleted || isSuspended ? (
123+
renderEmptyState()
125124
) : (
126125
<>
127126
<FeedType feedType={feedType as AccountFeedType} />
128-
{currentAccount?.address === account?.address ? (
129-
<NewPost />
130-
) : null}
131-
{feedType === AccountFeedType.Feed ||
132-
feedType === AccountFeedType.Replies ||
133-
feedType === AccountFeedType.Media ||
134-
feedType === AccountFeedType.Collects ? (
127+
{currentAccount?.address === account?.address && <NewPost />}
128+
{(feedType === AccountFeedType.Feed ||
129+
feedType === AccountFeedType.Replies ||
130+
feedType === AccountFeedType.Media ||
131+
feedType === AccountFeedType.Collects) && (
135132
<AccountFeed
136133
handle={getAccount(account).usernameWithPrefix}
137134
accountDetailsLoading={accountDetailsLoading}
138135
address={account.address}
139136
type={feedType}
140137
/>
141-
) : null}
138+
)}
142139
</>
143140
)}
144141
</GridItemEight>

0 commit comments

Comments
 (0)