Skip to content

Commit

Permalink
Fix recent FAQ sort
Browse files Browse the repository at this point in the history
  • Loading branch information
dcklages committed Apr 27, 2020
1 parent f204d1b commit b5d7794
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/components/Sidebar/RecentFAQs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import { DOMAIN_NAME } from 'api/endpoints';
import './styles.scss';
import { useSearch } from 'utils/hooks';
import { types, searchKeys } from 'api/content';
import { sortMapper, documentsSelector } from 'utils/helpers';
import { faqSortMapper, documentsSelector } from 'utils/helpers';
import { HashLink as Link } from 'react-router-hash-link';

const RecentFAQs = ({ styleGuide }) => {

const documents = useSearch(
{
sort: sortMapper(searchKeys.displayOrder),
sort: faqSortMapper(searchKeys.displayOrder),
fq: `type:(${types.faqItem})`,
fl: 'document:[json]&rows=5',
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/Sidebar/RelatedFAQs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DOMAIN_NAME } from 'api/endpoints';
import './styles.scss';
import { useSearch } from 'utils/hooks';
import { types, searchKeys } from 'api/content';
import { sortMapper, documentsSelector } from 'utils/helpers';
import { faqSortMapper, documentsSelector } from 'utils/helpers';
import { HashLink as Link } from 'react-router-hash-link';

const RelatedFAQs = ({ categories, styleGuide }) => {
Expand All @@ -34,7 +34,7 @@ const RelatedFAQs = ({ categories, styleGuide }) => {

const documents = useSearch(
{
sort: sortMapper(searchKeys.displayOrder),
sort: faqSortMapper(searchKeys.displayOrder),
fq: `type:(${types.faqItem}) AND ( ${query} )`,
fl: 'document:[json]&rows=5',
},
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/FAQPreview/FAQPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { useRouteMatch } from 'react-router-dom';

import ArticlesPreviewCard from 'components/ArticlesPreviewCard/ArticlesPreviewCard';
import FAQItem from 'components/FAQItem/FAQItem'
import { sortMapper, documentsSelector } from 'utils/helpers';
import { faqSortMapper, documentsSelector } from 'utils/helpers';
import { useSearch } from 'utils/hooks';
import { types, searchKeys } from 'api/content';

const FAQPreview = ({ styleGuide }) => {
const documents = useSearch(
{
sort: sortMapper(searchKeys.displayOrder),
sort: faqSortMapper(searchKeys.displayOrder),
fq: `type:(${types.faqItem}) AND ${searchKeys.topUpdate}:true`,
fl: 'document:[json]',
},
Expand Down
24 changes: 12 additions & 12 deletions src/pages/Home/Sidebar/RecentFAQs.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ import { DOMAIN_NAME } from 'api/endpoints';
import './styles.scss';
import { useSearch } from 'utils/hooks';
import { types, searchKeys } from 'api/content';
import { sortMapper, documentsSelector } from 'utils/helpers';
import { faqSortMapper, documentsSelector } from 'utils/helpers';

const RecentFAQs = ({styleGuide}) => {
const RecentFAQs = ({ styleGuide }) => {

const documents = useSearch(
{
sort: sortMapper(searchKeys.displayOrder),
fq: `type:(${types.faqItem})`,
fl: 'document:[json]&rows=5',
sort: faqSortMapper(searchKeys.displayOrder),
fq: `type:(${types.faqItem})`,
fl: 'document:[json]&rows=5',
},
documentsSelector
);
);

if(!documents?.length){
if (!documents?.length) {
return null;
}
return(
return (
<div className="sidebarSection">
<div className="sidebarTitle" style={{color:styleGuide.titleText, fontFamily:styleGuide.fontFamily}}>Recently added FAQs</div>
<ul style={{color:styleGuide.bodyText, fontFamily:styleGuide.fontFamily}}>
{documents?.map((document, index)=>
<div className="sidebarTitle" style={{ color: styleGuide.titleText, fontFamily: styleGuide.fontFamily }}>Recently added FAQs</div>
<ul style={{ color: styleGuide.bodyText, fontFamily: styleGuide.fontFamily }}>
{documents?.map((document, index) =>
<li key={index}>{document?.elements.question.value}</li>
)}
<li><a href="#/faq" style={{color:styleGuide.link, fontFamily:styleGuide.fontFamily}}>view all FAQs </a></li>
<li><a href="#/faq" style={{ color: styleGuide.link, fontFamily: styleGuide.fontFamily }}>view all FAQs </a></li>
</ul>
</div>
)
Expand Down
3 changes: 3 additions & 0 deletions src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export const removeDuplicates = array => Array.from(new Set(array));
export const sortMapper = value =>
`sortableDate1 ${value === 'Most Recent' ? 'desc' : 'asc'}`;

export const faqSortMapper = value =>
`lastModified ${value === 'Most Recent' ? 'desc' : 'asc'}`;

//get Date string in MMM DD YYYY format
const getFormattedDate = dateString =>
dateString
Expand Down

0 comments on commit b5d7794

Please sign in to comment.