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