@@ -21,68 +22,67 @@ export const VersionControl: React.FC = () => {
- {history
- .map((snapshot, index) => {
- const isCurrent = index === historyIndex;
- const isPast = index < historyIndex;
+ {reversedHistory.map((snapshot, reversedIndex) => {
+ const originalIndex = history.length - 1 - reversedIndex;
+ const isCurrent = originalIndex === historyIndex;
+ const isPast = originalIndex < historyIndex;
- return (
-
-
+
+ }`}
+ />
-
-
-
- {isCurrent ? 'Current Version' : `Version ${index + 1}`}
-
-
-
- Just now
-
+
+
+
+ {isCurrent ? 'Current Version' : `Version ${originalIndex + 1}`}
-
- {snapshot.modules.length} modules,{' '}
- {snapshot.modules.reduce((acc, m) => acc + m.lessons.length, 0)} lessons
-
+
+
+ Just now
+
+
+
+ {snapshot.modules.length} modules,{' '}
+ {snapshot.modules.reduce((acc, m) => acc + m.lessons.length, 0)} lessons
+
- {!isCurrent && (
-
- )}
+ {!isCurrent && (
+
+ )}
- {isCurrent && (
-
-
- Active
-
- )}
-
+ {isCurrent && (
+
+
+ Active
+
+ )}
- );
- })
- .reverse()}{' '}
+
+ );
+ })}{' '}
{/* Show newest first */}
diff --git a/src/store/cmsStore.ts b/src/store/cmsStore.ts
index 61662c9e..137e6747 100644
--- a/src/store/cmsStore.ts
+++ b/src/store/cmsStore.ts
@@ -2,9 +2,11 @@ import { create } from 'zustand';
import { persist, createJSONStorage } from 'zustand/middleware';
import { CMSCourse, MediaUploadTask, ContentTemplate } from '../types/cms';
+type CMSHistoryEntry = CMSCourse & { historyId: string };
+
interface CMSState {
course: CMSCourse;
- history: CMSCourse[];
+ history: CMSHistoryEntry[];
historyIndex: number;
mediaQueue: MediaUploadTask[];
templates: ContentTemplate[];
@@ -30,6 +32,11 @@ interface CMSState {
setTemplates: (templates: ContentTemplate[]) => void;
}
+const createHistoryEntry = (course: CMSCourse): CMSHistoryEntry => ({
+ ...course,
+ historyId: `history-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`,
+});
+
export const useCMSStore = create
()(
persist(
(set) => ({
@@ -48,7 +55,7 @@ export const useCMSStore = create()(
setCourse: (course) => {
set((state) => {
let newHistory = state.history.slice(0, state.historyIndex + 1);
- newHistory.push(course);
+ newHistory.push(createHistoryEntry(course));
if (newHistory.length > 20) {
newHistory = newHistory.slice(newHistory.length - 20);
@@ -67,7 +74,7 @@ export const useCMSStore = create()(
const updatedCourse = { ...state.course, ...updates };
let newHistory = state.history.slice(0, state.historyIndex + 1);
- newHistory.push(updatedCourse);
+ newHistory.push(createHistoryEntry(updatedCourse));
if (newHistory.length > 20) {
newHistory = newHistory.slice(newHistory.length - 20);