import { __ } from "@wordpress/i18n"; import React, { useEffect } from "react"; import UncategorizedFaq from "./UncategorizedFaq"; import { scrollExpandedIntoView } from "../utils/function"; // icons import { ReactComponent as DownArrow } from "./../assets/images/down-arrow.svg"; import FaqLoader from "../utils/FaqLoader"; const UncategorizedFaqList = ({ categoriesLoading, allFaqCategories, reFetchCategories, allUncategorizedFaq, setFetchUncategorizedFaq, categoryExpanded, setCategoryExpanded, setCreateFaqAt, faqExpanded, setFaqExpanded, setReFetchFaqForCategory, uncategorizedFaqLoading, uncategorizedFaqFetching, highlightGroupId, }) => { // Focus target after a FAQ is created without a group: open + scroll the // panel so the new FAQ row (which flashes itself) is visible. const isHighlighted = highlightGroupId === "uncategorized"; useEffect(() => { if (!isHighlighted) return; setCategoryExpanded("uncategorized"); setFetchUncategorizedFaq && setFetchUncategorizedFaq(); scrollExpandedIntoView("ctg-uncategorized"); }, [isHighlighted]); const handleShow = () => { if (categoryExpanded == "uncategorized") { setCategoryExpanded(undefined); } else { setCategoryExpanded("uncategorized"); // Fetch on open (like the categorized groups) so the loader shows. setFetchUncategorizedFaq && setFetchUncategorizedFaq(); } }; return (
handleShow()} style={{ cursor: "pointer" }} >

{__("Uncategorized", "betterdocs")}

{allUncategorizedFaq?.length > 0 && ( {`${allUncategorizedFaq.length} `} {allUncategorizedFaq.length === 1 ? __("question", "betterdocs") : __("questions", "betterdocs")} )}
{categoryExpanded == "uncategorized" && // Only show the loader on the initial load — NOT on a // background refetch (isFetching). A refetch fires after // editing/saving an uncategorized FAQ; swapping the whole // list for the loader there collapsed the open edit form // abruptly. Matching the categorized FaqList (which keys // off isLoading only) keeps the accordion open and the // slide-transition smooth. (uncategorizedFaqLoading ? ( ) : ( allUncategorizedFaq?.map((faq) => ( )) ))}
); }; export default UncategorizedFaqList;