-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathMainSection.tsx
More file actions
203 lines (194 loc) · 6.1 KB
/
MainSection.tsx
File metadata and controls
203 lines (194 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import type { ReactElement } from 'react';
import React, { useMemo } from 'react';
import { Section } from '../Section';
import type { SidebarMenuItem } from '../common';
import { ListIcon } from '../common';
import {
DevPlusIcon,
EyeIcon,
HomeIcon,
HotIcon,
JoystickIcon,
SquadIcon,
TerminalIcon,
YearInReviewIcon,
} from '../../icons';
import { useAuthContext } from '../../../contexts/AuthContext';
import { ProfileImageSize, ProfilePicture } from '../../ProfilePicture';
import { OtherFeedPage } from '../../../lib/query';
import type { SidebarSectionProps } from './common';
import { plusUrl, webappUrl } from '../../../lib/constants';
import useCustomDefaultFeed from '../../../hooks/feed/useCustomDefaultFeed';
import { SharedFeedPage } from '../../utilities';
import { isExtension } from '../../../lib/func';
import { useConditionalFeature } from '../../../hooks';
import {
featurePlusCtaCopy,
featureYearInReview,
questsFeature,
} from '../../../lib/featureManagement';
import { useQuestDashboard } from '../../../hooks/useQuestDashboard';
import { Typography, TypographyColor } from '../../typography/Typography';
export const MainSection = ({
isItemsButton,
onNavTabClick,
...defaultRenderSectionProps
}: SidebarSectionProps): ReactElement => {
const { user, isLoggedIn } = useAuthContext();
const { isCustomDefaultFeed } = useCustomDefaultFeed();
const isPlus = user?.isPlus;
const { value: ctaCopy } = useConditionalFeature({
feature: featurePlusCtaCopy,
shouldEvaluate: !isPlus,
});
const { value: showYearInReview } = useConditionalFeature({
feature: featureYearInReview,
shouldEvaluate: isLoggedIn,
});
const { value: showGameCenter } = useConditionalFeature({
feature: questsFeature,
shouldEvaluate: isLoggedIn,
});
const { data: questDashboard } = useQuestDashboard();
const claimableMilestoneCount = useMemo(
() =>
questDashboard?.milestone?.filter((quest) => quest.claimable).length ?? 0,
[questDashboard?.milestone],
);
const menuItems: SidebarMenuItem[] = useMemo(() => {
// this path can be opened on extension so it purposly
// is not using webappUrl so it gets selected
let myFeedPath = isCustomDefaultFeed ? '/my-feed' : '/';
if (isExtension) {
myFeedPath = '/my-feed';
}
const myFeed = isLoggedIn
? {
title: 'For You',
path: myFeedPath,
action: () =>
onNavTabClick?.(isCustomDefaultFeed ? SharedFeedPage.MyFeed : '/'),
icon: () => (
<ProfilePicture size={ProfileImageSize.XSmall} user={user!} />
),
}
: {
title: 'Home',
path: '/',
action: () => onNavTabClick?.('/'),
icon: (active: boolean) => (
<ListIcon Icon={() => <HomeIcon secondary={active} />} />
),
};
const plusButton = !isPlus
? {
icon: (active: boolean) => (
<ListIcon Icon={() => <DevPlusIcon secondary={active} />} />
),
title: ctaCopy.full,
path: plusUrl,
isForcedLink: true,
requiresLogin: true,
color: 'text-accent-avocado-default',
itemClassName:
'bg-action-upvote-float/50 hover:bg-action-upvote-float',
disableDefaultBackground: true,
}
: undefined;
const gameCenter = showGameCenter
? {
icon: (active: boolean) => (
<ListIcon Icon={() => <JoystickIcon secondary={active} />} />
),
title: 'Game Center',
path: `${webappUrl}game-center`,
isForcedLink: true,
requiresLogin: true,
...(claimableMilestoneCount > 0 && {
rightIcon: () => (
<Typography
color={TypographyColor.Secondary}
bold
className="rounded-6 bg-background-subtle px-1.5"
>
{claimableMilestoneCount}
</Typography>
),
}),
}
: undefined;
const yearInReview = showYearInReview
? {
icon: () => <ListIcon Icon={() => <YearInReviewIcon />} />,
title: 'Your 2025 in Review',
titleClassName:
'text-transparent bg-clip-text bg-gradient-to-b from-accent-lettuce-default to-accent-cabbage-default font-bold',
path: `${webappUrl}log`,
isForcedLink: true,
}
: undefined;
return (
[
myFeed,
{
title: 'Following',
// this path can be opened on extension so it purposly
// is not using webappUrl so it gets selected
path: '/following',
action: () => onNavTabClick?.(OtherFeedPage.Following),
requiresLogin: true,
icon: (active: boolean) => (
<ListIcon Icon={() => <SquadIcon secondary={active} />} />
),
},
{
icon: (active: boolean) => (
<ListIcon Icon={() => <HotIcon secondary={active} />} />
),
title: 'Explore',
path: '/posts',
action: () => onNavTabClick?.(OtherFeedPage.Explore),
},
{
icon: (active: boolean) => (
<ListIcon Icon={() => <EyeIcon secondary={active} />} />
),
title: 'History',
path: `${webappUrl}history`,
isForcedLink: true,
requiresLogin: true,
},
{
icon: (active: boolean) => (
<ListIcon Icon={() => <TerminalIcon secondary={active} />} />
),
title: 'Agentic Hub',
path: `${webappUrl}agents`,
isForcedLink: true,
requiresLogin: true,
},
gameCenter,
yearInReview,
plusButton,
] as (SidebarMenuItem | undefined)[]
).filter((item): item is SidebarMenuItem => !!item);
}, [
claimableMilestoneCount,
ctaCopy,
isCustomDefaultFeed,
isLoggedIn,
isPlus,
onNavTabClick,
showGameCenter,
showYearInReview,
user,
]);
return (
<Section
{...defaultRenderSectionProps}
items={menuItems}
isItemsButton={isItemsButton}
className="!mt-0"
/>
);
};