This commit is contained in:
ditiqi 2025-02-27 12:21:38 +08:00
parent 73757c0ee9
commit 57caccdfd4
1 changed files with 15 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { Prisma } from "packages/common/dist"; import { PostType, Prisma } from "packages/common/dist";
import React, { import React, {
createContext, createContext,
ReactNode, ReactNode,
@ -17,6 +17,12 @@ interface MainContextType {
setSelectedTerms?: React.Dispatch<React.SetStateAction<SelectedTerms>>; setSelectedTerms?: React.Dispatch<React.SetStateAction<SelectedTerms>>;
searchCondition?: Prisma.PostWhereInput; searchCondition?: Prisma.PostWhereInput;
termsCondition?: Prisma.PostWhereInput; termsCondition?: Prisma.PostWhereInput;
searchMode?: PostType.COURSE | PostType.PATH | "both";
setSearchMode?: React.Dispatch<
React.SetStateAction<PostType.COURSE | PostType.PATH | "both">
>;
showSearchMode?: boolean;
setShowSearchMode?: React.Dispatch<React.SetStateAction<boolean>>;
} }
const MainContext = createContext<MainContextType | null>(null); const MainContext = createContext<MainContextType | null>(null);
@ -25,6 +31,10 @@ interface MainProviderProps {
} }
export function MainProvider({ children }: MainProviderProps) { export function MainProvider({ children }: MainProviderProps) {
const [searchMode, setSearchMode] = useState<
PostType.COURSE | PostType.PATH | "both"
>("both");
const [showSearchMode, setShowSearchMode] = useState<boolean>(false);
const [searchValue, setSearchValue] = useState(""); const [searchValue, setSearchValue] = useState("");
const [selectedTerms, setSelectedTerms] = useState<SelectedTerms>({}); // 初始化状态 const [selectedTerms, setSelectedTerms] = useState<SelectedTerms>({}); // 初始化状态
const termFilters = useMemo(() => { const termFilters = useMemo(() => {
@ -79,6 +89,10 @@ export function MainProvider({ children }: MainProviderProps) {
setSelectedTerms, setSelectedTerms,
searchCondition, searchCondition,
termsCondition, termsCondition,
searchMode,
setSearchMode,
showSearchMode,
setShowSearchMode,
}}> }}>
{children} {children}
</MainContext.Provider> </MainContext.Provider>