PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.5
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 All 203 releases
betterdocs / react-src / admin / components / FAQContext.js

FAQContext.js in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.5, at react-src/admin/components/FAQContext.js

35 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { createContext, useContext, useState, useCallback } from 'react';
2
3 const FAQContext = createContext();
4
5 export const FAQProvider = ({ children }) => {
6 const [categories, setCategories] = useState([]);
7 const [reFetchCategories, setReFetchCategories] = useState(() => () => {});
8 // Bumped on any FAQ activity (add / delete / duplicate / draft toggle) so
9 // the stat cards re-derive even when the change is to an uncategorized FAQ
10 // (which doesn't alter the categories query the cards otherwise watch).
11 const [statsVersion, setStatsVersion] = useState(0);
12 const bumpStats = useCallback(() => setStatsVersion((v) => v + 1), []);
13
14 // One-shot "reveal this FAQ" signal, set after a FAQ is created
15 // (?faq_action=create) or moved into a group via Edit. Shape:
16 // { groupId, faqId } where groupId ("uncategorized" | term id) drives the
17 // pagination jump + group expand, and faqId is the FAQ row that then
18 // flashes. Mirrors the Doc Categories / Doc Tags panels' focusTermId.
19 // `highlightGroupId` = group currently being expanded; `highlightFaqId` =
20 // FAQ row currently flashing (consumed by the row once it renders).
21 const [focusTarget, setFocusTarget] = useState(null);
22 const [highlightGroupId, setHighlightGroupId] = useState(null);
23 const [highlightFaqId, setHighlightFaqId] = useState(null);
24
25 return (
26 <FAQContext.Provider value={{ categories, setCategories, reFetchCategories, setReFetchCategories, statsVersion, bumpStats, focusTarget, setFocusTarget, highlightGroupId, setHighlightGroupId, highlightFaqId, setHighlightFaqId }}>
27 {children}
28 </FAQContext.Provider>
29 );
30 };
31
32 export const useFAQ = () => {
33 return useContext(FAQContext);
34 };
35