Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alshakero committed Jun 20, 2024
1 parent 03abd41 commit be06509
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
import { useLocale } from '@automattic/i18n-utils';
import { useEffect } from 'react';
import { SUPPORT_BLOG_ID } from 'calypso/blocks/inline-help/constants';
import QueryReaderPost from 'calypso/components/data/query-reader-post';
import QueryReaderSite from 'calypso/components/data/query-reader-site';
import useSupportArticleAlternatesQuery from 'calypso/data/support-article-alternates/use-support-article-alternates-query';
import { usePostByKey } from '../hooks/use-post-by-key';
import ArticleContent from './help-center-article-content';
// import './style.scss';
import './help-center-article-content.scss';

const getPostKey = ( blogId: number, postId: number ) => ( { blogId, postId } );
Expand Down Expand Up @@ -36,17 +33,10 @@ const ArticleFetchingContent = ( { postId, blogId, articleUrl }: ArticleFetching
const postKey = useSupportArticleAlternatePostKey( +( blogId ?? SUPPORT_BLOG_ID ), postId );
const post = usePostByKey( postKey ).data;
const isLoading = ! post?.content || ! postKey;

Check failure on line 35 in packages/help-center/src/components/help-center-article-fetching-content.tsx

View workflow job for this annotation

GitHub Actions / Run PHPunit tests.

Property 'content' does not exist on type '{}'.
const siteId = post?.site_ID;
const shouldQueryReaderPost = ! post && postKey;

useEffect( () => {
//If a url includes an anchor, let's scroll this into view!
if (
typeof window !== 'undefined' &&
articleUrl &&
articleUrl.indexOf( '#' ) !== -1 &&
post?.content
) {
if ( articleUrl && articleUrl.indexOf( '#' ) !== -1 && post?.content ) {
setTimeout( () => {
const anchorId = articleUrl.split( '#' ).pop();
if ( anchorId ) {
Expand All @@ -61,8 +51,6 @@ const ArticleFetchingContent = ( { postId, blogId, articleUrl }: ArticleFetching

return (
<>
{ siteId && <QueryReaderSite siteId={ +siteId } /> }
{ shouldQueryReaderPost && <QueryReaderPost postKey={ postKey } isHelpCenter /> }
<ArticleContent
content={ post?.content }
title={ post?.title }
Expand Down
19 changes: 5 additions & 14 deletions packages/help-center/src/components/help-center-launchpad.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import config from '@automattic/calypso-config';
import { CircularProgressBar } from '@automattic/components';
import { useLaunchpad } from '@automattic/data-stores';
import { localizeUrl } from '@automattic/i18n-utils';
import { useSelect } from '@wordpress/data';
import { chevronRight, Icon } from '@wordpress/icons';
import { useI18n } from '@wordpress/react-i18n';
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
import { SITE_STORE } from '../stores';
import type { SiteSelect } from '@automattic/data-stores';
import { useSiteIntent } from '../hooks/use-site-intent';
import { useSiteSlug } from '../hooks/use-site-slug';

const getEnvironmentHostname = () => {
try {
Expand All @@ -29,18 +28,10 @@ const getEnvironmentHostname = () => {

export const HelpCenterLaunchpad = () => {
const { __ } = useI18n();
const { selectedSiteId, sectionName } = useHelpCenterContext();
const { sectionName } = useHelpCenterContext();

const site = useSelect(
( select ) => {
if ( selectedSiteId ) {
return ( select( SITE_STORE ) as SiteSelect ).getSite( selectedSiteId );
}
},
[ selectedSiteId ]
);
let siteIntent = site && site?.options?.site_intent;
let siteSlug = site && new URL( site.URL ).host;
let siteIntent = useSiteIntent();
let siteSlug = useSiteSlug();

if ( ! siteIntent || ! siteSlug ) {
siteIntent = window?.helpCenterData?.currentSite?.site_intent;
Expand Down
32 changes: 11 additions & 21 deletions packages/help-center/src/components/help-center-search-results.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable no-restricted-imports */
import { recordTracksEvent } from '@automattic/calypso-analytics';
import page from '@automattic/calypso-router';
import { Gridicon } from '@automattic/components';
import {
Expand All @@ -22,16 +23,13 @@ import { useRtl } from 'i18n-calypso';
import { debounce } from 'lodash';
import PropTypes from 'prop-types';
import { Fragment, useEffect, useMemo } from 'react';
import { useDispatch } from 'react-redux';
import { useDebounce } from 'use-debounce';
import QueryUserPurchases from 'calypso/components/data/query-user-purchases';
import { useHelpSearchQuery } from 'calypso/data/help/use-help-search-query';
import { decodeEntities, preventWidows } from 'calypso/lib/formatting';
import { recordTracksEvent } from 'calypso/state/analytics/actions';
import { useSiteOption } from 'calypso/state/sites/hooks';
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
import { useAdminResults } from '../hooks/use-admin-results';
import { useContextBasedSearchMapping } from '../hooks/use-context-based-search-mapping';
import { useSiteIntent } from '../hooks/use-site-intent';
import PlaceholderLines from './placeholder-lines';
import type { SearchResult } from '../types';

Expand Down Expand Up @@ -110,13 +108,12 @@ function HelpSearchResults( {
location = 'inline-help-popover',
currentRoute,
}: HelpSearchResultsProps ) {
const dispatch = useDispatch();
const { hasPurchases, sectionName } = useHelpCenterContext();

const adminResults = useAdminResults( searchQuery );

const isPurchasesSection = [ 'purchases', 'site-purchases' ].includes( sectionName );
const siteIntent = useSiteOption( 'site_intent' );
const siteIntent = useSiteIntent();
const rawContextualResults = useMemo(
() => getContextResults( sectionName, siteIntent ),

Check failure on line 118 in packages/help-center/src/components/help-center-search-results.tsx

View workflow job for this annotation

GitHub Actions / Run PHPunit tests.

Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
[ sectionName, siteIntent ]
Expand Down Expand Up @@ -176,14 +173,12 @@ function HelpSearchResults( {
// check and catch admin section links.
if ( type === SUPPORT_TYPE_ADMIN_SECTION && link ) {
// record track-event.
dispatch(
recordTracksEvent( 'calypso_inlinehelp_admin_section_visit', {
link: link,
search_term: searchQuery,
location,
section: sectionName,
} )
);
recordTracksEvent( 'calypso_inlinehelp_admin_section_visit', {
link: link,
search_term: searchQuery,
location,
section: sectionName,
} );

// push state only if it's internal link.
if ( ! /^http/.test( link ) ) {
Expand All @@ -209,7 +204,7 @@ function HelpSearchResults( {
? 'calypso_inlinehelp_tailored_article_select'
: 'calypso_inlinehelp_article_select';

dispatch( recordTracksEvent( eventName, eventData ) );
recordTracksEvent( eventName, eventData );
onSelect( event, result );
};

Expand Down Expand Up @@ -359,12 +354,7 @@ function HelpSearchResults( {
);
};

return (
<>
<QueryUserPurchases />
{ renderSearchResults() }
</>
);
return renderSearchResults();
}

HelpSearchResults.propTypes = {
Expand Down
17 changes: 0 additions & 17 deletions packages/help-center/src/components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ declare module 'calypso/blocks/inline-help/inline-help-search-results' {
const InlineHelpSearchResults: FC;
export = InlineHelpSearchResults;
}

declare module 'calypso/components/data/query-user-purchases' {
const QueryUserPurchases: () => null;
export const purchases: void;
export = QueryUserPurchases;
}

declare module 'calypso/components/data/query-reader-post' {
const QueryReaderPost: FC;
export default QueryReaderPost;
}

declare module 'calypso/components/data/query-reader-site' {
const QueryReaderSite: FC;
export default QueryReaderSite;
}

declare module 'calypso/components/embed-container' {
const EmbedContainer: FC;
export default EmbedContainer;
Expand Down
17 changes: 17 additions & 0 deletions packages/help-center/src/hooks/use-site-intent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { SiteSelect } from '@automattic/data-stores';
import { useSelect } from '@wordpress/data';
import { useHelpCenterContext } from '../contexts/HelpCenterContext';
import { SITE_STORE } from '../stores';

export function useSiteIntent() {
const { selectedSiteId } = useHelpCenterContext();
const site = useSelect(
( select ) => {
if ( selectedSiteId ) {
return ( select( SITE_STORE ) as SiteSelect ).getSite( selectedSiteId );
}
},
[ selectedSiteId ]
);
return site?.options?.site_intent;
}

0 comments on commit be06509

Please sign in to comment.