From 96351ac9ac23632e2ebc4e7f4288ecb7910a027b Mon Sep 17 00:00:00 2001 From: ditiqi Date: Thu, 27 Feb 2025 10:23:36 +0800 Subject: [PATCH] add --- .../courses/components/CoursesContainer.tsx | 22 +++------- apps/web/src/app/main/layout/MainHeader.tsx | 3 +- apps/web/src/app/main/layout/MainProvider.tsx | 22 ++++++++++ .../src/app/main/layout/NavigationMenu.tsx | 4 +- .../src/app/main/layout/UserMenu/UserMenu.tsx | 15 +------ .../components/MyDutyListContainer.tsx | 29 ++++++++++++ .../app/main/path/components/PathFilter.tsx | 44 ------------------- .../path/components/PathListContainer.tsx | 21 +-------- .../app/main/path/layout/PathListLayout.tsx | 4 +- 9 files changed, 66 insertions(+), 98 deletions(-) create mode 100644 apps/web/src/app/main/my-duty/components/MyDutyListContainer.tsx delete mode 100755 apps/web/src/app/main/path/components/PathFilter.tsx diff --git a/apps/web/src/app/main/courses/components/CoursesContainer.tsx b/apps/web/src/app/main/courses/components/CoursesContainer.tsx index 5f16cc1..847dbd3 100755 --- a/apps/web/src/app/main/courses/components/CoursesContainer.tsx +++ b/apps/web/src/app/main/courses/components/CoursesContainer.tsx @@ -5,30 +5,18 @@ import { useMemo } from "react"; import CourseCard from "./CourseCard"; export function CoursesContainer() { - const { selectedTerms, searchCondition } = useMainContext(); - const termFilters = useMemo(() => { - return Object.entries(selectedTerms) - .filter(([, terms]) => terms.length > 0) - .map(([, terms]) => terms); - }, [selectedTerms]); - + const {searchCondition, termsCondition } = useMainContext(); return ( <> } + renderItem={(post) => ( + + )} params={{ pageSize: 12, where: { type: PostType.COURSE, - AND: termFilters.map((termFilter) => ({ - terms: { - some: { - id: { - in: termFilter, // 确保至少有一个 term.id 在当前 termFilter 中 - }, - }, - }, - })), + ...termsCondition, ...searchCondition, }, }} diff --git a/apps/web/src/app/main/layout/MainHeader.tsx b/apps/web/src/app/main/layout/MainHeader.tsx index d6d288f..de0d1ce 100755 --- a/apps/web/src/app/main/layout/MainHeader.tsx +++ b/apps/web/src/app/main/layout/MainHeader.tsx @@ -43,7 +43,8 @@ export function MainHeader() { onPressEnter={(e) => { if ( !window.location.pathname.startsWith("/courses/") && - !window.location.pathname.startsWith("my") + !window.location.pathname.startsWith("/my") && + !window.location.pathname.startsWith("/path") ) { navigate(`/courses/`); window.scrollTo({ diff --git a/apps/web/src/app/main/layout/MainProvider.tsx b/apps/web/src/app/main/layout/MainProvider.tsx index 979d110..21d1a4a 100755 --- a/apps/web/src/app/main/layout/MainProvider.tsx +++ b/apps/web/src/app/main/layout/MainProvider.tsx @@ -16,6 +16,7 @@ interface MainContextType { setSearchValue?: React.Dispatch>; setSelectedTerms?: React.Dispatch>; searchCondition?: Prisma.PostWhereInput; + termsCondition?: Prisma.PostWhereInput; } const MainContext = createContext(null); @@ -26,7 +27,27 @@ interface MainProviderProps { export function MainProvider({ children }: MainProviderProps) { const [searchValue, setSearchValue] = useState(""); const [selectedTerms, setSelectedTerms] = useState({}); // 初始化状态 + const termFilters = useMemo(() => { + return Object.entries(selectedTerms) + .filter(([, terms]) => terms.length > 0) + ?.map(([, terms]) => terms); + }, [selectedTerms]); + const termsCondition: Prisma.PostWhereInput = useMemo(() => { + return termFilters && termFilters?.length > 0 + ? { + AND: termFilters.map((termFilter) => ({ + terms: { + some: { + id: { + in: termFilter, // 确保至少有一个 term.id 在当前 termFilter 中 + }, + }, + }, + })), + } + : {}; + }, [termFilters]); const searchCondition: Prisma.PostWhereInput = useMemo(() => { const containTextCondition: Prisma.StringNullableFilter = { contains: searchValue, @@ -57,6 +78,7 @@ export function MainProvider({ children }: MainProviderProps) { selectedTerms, setSelectedTerms, searchCondition, + termsCondition, }}> {children} diff --git a/apps/web/src/app/main/layout/NavigationMenu.tsx b/apps/web/src/app/main/layout/NavigationMenu.tsx index 63ab7d1..557dc2c 100755 --- a/apps/web/src/app/main/layout/NavigationMenu.tsx +++ b/apps/web/src/app/main/layout/NavigationMenu.tsx @@ -20,7 +20,8 @@ export const NavigationMenu = () => { return [ ...baseItems, { key: "my-duty", path: "/my-duty", label: "我创建的" }, - { key: "my-learning", path: "/my-learning", label: "我学习的" }, + { key: "my-learning", path: "/my-learning", label: "我的课表" }, + { key: "my-path", path: "/my-path", label: "我的路径" }, ]; } }, [isAuthenticated]); @@ -31,6 +32,7 @@ export const NavigationMenu = () => { { const selectedItem = menuItems.find((item) => item.key === key); diff --git a/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx b/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx index c25fc53..17c3413 100755 --- a/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx +++ b/apps/web/src/app/main/layout/UserMenu/UserMenu.tsx @@ -86,20 +86,7 @@ export function UserMenu() { setModalOpen(true); }, }, - { - icon: , - label: "我创建的课程", - action: () => { - navigate("/my-duty"); - }, - }, - { - icon: , - label: "我学习的课程", - action: () => { - navigate("/my-learning"); - }, - }, + canManageAnyStaff && { icon: , label: "设置", diff --git a/apps/web/src/app/main/my-duty/components/MyDutyListContainer.tsx b/apps/web/src/app/main/my-duty/components/MyDutyListContainer.tsx new file mode 100644 index 0000000..b1cd8e2 --- /dev/null +++ b/apps/web/src/app/main/my-duty/components/MyDutyListContainer.tsx @@ -0,0 +1,29 @@ +import PostList from "@web/src/components/models/course/list/PostList"; +import { useAuth } from "@web/src/providers/auth-provider"; + +import CourseCard from "../../courses/components/CourseCard"; +import { PostType } from "@nice/common"; +import { useMainContext } from "../../layout/MainProvider"; + +export default function MyDutyPage() { + const { user } = useAuth(); + const { searchCondition, termsCondition } = useMainContext(); + return ( + <> + ( + + )} + params={{ + pageSize: 12, + where: { + type: PostType.COURSE, + authorId: user.id, + ...termsCondition, + ...searchCondition, + }, + }} + cols={4}> + + ); +} diff --git a/apps/web/src/app/main/path/components/PathFilter.tsx b/apps/web/src/app/main/path/components/PathFilter.tsx deleted file mode 100755 index 01442c8..0000000 --- a/apps/web/src/app/main/path/components/PathFilter.tsx +++ /dev/null @@ -1,44 +0,0 @@ - -import { api } from "@nice/client"; -import { useMainContext } from "../../layout/MainProvider"; -import TermParentSelector from "@web/src/components/models/term/term-parent-selector"; - -export default function PathFilter() { - const { data: taxonomies } = api.taxonomy.getAll.useQuery({}); - const { selectedTerms, setSelectedTerms } = useMainContext(); - const handleTermChange = (slug: string, selected: string[]) => { - setSelectedTerms({ - ...selectedTerms, - [slug]: selected, // 更新对应 slug 的选择 - }); - }; - return ( -
- {taxonomies?.map((tax, index) => { - const items = Object.entries(selectedTerms).find( - ([key, items]) => key === tax.slug - )?.[1]; - return ( -
-

- {tax?.name} -

- - handleTermChange( - tax?.slug, - selected as string[] - ) - } - taxonomyId={tax?.id} - > - -
- ); - })} -
- ); -} diff --git a/apps/web/src/app/main/path/components/PathListContainer.tsx b/apps/web/src/app/main/path/components/PathListContainer.tsx index 12bf941..3c272bf 100755 --- a/apps/web/src/app/main/path/components/PathListContainer.tsx +++ b/apps/web/src/app/main/path/components/PathListContainer.tsx @@ -1,17 +1,9 @@ import PostList from "@web/src/components/models/course/list/PostList"; import { useMainContext } from "../../layout/MainProvider"; import { PostType, Prisma } from "@nice/common"; -import { useMemo } from "react"; import PathCard from "./PathCard"; - export function PathListContainer() { - const { searchValue, selectedTerms, searchCondition } = useMainContext(); - const termFilters = useMemo(() => { - return Object.entries(selectedTerms) - .filter(([, terms]) => terms.length > 0) - .map(([, terms]) => terms); - }, [selectedTerms]); - + const { searchCondition, termsCondition } = useMainContext(); return ( <> ({ - terms: { - some: { - id: { - in: termFilter, // 确保至少有一个 term.id 在当前 termFilter 中 - }, - }, - }, - })), + ...termsCondition, ...searchCondition, }, }} @@ -36,5 +20,4 @@ export function PathListContainer() { ); } - export default PathListContainer; diff --git a/apps/web/src/app/main/path/layout/PathListLayout.tsx b/apps/web/src/app/main/path/layout/PathListLayout.tsx index 88fcf59..855fcfe 100755 --- a/apps/web/src/app/main/path/layout/PathListLayout.tsx +++ b/apps/web/src/app/main/path/layout/PathListLayout.tsx @@ -1,5 +1,5 @@ import FilterSection from "../../courses/components/FilterSection"; -import PathFilter from "../components/PathFilter"; + import PathListContainer from "../components/PathListContainer"; export function PathListLayout() { @@ -9,7 +9,7 @@ export function PathListLayout() {
- {/* */} +