| 1 |
import { __ } from "@wordpress/i18n"; |
| 2 |
import React, { useEffect } from "react"; |
| 3 |
import UncategorizedFaq from "./UncategorizedFaq"; |
| 4 |
import { scrollExpandedIntoView } from "../utils/function"; |
| 5 |
|
| 6 |
// icons |
| 7 |
import { ReactComponent as DownArrow } from "./../assets/images/down-arrow.svg"; |
| 8 |
import FaqLoader from "../utils/FaqLoader"; |
| 9 |
|
| 10 |
const UncategorizedFaqList = ({ |
| 11 |
categoriesLoading, |
| 12 |
allFaqCategories, |
| 13 |
reFetchCategories, |
| 14 |
allUncategorizedFaq, |
| 15 |
setFetchUncategorizedFaq, |
| 16 |
categoryExpanded, |
| 17 |
setCategoryExpanded, |
| 18 |
setCreateFaqAt, |
| 19 |
faqExpanded, |
| 20 |
setFaqExpanded, |
| 21 |
setReFetchFaqForCategory, |
| 22 |
uncategorizedFaqLoading, |
| 23 |
uncategorizedFaqFetching, |
| 24 |
highlightGroupId, |
| 25 |
}) => { |
| 26 |
// Focus target after a FAQ is created without a group: open + scroll the |
| 27 |
// panel so the new FAQ row (which flashes itself) is visible. |
| 28 |
const isHighlighted = highlightGroupId === "uncategorized"; |
| 29 |
useEffect(() => { |
| 30 |
if (!isHighlighted) return; |
| 31 |
setCategoryExpanded("uncategorized"); |
| 32 |
setFetchUncategorizedFaq && setFetchUncategorizedFaq(); |
| 33 |
scrollExpandedIntoView("ctg-uncategorized"); |
| 34 |
}, [isHighlighted]); |
| 35 |
|
| 36 |
const handleShow = () => { |
| 37 |
if (categoryExpanded == "uncategorized") { |
| 38 |
setCategoryExpanded(undefined); |
| 39 |
} else { |
| 40 |
setCategoryExpanded("uncategorized"); |
| 41 |
// Fetch on open (like the categorized groups) so the loader shows. |
| 42 |
setFetchUncategorizedFaq && setFetchUncategorizedFaq(); |
| 43 |
} |
| 44 |
}; |
| 45 |
|
| 46 |
return ( |
| 47 |
<div className="bd-faq-ctg" data-bd-expand-id="ctg-uncategorized"> |
| 48 |
<div className="bd-faq-ctg-head"> |
| 49 |
<div |
| 50 |
className="bd-faq-ctg-title-wrap" |
| 51 |
onClick={() => handleShow()} |
| 52 |
style={{ cursor: "pointer" }} |
| 53 |
> |
| 54 |
<h3 className="bd-faq-ctg-title"> |
| 55 |
{__("Uncategorized", "betterdocs")} |
| 56 |
</h3> |
| 57 |
{allUncategorizedFaq?.length > 0 && ( |
| 58 |
<span className="bd-faq-ctg-meta"> |
| 59 |
<span className="bd-faq-ctg-meta-count"> |
| 60 |
{`${allUncategorizedFaq.length} `} |
| 61 |
{allUncategorizedFaq.length === 1 |
| 62 |
? __("question", "betterdocs") |
| 63 |
: __("questions", "betterdocs")} |
| 64 |
</span> |
| 65 |
</span> |
| 66 |
)} |
| 67 |
</div> |
| 68 |
<button |
| 69 |
type="button" |
| 70 |
className={`bd-faq-accordion-icon ${categoryExpanded == "uncategorized" ? "active" : "" |
| 71 |
}`} |
| 72 |
onClick={() => handleShow()} |
| 73 |
> |
| 74 |
<DownArrow /> |
| 75 |
</button> |
| 76 |
</div> |
| 77 |
<div |
| 78 |
className={`bd-faq-category-body ${categoryExpanded == "uncategorized" ? "active" : "" |
| 79 |
}`} |
| 80 |
> |
| 81 |
<div style={{ overflow: "hidden" }}> |
| 82 |
<div className="bd-faq-category-body-inner"> |
| 83 |
{categoryExpanded == "uncategorized" && |
| 84 |
// Only show the loader on the initial load — NOT on a |
| 85 |
// background refetch (isFetching). A refetch fires after |
| 86 |
// editing/saving an uncategorized FAQ; swapping the whole |
| 87 |
// list for the loader there collapsed the open edit form |
| 88 |
// abruptly. Matching the categorized FaqList (which keys |
| 89 |
// off isLoading only) keeps the accordion open and the |
| 90 |
// slide-transition smooth. |
| 91 |
(uncategorizedFaqLoading ? ( |
| 92 |
<FaqLoader /> |
| 93 |
) : ( |
| 94 |
allUncategorizedFaq?.map((faq) => ( |
| 95 |
<UncategorizedFaq |
| 96 |
key={faq?.ID} |
| 97 |
data={faq} |
| 98 |
reFetchFaqList={setFetchUncategorizedFaq} |
| 99 |
categoriesLoading={categoriesLoading} |
| 100 |
allFaqCategories={allFaqCategories} |
| 101 |
reFetchCategories={reFetchCategories} |
| 102 |
setCreateFaqAt={setCreateFaqAt} |
| 103 |
faqExpanded={faqExpanded} |
| 104 |
setFaqExpanded={setFaqExpanded} |
| 105 |
setReFetchFaqForCategory={ |
| 106 |
setReFetchFaqForCategory |
| 107 |
} |
| 108 |
settings={betterdocsFaq?.betterdocs_settings} |
| 109 |
/> |
| 110 |
)) |
| 111 |
))} |
| 112 |
</div> |
| 113 |
</div> |
| 114 |
</div> |
| 115 |
</div> |
| 116 |
); |
| 117 |
}; |
| 118 |
|
| 119 |
export default UncategorizedFaqList; |
| 120 |
|