mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
add more things
This commit is contained in:
@@ -29,7 +29,7 @@ export default function CoursesTable() {
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { courses, attributes, pagination, setPagination, loading, fetchCourses, archiveCourse, archiveCourses, fetchCourseFieldValues } = useCourses();
|
||||
const { courses, attributes, pagination, setPagination, loading, fetchCourses, reorderCourses, archiveCourse, archiveCourses, fetchCourseFieldValues } = useCourses();
|
||||
|
||||
const handleRefsReady = (refs) => {
|
||||
tableRefsRef.current = refs;
|
||||
@@ -42,14 +42,31 @@ export default function CoursesTable() {
|
||||
sheetName: "Courses",
|
||||
};
|
||||
|
||||
const rowActions = useMemo(() => buildRowActions({
|
||||
// Reorder — swaps this row with its neighbor in the currently displayed
|
||||
// (order_index-sorted) list, then persists the new order_index set.
|
||||
const handleMove = async (row, direction) => {
|
||||
const idx = courses.findIndex((c) => c.course_id === row.course_id);
|
||||
const swapIdx = idx + direction;
|
||||
if (idx < 0 || swapIdx < 0 || swapIdx >= courses.length) return;
|
||||
|
||||
const reordered = [...courses];
|
||||
[reordered[idx], reordered[swapIdx]] = [reordered[swapIdx], reordered[idx]];
|
||||
|
||||
const ok = await reorderCourses(reordered.map((c) => c.course_id));
|
||||
if (ok) fetchCourses({ page: 1, limit: pagination?.limit ?? 10 });
|
||||
};
|
||||
|
||||
const rowActions = buildRowActions({
|
||||
onViewAssessment: (row) => navigate(`/admin/courses/${row.course_id}/assessment/view`),
|
||||
onAssessment: (row) => navigate(`/admin/courses/${row.course_id}/assessment`),
|
||||
onViewUnits: (row) => navigate(`/admin/courses/${row.course_id}/units`),
|
||||
onView: (row) => navigate(`/admin/courses/${row.course_id}/view`),
|
||||
onEdit: (row) => navigate(`/admin/courses/${row.course_id}/edit`),
|
||||
onArchive: (row) => setArchiveTarget(row),
|
||||
}), []);
|
||||
onMoveUp: (row) => handleMove(row, -1),
|
||||
onMoveDown: (row) => handleMove(row, 1),
|
||||
courses,
|
||||
});
|
||||
|
||||
const toolbarActions = buildToolbarActions({
|
||||
fetchCourses,
|
||||
@@ -70,7 +87,7 @@ export default function CoursesTable() {
|
||||
|
||||
const columns = useMemo(
|
||||
() => buildDataColumns(attributes, rowActions),
|
||||
[attributes]
|
||||
[attributes, rowActions]
|
||||
);
|
||||
|
||||
const handleArchiveSuccess = () => {
|
||||
|
||||
Reference in New Issue
Block a user