add
This commit is contained in:
parent
cf3e242462
commit
3e160b49e7
|
@ -34,7 +34,7 @@ const CourseContentForm: React.FC = () => {
|
|||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
})
|
||||
);
|
||||
const { softDeleteByIds } = usePost();
|
||||
const { softDeleteByIds, updateOrderByIds } = usePost();
|
||||
const { data: sections = [], isLoading } = api.post.findMany.useQuery(
|
||||
{
|
||||
where: {
|
||||
|
@ -60,11 +60,15 @@ const CourseContentForm: React.FC = () => {
|
|||
const handleDragEnd = (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
if (!over || active.id === over.id) return;
|
||||
|
||||
let newItems = [];
|
||||
setItems((items) => {
|
||||
const oldIndex = items.findIndex((item) => item.id === active.id);
|
||||
const newIndex = items.findIndex((item) => item.id === over.id);
|
||||
return arrayMove(items, oldIndex, newIndex);
|
||||
newItems = arrayMove(items, oldIndex, newIndex);
|
||||
return newItems;
|
||||
});
|
||||
updateOrderByIds.mutateAsync({
|
||||
ids: newItems.map((item) => item.id),
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -112,7 +116,7 @@ const CourseContentForm: React.FC = () => {
|
|||
className="mt-4"
|
||||
onClick={() => {
|
||||
if (items.some((item) => item.id === null)) {
|
||||
toast.error("请先保存当前编辑章节");
|
||||
toast.error("请先保存当前编辑的章节");
|
||||
} else {
|
||||
setItems([...items, { id: null, title: "" }]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue