mirror of
https://github.com/Since-3/Kuma.git
synced 2026-10-12 21:41:17 +00:00
see comments
This commit is contained in:
parent
0ff9df8e16
commit
ba2e39b37e
4 changed files with 22 additions and 8 deletions
|
|
@ -54,7 +54,7 @@ const RichTextEditor: React.FC<RichTextEditorProps> = ({
|
|||
// Sync editor content when value prop changes (for edit mode)
|
||||
useEffect(() => {
|
||||
if (editor && value !== editor.getHTML()) {
|
||||
editor.commands.setContent(value);
|
||||
editor.commands.setContent(value, { emitUpdate: false });
|
||||
}
|
||||
}, [editor, value]);
|
||||
|
||||
|
|
|
|||
|
|
@ -348,6 +348,7 @@ export async function updateCourse(
|
|||
|
||||
// Schritt 9: Next.js Cache für /courses Seite invalidieren
|
||||
revalidatePath("/courses");
|
||||
revalidatePath(`/courses/edit/${courseId}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
|
|
|
|||
|
|
@ -90,7 +90,11 @@ const CourseCreateView = ({
|
|||
// Format date for input field (YYYY-MM-DD)
|
||||
if (initialData.date) {
|
||||
const date = new Date(initialData.date);
|
||||
const formattedDate = date.toISOString().split("T")[0];
|
||||
const formattedDate = [
|
||||
date.getFullYear(),
|
||||
String(date.getMonth() + 1).padStart(2, "0"),
|
||||
String(date.getDate()).padStart(2, "0"),
|
||||
].join("-");
|
||||
setCourseDate(formattedDate);
|
||||
}
|
||||
|
||||
|
|
@ -159,9 +163,13 @@ const CourseCreateView = ({
|
|||
weekdays: selectedWeekdays.length > 0 ? selectedWeekdays : undefined,
|
||||
};
|
||||
|
||||
if (mode === "edit" && !courseId) {
|
||||
throw new Error("Missing courseId in edit mode");
|
||||
}
|
||||
|
||||
const result =
|
||||
mode === "edit" && courseId
|
||||
? await updateCourse(courseId, courseData, status)
|
||||
mode === "edit"
|
||||
? await updateCourse(courseId!, courseData, status)
|
||||
: await createCourse(courseData, status);
|
||||
|
||||
if (result.success) {
|
||||
|
|
|
|||
|
|
@ -16,20 +16,25 @@ const CourseEditView = ({ courseId }: CourseEditViewProps) => {
|
|||
const [courseData, setCourseData] = useState<Course | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
|
||||
const fetchCourse = async () => {
|
||||
setIsLoading(true);
|
||||
if (alive) setIsLoading(true);
|
||||
const result = await getCourseById(courseId);
|
||||
|
||||
if (result.success && result.course) {
|
||||
setCourseData(result.course);
|
||||
if (alive) setCourseData(result.course);
|
||||
} else {
|
||||
toast.error(result.error || "Fehler beim Laden des Kurses");
|
||||
router.push("/courses/myCourses");
|
||||
router.push("/courses");
|
||||
}
|
||||
setIsLoading(false);
|
||||
if (alive) setIsLoading(false);
|
||||
};
|
||||
|
||||
fetchCourse();
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [courseId, router]);
|
||||
|
||||
if (isLoading) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue