Skip to content

Commit d9f1e0c

Browse files
authored
Revert "fix: header, sidebar UI, animations & mobile header fix (#5456)"
This reverts commit f247a5b.
1 parent c361d4d commit d9f1e0c

File tree

21 files changed

+226
-227
lines changed

21 files changed

+226
-227
lines changed

packages/shared/src/components/Feed.module.css

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
grid-template-columns: 100%;
33
}
44
.container {
5-
max-width: 100%;
6-
7-
@screen desktopL {
5+
@screen laptopL {
86
max-width: calc(20rem * var(--num-cards) + var(--feed-gap) * (var(--num-cards) - 1));
97
}
108
}
119
.cards {
12-
max-width: 100%;
13-
14-
@screen desktopL {
10+
@screen mobileL {
1511
max-width: calc(20rem * var(--num-cards) + var(--feed-gap) * (var(--num-cards) - 1));
1612
}
1713
}

packages/shared/src/components/Feed.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ export default function Feed<T>({
179179
const currentSettings = useContext(FeedContext);
180180
const { user } = useContext(AuthContext);
181181
const { isFallback, query: routerQuery } = useRouter();
182-
const { openNewTab, loadedSettings } = useContext(SettingsContext);
182+
const { openNewTab, spaciness, loadedSettings } = useContext(SettingsContext);
183183
const { isListMode } = useFeedLayout();
184-
const numCards = currentSettings.numCards.eco;
184+
const numCards = currentSettings.numCards[spaciness ?? 'eco'];
185185
const isSquadFeed = feedName === OtherFeedPage.Squad;
186186
const { shouldUseListFeedLayout } = useFeedLayout();
187187
const trackedFeedFinish = useRef(false);

packages/shared/src/components/MainLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ function MainLayoutComponent({
196196
/>
197197
<main
198198
className={classNames(
199-
'flex flex-col transition-[padding] duration-300 ease-in-out laptop:pt-16',
199+
'flex flex-col',
200200
showSidebar && 'tablet:pl-16 laptop:pl-11',
201201
className,
202202
isAuthReady &&
203203
!isScreenCentered &&
204204
sidebarExpanded &&
205205
'laptop:!pl-60',
206-
isBannerAvailable && 'laptop:pt-24',
206+
isBannerAvailable && 'laptop:pt-8',
207207
)}
208208
>
209209
{isAuthReady && showSidebar && (

packages/shared/src/components/feeds/FeedContainer.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ const cardListClass = {
6969
export const getFeedGapPx = {
7070
'gap-2': 8,
7171
'gap-3': 12,
72-
'gap-4': 16,
7372
'gap-5': 20,
74-
'gap-6': 24,
7573
'gap-8': 32,
7674
'gap-12': 48,
7775
'gap-14': 56,
@@ -89,7 +87,7 @@ export const gapClass = ({
8987
if (isFeedLayoutList) {
9088
return '';
9189
}
92-
return isList ? listGaps[space] ?? 'gap-2' : gridGaps[space] ?? 'gap-4';
90+
return isList ? listGaps[space] ?? 'gap-2' : gridGaps[space] ?? 'gap-8';
9391
};
9492

9593
const cardClass = ({
@@ -151,15 +149,15 @@ export const FeedContainer = ({
151149
}: FeedContainerProps): ReactElement => {
152150
const currentSettings = useContext(FeedContext);
153151
const { subject } = useToastNotification();
154-
const { loadedSettings } = useContext(SettingsContext);
152+
const { spaciness, loadedSettings } = useContext(SettingsContext);
155153
const { shouldUseListFeedLayout, isListMode } = useFeedLayout();
156154
const isLaptop = useViewSize(ViewSize.Laptop);
157155
const { feedName } = useActiveFeedNameContext();
158156
const { isAnyExplore, isExplorePopular, isExploreLatest } = useFeedName({
159157
feedName,
160158
});
161159
const router = useRouter();
162-
const numCards = currentSettings.numCards.eco;
160+
const numCards = currentSettings.numCards[spaciness ?? 'eco'];
163161
const isList =
164162
(isHorizontal || isListMode) && !shouldUseListFeedLayout
165163
? false
@@ -169,14 +167,14 @@ export const FeedContainer = ({
169167
gapClass({
170168
isList,
171169
isFeedLayoutList: shouldUseListFeedLayout,
172-
space: 'eco',
170+
space: spaciness,
173171
})
174172
];
175173
const style = {
176174
'--num-cards': isHorizontal && isListMode && numCards >= 2 ? 2 : numCards,
177175
'--feed-gap': `${feedGapPx / 16}rem`,
178176
} as CSSProperties;
179-
const cardContainerStyle = { ...getStyle(isList, 'eco') };
177+
const cardContainerStyle = { ...getStyle(isList, spaciness) };
180178
const isFinder = router.pathname === '/search/posts';
181179
const isSearch = showSearch && !isFinder;
182180

@@ -324,7 +322,7 @@ export const FeedContainer = ({
324322
gapClass({
325323
isList,
326324
isFeedLayoutList: shouldUseListFeedLayout,
327-
space: 'eco',
325+
space: spaciness,
328326
}),
329327
cardClass({ isList, numberOfCards: numCards, isHorizontal }),
330328
)}

packages/shared/src/components/feeds/FeedNav.tsx

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import classNames from 'classnames';
22
import type { ReactElement } from 'react';
3-
import React, { useMemo } from 'react';
3+
import React, { useMemo, useState, useTransition } from 'react';
44
import { useRouter } from 'next/router';
55
import { Tab, TabContainer } from '../tabs/TabContainer';
66
import { useActiveFeedNameContext } from '../../contexts';
77
import useActiveNav from '../../hooks/useActiveNav';
8-
import { useFeeds, useViewSize, ViewSize } from '../../hooks';
8+
import { useEventListener, useFeeds, useViewSize, ViewSize } from '../../hooks';
99
import usePersistentContext from '../../hooks/usePersistentContext';
1010
import {
1111
algorithmsList,
@@ -31,6 +31,7 @@ import { SharedFeedPage } from '../utilities';
3131
import PlusMobileEntryBanner from '../banners/PlusMobileEntryBanner';
3232
import { TargetType } from '../../lib/log';
3333
import usePlusEntry from '../../hooks/usePlusEntry';
34+
import { useAlertsContext } from '../../contexts/AlertContext';
3435

3536
enum FeedNavTab {
3637
ForYou = 'For you',
@@ -51,12 +52,17 @@ const StickyNavIconWrapper = classed(
5152
'sticky flex h-14 pt-1 -translate-y-16 items-center justify-end bg-gradient-to-r from-transparent via-background-default via-40% to-background-default pr-4',
5253
);
5354

55+
const MIN_SCROLL_BEFORE_HIDING = 60;
56+
5457
function FeedNav(): ReactElement {
5558
const router = useRouter();
59+
const [, startTransition] = useTransition();
60+
const [isHeaderVisible, setIsHeaderVisible] = useState(true);
5661
const { feedName } = useActiveFeedNameContext();
5762
const { sortingEnabled } = useSettingsContext();
5863
const { isSortableFeed } = useFeedName({ feedName });
5964
const { home, bookmarks } = useActiveNav(feedName);
65+
const { alerts } = useAlertsContext();
6066
const isMobile = useViewSize(ViewSize.MobileL);
6167
const [selectedAlgo, setSelectedAlgo] = usePersistentContext(
6268
DEFAULT_ALGORITHM_KEY,
@@ -76,6 +82,8 @@ function FeedNav(): ReactElement {
7682
isMobile &&
7783
((sortingEnabled && isSortableFeed) || feedName === SharedFeedPage.Custom);
7884

85+
const hasOpportunityAlert = !!alerts.opportunityId;
86+
7987
const urlToTab: Record<string, FeedNavTab> = useMemo(() => {
8088
const customFeeds = sortedFeeds.reduce((acc, { node: feed }) => {
8189
const isEditingFeed =
@@ -119,16 +127,45 @@ function FeedNav(): ReactElement {
119127
isCustomDefaultFeed,
120128
]);
121129

130+
const previousScrollY = React.useRef(0);
131+
132+
useEventListener(globalThis, 'scroll', () => {
133+
// when scrolled down we should hide the header
134+
// when scrolled up, we should bring it back
135+
const { scrollY } = window;
136+
const shouldHeaderBeVisible = scrollY < previousScrollY.current;
137+
138+
previousScrollY.current = scrollY;
139+
140+
if (shouldHeaderBeVisible === isHeaderVisible) {
141+
return;
142+
}
143+
144+
if (!shouldHeaderBeVisible && scrollY < MIN_SCROLL_BEFORE_HIDING) {
145+
return;
146+
}
147+
148+
startTransition(() => {
149+
setIsHeaderVisible(shouldHeaderBeVisible);
150+
});
151+
});
122152
const shouldRenderNav = home || (isMobile && bookmarks);
123153
if (!shouldRenderNav || router?.pathname?.startsWith('/posts/[id]')) {
124154
return null;
125155
}
126156

157+
const headerTransitionClasses =
158+
isMobile && hasOpportunityAlert
159+
? '-translate-y-[7.5rem] duration-[800ms]'
160+
: '-translate-y-26 duration-[800ms]';
161+
127162
return (
128163
<div
129164
className={classNames(
130-
'sticky top-0 z-header w-full bg-background-default tablet:pl-16',
165+
'sticky top-0 z-header w-full transition-transform tablet:pl-16',
131166
scrollClassName,
167+
isHeaderVisible && 'translate-y-0 duration-200',
168+
!isHeaderVisible && headerTransitionClasses,
132169
)}
133170
>
134171
{isMobile && <MobileFeedActions />}

packages/shared/src/components/layout/MainLayoutHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ function MainLayoutHeader({
9393
return (
9494
<header
9595
className={classNames(
96-
'fixed top-0 z-header h-14 flex-row content-center items-center justify-center gap-3 border-b border-border-subtlest-tertiary bg-background-default px-4 py-3 tablet:px-8 laptop:left-0 laptop:h-16 laptop:w-full laptop:px-4',
96+
'sticky top-0 z-header h-14 flex-row content-center items-center justify-center gap-3 border-b border-border-subtlest-tertiary px-4 py-3 tablet:px-8 laptop:left-0 laptop:h-16 laptop:w-full laptop:px-4',
9797
isMobileProfile ? 'hidden laptop:flex' : 'flex',
9898
hasBanner && 'laptop:top-8',
9999
isSearchPage && 'mb-16 laptop:mb-0',

packages/shared/src/components/layout/PageWrapperLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ComponentProps, PropsWithChildren, ReactElement } from 'react';
22
import React from 'react';
33
import classNames from 'classnames';
44

5-
export const pageMainClassNames = 'tablet:p-4 laptop:p-10';
5+
export const pageMainClassNames = 'tablet:p-4 laptop:px-10 laptop:py-5';
66

77
export const PageWrapperLayout = ({
88
children,

packages/shared/src/components/search/SearchResults/SearchResultsLayout.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { PropsWithChildren, ReactElement } from 'react';
2-
import React from 'react';
2+
import React, { useContext } from 'react';
33
import { useRouter } from 'next/router';
44
import classNames from 'classnames';
55
import { PageWidgets } from '../../utilities';
@@ -12,6 +12,7 @@ import { webappUrl } from '../../../lib/constants';
1212
import { SearchResultsTags } from './SearchResultsTags';
1313
import { SearchResultsSources } from './SearchResultsSources';
1414
import { useSearchProviderSuggestions } from '../../../hooks/search';
15+
import SettingsContext from '../../../contexts/SettingsContext';
1516
import { gapClass } from '../../feeds/FeedContainer';
1617
import { useFeedLayout } from '../../../hooks';
1718
import { SearchResultsUsers } from './SearchResultsUsers';
@@ -25,6 +26,7 @@ export const SearchResultsLayout = (
2526
): ReactElement => {
2627
const { children } = props;
2728
const { isListMode } = useFeedLayout();
29+
const { spaciness } = useContext(SettingsContext);
2830
const { isSearchPageLaptop } = useSearchResultsLayout();
2931

3032
const {
@@ -101,7 +103,7 @@ export const SearchResultsLayout = (
101103
gapClass({
102104
isList: true,
103105
isFeedLayoutList: false,
104-
space: 'eco',
106+
space: spaciness,
105107
}),
106108
isListMode
107109
? `flex flex-col`

packages/shared/src/components/sidebar/Section.tsx

Lines changed: 21 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import React, { useRef } from 'react';
44
import type { ItemInnerProps, SidebarMenuItem } from './common';
55
import { NavHeader, NavSection } from './common';
66
import { SidebarItem } from './SidebarItem';
7-
import { ArrowIcon, PlusIcon } from '../icons';
7+
import { Button, ButtonSize, ButtonVariant } from '../buttons/Button';
8+
import { ArrowIcon } from '../icons';
89
import type { SettingsFlags } from '../../graphql/settings';
910
import { useSettingsContext } from '../../contexts/SettingsContext';
1011
import { isNullOrUndefined } from '../../lib/func';
1112
import useSidebarRendered from '../../hooks/useSidebarRendered';
12-
import Link from '../utilities/Link';
1313

1414
export interface SectionCommonProps
1515
extends Pick<ItemInnerProps, 'shouldShowLabel'> {
@@ -24,8 +24,6 @@ interface SectionProps extends SectionCommonProps {
2424
items: SidebarMenuItem[];
2525
isItemsButton: boolean;
2626
isAlwaysOpenOnMobile?: boolean;
27-
onAdd?: () => void;
28-
addHref?: string;
2927
}
3028

3129
export function Section({
@@ -38,8 +36,6 @@ export function Section({
3836
className,
3937
flag,
4038
isAlwaysOpenOnMobile,
41-
onAdd,
42-
addHref,
4339
}: SectionProps): ReactElement {
4440
const { flags, updateFlag } = useSettingsContext();
4541
const { sidebarRendered } = useSidebarRendered();
@@ -53,79 +49,30 @@ export function Section({
5349
};
5450

5551
return (
56-
<NavSection className={classNames('mt-1', className)}>
52+
<NavSection className={className}>
5753
{title && (
58-
<NavHeader className="relative hidden laptop:flex">
59-
{/* Divider shown when sidebar is collapsed */}
60-
<div
61-
className={classNames(
62-
'absolute inset-x-0 flex items-center justify-center px-2 transition-opacity duration-300',
63-
sidebarExpanded ? 'opacity-0' : 'opacity-100',
64-
)}
65-
>
66-
<hr className="w-full border-t border-border-subtlest-tertiary" />
67-
</div>
68-
{/* Header content shown when sidebar is expanded */}
69-
<div
70-
className={classNames(
71-
'group/section flex min-h-9 w-full items-center justify-between px-2 py-1.5 transition-opacity duration-300',
72-
sidebarExpanded ? 'opacity-100' : 'pointer-events-none opacity-0',
73-
)}
74-
>
75-
<button
76-
type="button"
77-
onClick={toggleFlag}
78-
aria-label={`Toggle ${title}`}
79-
aria-expanded={!!isVisible.current}
80-
className="flex items-center gap-1 rounded-6 transition-colors hover:text-text-primary"
81-
>
82-
<span
83-
className={classNames(
84-
'text-text-quaternary typo-callout',
85-
!sidebarExpanded && 'opacity-0',
86-
)}
87-
>
88-
{title}
89-
</span>
54+
<NavHeader
55+
className={classNames(
56+
'hidden justify-between laptop:flex',
57+
sidebarExpanded ? 'px-3 opacity-100' : 'px-0 opacity-0',
58+
)}
59+
>
60+
{title}
61+
<Button
62+
variant={ButtonVariant.Tertiary}
63+
onClick={toggleFlag}
64+
size={ButtonSize.XSmall}
65+
aria-label={`Toggle ${title}`}
66+
icon={
9067
<ArrowIcon
91-
className={classNames(
92-
'h-2.5 w-2.5 text-text-quaternary transition-transform duration-200',
93-
isVisible.current ? 'rotate-180' : 'rotate-90',
94-
)}
68+
className={isVisible.current ? 'rotate-360' : 'rotate-180'}
9569
/>
96-
</button>
97-
{addHref && (
98-
<Link href={addHref}>
99-
<a
100-
aria-label={`Add to ${title}`}
101-
className="flex h-6 w-6 items-center justify-center rounded-6 text-text-tertiary transition-all hover:bg-surface-hover hover:text-text-primary"
102-
>
103-
<PlusIcon className="h-4 w-4" />
104-
</a>
105-
</Link>
106-
)}
107-
{!addHref && onAdd && (
108-
<button
109-
type="button"
110-
onClick={onAdd}
111-
aria-label={`Add to ${title}`}
112-
className="flex h-6 w-6 items-center justify-center rounded-6 text-text-tertiary transition-all hover:bg-surface-hover hover:text-text-primary"
113-
>
114-
<PlusIcon className="h-4 w-4" />
115-
</button>
116-
)}
117-
</div>
70+
}
71+
/>
11872
</NavHeader>
11973
)}
120-
<div
121-
className={classNames(
122-
'flex flex-col overflow-hidden transition-all duration-300',
123-
isVisible.current || shouldAlwaysBeVisible
124-
? 'max-h-[2000px] opacity-100' // Using large max-height for CSS transition animation
125-
: 'max-h-0 opacity-0',
126-
)}
127-
>
128-
{items.map((item) => (
74+
{(isVisible.current || shouldAlwaysBeVisible) &&
75+
items.map((item) => (
12976
<SidebarItem
13077
key={`${item.title}-${item.path}`}
13178
item={item}
@@ -134,7 +81,6 @@ export function Section({
13481
shouldShowLabel={shouldShowLabel}
13582
/>
13683
))}
137-
</div>
13884
</NavSection>
13985
);
14086
}

0 commit comments

Comments
 (0)