Skip to content

Commit

Permalink
Handle closing
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero committed Dec 9, 2024
1 parent d086ad8 commit 510a683
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
29 changes: 17 additions & 12 deletions packages/help-center/src/components/help-center-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ const HelpCenterContent: React.FC< { isRelative?: boolean; currentRoute?: string
const { data: openSupportInteraction, isLoading: isLoadingOpenSupportInteractions } =
useGetSupportInteractions( 'help-center' );
const isUserEligibleForPaidSupport = data?.eligibility.is_user_eligible ?? false;
const scrollPosition = useArticleScrollPosition(
containerRef,
location.pathname.includes( '/post' )
);

useEffect( () => {
recordTracksEvent( 'calypso_helpcenter_page_open', {
Expand All @@ -75,14 +71,23 @@ const HelpCenterContent: React.FC< { isRelative?: boolean; currentRoute?: string
} );
}, [ location, sectionName, isUserEligibleForPaidSupport ] );

const { currentSupportInteraction, navigateToRoute, isMinimized } = useSelect( ( select ) => {
const store = select( HELP_CENTER_STORE ) as HelpCenterSelect;
return {
currentSupportInteraction: store.getCurrentSupportInteraction(),
navigateToRoute: store.getNavigateToRoute(),
isMinimized: store.getIsMinimized(),
};
}, [] );
const { currentSupportInteraction, navigateToRoute, isMinimized, isShown } = useSelect(
( select ) => {
const store = select( HELP_CENTER_STORE ) as HelpCenterSelect;
return {
currentSupportInteraction: store.getCurrentSupportInteraction(),
navigateToRoute: store.getNavigateToRoute(),
isMinimized: store.getIsMinimized(),
isShown: store.isHelpCenterShown(),
};
},
[]
);

const scrollPosition = useArticleScrollPosition(
containerRef,
location.pathname.includes( '/post' ) && Boolean( isShown )
);

useEffect( () => {
if (
Expand Down
3 changes: 3 additions & 0 deletions packages/help-center/src/hooks/use-scroll-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export function useArticleScrollPosition( ref: React.RefObject< HTMLElement >, e
};
if ( enabled ) {
element?.addEventListener( 'scroll', handleScroll );
} else {
// Reset the cached scroll position when the HC is closed or the article page is unmounted.
cachedScrollPosition = 0;
}
return () => {
element?.removeEventListener( 'scroll', handleScroll );
Expand Down

0 comments on commit 510a683

Please sign in to comment.