add 2025-0122-2332
This commit is contained in:
parent
ce65bea0ed
commit
49ccc4d973
|
@ -68,6 +68,11 @@ export class PostRouter {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.postService.findById(input.id, input.args);
|
return await this.postService.findById(input.id, input.args);
|
||||||
}),
|
}),
|
||||||
|
findFirst: this.trpc.procedure
|
||||||
|
.input(PostFindFirstArgsSchema) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||||||
|
.query(async ({ input }) => {
|
||||||
|
return await this.postService.findFirst(input);
|
||||||
|
}),
|
||||||
deleteMany: this.trpc.protectProcedure
|
deleteMany: this.trpc.protectProcedure
|
||||||
.input(PostDeleteManyArgsSchema)
|
.input(PostDeleteManyArgsSchema)
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { PostDetailProvider } from "./context/PostDetailContext";
|
||||||
|
import PostDetailLayout from "./layout/PostDetailLayout";
|
||||||
|
|
||||||
|
export default function PostDetail({ id }: { id?: string }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<PostDetailProvider editId={id}>
|
||||||
|
<PostDetailLayout></PostDetailLayout>
|
||||||
|
</PostDetailProvider>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,54 +1,45 @@
|
||||||
import { api, usePost } from "@nice/client";
|
import { api, usePost } from "@nice/client";
|
||||||
import {} from "@nice/common";
|
import { Post } from "@nice/common";
|
||||||
import React, { createContext, ReactNode, useState } from "react";
|
import React, { createContext, ReactNode, useState } from "react";
|
||||||
import { string } from "zod";
|
import { string } from "zod";
|
||||||
|
|
||||||
interface PostDetailContextType {
|
interface PostDetailContextType {
|
||||||
editId?: string; // 添加 editId
|
editId?: string; // 添加 editId
|
||||||
course?: CourseDto;
|
post?: Post;
|
||||||
selectedLectureId?: string | undefined;
|
|
||||||
setSelectedLectureId?: React.Dispatch<React.SetStateAction<string>>;
|
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
isHeaderVisible: boolean; // 新增
|
|
||||||
setIsHeaderVisible: (visible: boolean) => void; // 新增
|
|
||||||
}
|
}
|
||||||
interface CourseFormProviderProps {
|
interface PostFormProviderProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
editId?: string; // 添加 editId 参数
|
editId?: string; // 添加 editId 参数
|
||||||
}
|
}
|
||||||
export const CourseDetailContext =
|
export const PostDetailContext = createContext<PostDetailContextType | null>(
|
||||||
createContext<PostDetailContextType | null>(null);
|
null
|
||||||
export function CourseDetailProvider({
|
);
|
||||||
|
export function PostDetailProvider({
|
||||||
children,
|
children,
|
||||||
editId,
|
editId,
|
||||||
}: CourseFormProviderProps) {
|
}: PostFormProviderProps) {
|
||||||
const { data: course, isLoading }: { data: CourseDto; isLoading: boolean } =
|
const { data: post, isLoading }: { data: Post; isLoading: boolean } = (
|
||||||
api.course.findFirst.useQuery(
|
api.post.findFirst as any
|
||||||
|
).useQuery(
|
||||||
{
|
{
|
||||||
where: { id: editId },
|
where: { id: editId },
|
||||||
include: {
|
|
||||||
sections: { include: { lectures: true } },
|
|
||||||
enrollments: true,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{ enabled: Boolean(editId) }
|
{ enabled: Boolean(editId) }
|
||||||
);
|
);
|
||||||
const [selectedLectureId, setSelectedLectureId] = useState<
|
// const {}:{} =(
|
||||||
string | undefined
|
// api.post.fin as any
|
||||||
>(undefined);
|
// )
|
||||||
const [isHeaderVisible, setIsHeaderVisible] = useState(true); // 新增
|
|
||||||
return (
|
return (
|
||||||
<CourseDetailContext.Provider
|
<PostDetailContext.Provider
|
||||||
value={{
|
value={{
|
||||||
editId,
|
editId,
|
||||||
course,
|
post,
|
||||||
selectedLectureId,
|
|
||||||
setSelectedLectureId,
|
|
||||||
isLoading,
|
isLoading,
|
||||||
isHeaderVisible,
|
|
||||||
setIsHeaderVisible,
|
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</CourseDetailContext.Provider>
|
</PostDetailContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { motion } from "framer-motion";
|
||||||
|
import { useContext } from "react";
|
||||||
|
import { PostDetailContext } from "../context/PostDetailContext";
|
||||||
|
|
||||||
|
export default function PostDetailLayout() {
|
||||||
|
const { post } = useContext(PostDetailContext);
|
||||||
|
|
||||||
|
return <div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>;
|
||||||
|
}
|
Loading…
Reference in New Issue