| 1 |
import React, { useEffect } from "react"; |
| 2 |
import { FAQProvider, useFAQ } from "../../components/FAQContext"; |
| 3 |
import { FAQScopeProvider, PRODUCT_TAXONOMY } from "../context/ScopeContext"; |
| 4 |
import BetterDocsFaqRoot from "../components/index"; |
| 5 |
|
| 6 |
// Fired by the header "Create a New Product FAQ Group" button after a group is |
| 7 |
// created; the header sits outside this nested provider, so a window event is |
| 8 |
// how it asks the product list to refresh. |
| 9 |
export const PRODUCT_FAQ_REFRESH_EVENT = "betterdocs:product-faq-refresh"; |
| 10 |
|
| 11 |
// Bridges the header's refresh event to the nested provider's refetch. |
| 12 |
const ProductGroupsRefresher = () => { |
| 13 |
const { reFetchCategories } = useFAQ(); |
| 14 |
|
| 15 |
useEffect(() => { |
| 16 |
const handler = () => reFetchCategories?.(); |
| 17 |
window.addEventListener(PRODUCT_FAQ_REFRESH_EVENT, handler); |
| 18 |
return () => |
| 19 |
window.removeEventListener(PRODUCT_FAQ_REFRESH_EVENT, handler); |
| 20 |
}, [reFetchCategories]); |
| 21 |
|
| 22 |
return null; |
| 23 |
}; |
| 24 |
|
| 25 |
// A nested FAQProvider isolates the Product scope's category/stat state from the |
| 26 |
// General tab's shared provider, so switching tabs never bleeds one list into |
| 27 |
// the other. The "Create a New Product FAQ Group" button lives in the page |
| 28 |
// header (see CreateProductFAQGroup), matching the General tab's layout. |
| 29 |
const ProductFaqGroups = () => { |
| 30 |
return ( |
| 31 |
<FAQProvider> |
| 32 |
<FAQScopeProvider taxonomy={PRODUCT_TAXONOMY}> |
| 33 |
<ProductGroupsRefresher /> |
| 34 |
<BetterDocsFaqRoot /> |
| 35 |
</FAQScopeProvider> |
| 36 |
</FAQProvider> |
| 37 |
); |
| 38 |
}; |
| 39 |
|
| 40 |
export default ProductFaqGroups; |
| 41 |
|