add
This commit is contained in:
parent
ae44ed6872
commit
47ccacfee2
|
@ -15,7 +15,7 @@ export function MainHeader() {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { searchValue, setSearchValue } = useMainContext();
|
const { searchValue, setSearchValue } = useMainContext();
|
||||||
const { update } = useStaff();
|
const { update } = useStaff();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Header className="select-none flex items-center justify-center bg-white shadow-md border-b border-gray-100 fixed w-full z-30">
|
<Header className="select-none flex items-center justify-center bg-white shadow-md border-b border-gray-100 fixed w-full z-30">
|
||||||
<div className="w-full max-w-screen-3xl px-4 md:px-6 mx-auto flex items-center justify-between h-full">
|
<div className="w-full max-w-screen-3xl px-4 md:px-6 mx-auto flex items-center justify-between h-full">
|
||||||
|
@ -42,7 +42,8 @@ export function MainHeader() {
|
||||||
if (
|
if (
|
||||||
!window.location.pathname.startsWith(
|
!window.location.pathname.startsWith(
|
||||||
"/courses/"
|
"/courses/"
|
||||||
)
|
) &&
|
||||||
|
!window.location.pathname.startsWith("my")
|
||||||
) {
|
) {
|
||||||
navigate(`/courses/`);
|
navigate(`/courses/`);
|
||||||
window.scrollTo({
|
window.scrollTo({
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
import React, { createContext, ReactNode, useContext, useState } from "react";
|
import { Prisma } from "packages/common/dist";
|
||||||
|
import React, {
|
||||||
|
createContext,
|
||||||
|
ReactNode,
|
||||||
|
useContext,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
} from "react";
|
||||||
interface SelectedTerms {
|
interface SelectedTerms {
|
||||||
[key: string]: string[]; // 每个 slug 对应一个 string 数组
|
[key: string]: string[]; // 每个 slug 对应一个 string 数组
|
||||||
}
|
}
|
||||||
|
@ -8,6 +15,7 @@ interface MainContextType {
|
||||||
selectedTerms?: SelectedTerms;
|
selectedTerms?: SelectedTerms;
|
||||||
setSearchValue?: React.Dispatch<React.SetStateAction<string>>;
|
setSearchValue?: React.Dispatch<React.SetStateAction<string>>;
|
||||||
setSelectedTerms?: React.Dispatch<React.SetStateAction<SelectedTerms>>;
|
setSelectedTerms?: React.Dispatch<React.SetStateAction<SelectedTerms>>;
|
||||||
|
searchCondition?: Prisma.PostWhereInput;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MainContext = createContext<MainContextType | null>(null);
|
const MainContext = createContext<MainContextType | null>(null);
|
||||||
|
@ -18,6 +26,29 @@ interface MainProviderProps {
|
||||||
export function MainProvider({ children }: MainProviderProps) {
|
export function MainProvider({ children }: MainProviderProps) {
|
||||||
const [searchValue, setSearchValue] = useState("");
|
const [searchValue, setSearchValue] = useState("");
|
||||||
const [selectedTerms, setSelectedTerms] = useState<SelectedTerms>({}); // 初始化状态
|
const [selectedTerms, setSelectedTerms] = useState<SelectedTerms>({}); // 初始化状态
|
||||||
|
|
||||||
|
const searchCondition: Prisma.PostWhereInput = useMemo(() => {
|
||||||
|
const containTextCondition: Prisma.StringNullableFilter = {
|
||||||
|
contains: searchValue,
|
||||||
|
mode: "insensitive" as Prisma.QueryMode, // 使用类型断言
|
||||||
|
};
|
||||||
|
return searchValue
|
||||||
|
? {
|
||||||
|
OR: [
|
||||||
|
{ title: containTextCondition },
|
||||||
|
{ subTitle: containTextCondition },
|
||||||
|
{ content: containTextCondition },
|
||||||
|
{
|
||||||
|
terms: {
|
||||||
|
some: {
|
||||||
|
name: containTextCondition,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
}, [searchValue]);
|
||||||
return (
|
return (
|
||||||
<MainContext.Provider
|
<MainContext.Provider
|
||||||
value={{
|
value={{
|
||||||
|
@ -25,6 +56,7 @@ export function MainProvider({ children }: MainProviderProps) {
|
||||||
setSearchValue,
|
setSearchValue,
|
||||||
selectedTerms,
|
selectedTerms,
|
||||||
setSelectedTerms,
|
setSelectedTerms,
|
||||||
|
searchCondition,
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</MainContext.Provider>
|
</MainContext.Provider>
|
||||||
|
|
Loading…
Reference in New Issue