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, {
createContext,
ReactNode,
@ -17,6 +17,12 @@ interface MainContextType {
setSelectedTerms?: React.Dispatch<React.SetStateAction<SelectedTerms>>;
searchCondition?: 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);
@ -25,6 +31,10 @@ interface 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 [selectedTerms, setSelectedTerms] = useState<SelectedTerms>({}); // 初始化状态
const termFilters = useMemo(() => {
@ -79,6 +89,10 @@ export function MainProvider({ children }: MainProviderProps) {
setSelectedTerms,
searchCondition,
termsCondition,
searchMode,
setSearchMode,
showSearchMode,
setShowSearchMode,
}}>
{children}
</MainContext.Provider>