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 / DocCategoriesContext.js

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

57 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { createContext, useContext, useState, useEffect } from "react";
2
3 const DocCategoriesContext = createContext(null);
4
5 export const DocCategoriesProvider = ({ children }) => {
6 const [slideOpen, setSlideOpen] = useState(false);
7
8 // Auto-open the "Add New Category" slide-over when arrived here from the
9 // empty-state "Create A New Category" button (?betterdocs_action=new-category).
10 useEffect(() => {
11 try {
12 const params = new URLSearchParams(window.location.search);
13 if (params.get("betterdocs_action") === "new-category") {
14 setSlideOpen(true);
15 }
16 } catch (e) {}
17 }, []);
18 const [editNode, setEditNode] = useState(null);
19 const [defaultParent, setDefaultParent] = useState(null);
20 const [totalCount, setTotalCount] = useState(null);
21 // One-shot id of a just-created term: the tree jumps to its page and flashes it.
22 const [focusTermId, setFocusTermId] = useState(null);
23 // Pre-fill for the "add translation" create flow: { lang, translationOf }.
24 const [createMeta, setCreateMeta] = useState(null);
25
26 const openCreate = (parent = null, meta = null) => {
27 setEditNode(null);
28 setDefaultParent(parent);
29 setCreateMeta(meta);
30 setSlideOpen(true);
31 };
32
33 const openEdit = (node) => {
34 setEditNode(node);
35 setDefaultParent(null);
36 setCreateMeta(null);
37 setSlideOpen(true);
38 };
39
40 const close = () => {
41 setSlideOpen(false);
42 setEditNode(null);
43 setDefaultParent(null);
44 setCreateMeta(null);
45 };
46
47 return (
48 <DocCategoriesContext.Provider
49 value={{ slideOpen, editNode, defaultParent, totalCount, focusTermId, createMeta, openCreate, openEdit, close, setTotalCount, setFocusTermId }}
50 >
51 {children}
52 </DocCategoriesContext.Provider>
53 );
54 };
55
56 export const useDocCategories = () => useContext(DocCategoriesContext);
57