공지사항 삭제등록 등11
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { useState, useMemo, useEffect, useRef } from "react";
|
||||
import AdminSidebar from "@/app/components/AdminSidebar";
|
||||
import CourseRegistrationModal from "./CourseRegistrationModal";
|
||||
import ChevronDownSvg from "@/app/svgs/chevrondownsvg";
|
||||
@@ -31,6 +31,8 @@ export default function AdminCoursesPage() {
|
||||
const [editingCourse, setEditingCourse] = useState<Course | null>(null);
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [showToast, setShowToast] = useState(false);
|
||||
const prevModalOpenRef = useRef(false);
|
||||
const shouldRefreshRef = useRef(false);
|
||||
|
||||
// API에서 과목 리스트 가져오기
|
||||
useEffect(() => {
|
||||
@@ -70,35 +72,9 @@ export default function AdminCoursesPage() {
|
||||
}, [sortedCourses, currentPage]);
|
||||
|
||||
const handleSaveCourse = async (courseName: string, instructorName: string) => {
|
||||
if (editingCourse) {
|
||||
// 수정 모드 - TODO: API 호출로 변경 필요
|
||||
setCourses(prev => prev.map(course =>
|
||||
course.id === editingCourse.id
|
||||
? { ...course, courseName, instructorName }
|
||||
: course
|
||||
));
|
||||
} else {
|
||||
// 등록 모드 - TODO: API 호출로 변경 필요
|
||||
const newCourse: Course = {
|
||||
id: String(Date.now()),
|
||||
courseName,
|
||||
instructorName,
|
||||
createdAt: new Date().toISOString().split('T')[0],
|
||||
createdBy: '', // API에서 받아오도록 변경 필요
|
||||
hasLessons: false, // 기본값: 미포함
|
||||
};
|
||||
setCourses(prev => [...prev, newCourse]);
|
||||
}
|
||||
shouldRefreshRef.current = true; // 새로고침 플래그 설정
|
||||
setIsModalOpen(false);
|
||||
setEditingCourse(null);
|
||||
|
||||
// 저장 후 리스트 새로고침
|
||||
try {
|
||||
const data = await getCourses();
|
||||
setCourses(data);
|
||||
} catch (error) {
|
||||
console.error('과목 리스트 새로고침 오류:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleRowClick = (course: Course) => {
|
||||
@@ -117,25 +93,38 @@ export default function AdminCoursesPage() {
|
||||
};
|
||||
|
||||
const handleDeleteCourse = async () => {
|
||||
if (editingCourse) {
|
||||
// TODO: API 호출로 삭제 처리 필요
|
||||
setCourses(prev => prev.filter(course => course.id !== editingCourse.id));
|
||||
setEditingCourse(null);
|
||||
setShowToast(true);
|
||||
setTimeout(() => {
|
||||
setShowToast(false);
|
||||
}, 3000);
|
||||
|
||||
// 삭제 후 리스트 새로고침
|
||||
try {
|
||||
const data = await getCourses();
|
||||
setCourses(data);
|
||||
} catch (error) {
|
||||
console.error('과목 리스트 새로고침 오류:', error);
|
||||
}
|
||||
}
|
||||
shouldRefreshRef.current = true; // 새로고침 플래그 설정
|
||||
setEditingCourse(null);
|
||||
setShowToast(true);
|
||||
setTimeout(() => {
|
||||
setShowToast(false);
|
||||
}, 3000);
|
||||
};
|
||||
|
||||
// 모달이 닫힌 후 리스트 새로고침
|
||||
useEffect(() => {
|
||||
// 모달이 열렸다가 닫힐 때, 그리고 새로고침 플래그가 설정되어 있을 때만 새로고침
|
||||
if (prevModalOpenRef.current && !isModalOpen && shouldRefreshRef.current) {
|
||||
shouldRefreshRef.current = false; // 플래그 리셋
|
||||
|
||||
async function refreshList() {
|
||||
try {
|
||||
setIsLoading(true);
|
||||
const data = await getCourses();
|
||||
console.log('📋 [AdminCoursesPage] 새로고침된 데이터:', data);
|
||||
console.log('📋 [AdminCoursesPage] 새로고침된 데이터 개수:', data.length);
|
||||
setCourses(data);
|
||||
} catch (error) {
|
||||
console.error('과목 리스트 새로고침 오류:', error);
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
}
|
||||
refreshList();
|
||||
}
|
||||
prevModalOpenRef.current = isModalOpen;
|
||||
}, [isModalOpen]);
|
||||
|
||||
return (
|
||||
<div className="min-h-screen flex flex-col bg-white">
|
||||
{/* 메인 레이아웃 */}
|
||||
|
||||
Reference in New Issue
Block a user