From 12cbeccb05ce56562bc9b1207058e3532b7f01f9 Mon Sep 17 00:00:00 2001 From: Musa Khalid Date: Wed, 29 Jul 2026 22:29:39 +0100 Subject: [PATCH 1/2] feat: Enhance version control by reversing history and adding unique history IDs --- src/components/cms/VersionControl.tsx | 18 +++++++++--------- src/store/cmsStore.ts | 13 ++++++++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/components/cms/VersionControl.tsx b/src/components/cms/VersionControl.tsx index 45bca71b..632d008c 100644 --- a/src/components/cms/VersionControl.tsx +++ b/src/components/cms/VersionControl.tsx @@ -1,11 +1,12 @@ 'use client'; -import React from 'react'; +import React, { useMemo } from 'react'; import { useCMS } from '@/hooks/useCMS'; import { History, RotateCcw, Clock, CheckCircle2 } from 'lucide-react'; export const VersionControl: React.FC = () => { const { history, historyIndex, undo, redo, course } = useCMS(); + const reversedHistory = useMemo(() => history.slice().reverse(), [history]); return (
@@ -21,13 +22,13 @@ 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}`} + {isCurrent ? 'Current Version' : `Version ${originalIndex + 1}`}
@@ -81,8 +82,7 @@ export const VersionControl: React.FC = () => {
); - }) - .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); From bafe8e52971282b15f3fef611f3288c6b3d9602b Mon Sep 17 00:00:00 2001 From: Musa Khalid Date: Wed, 29 Jul 2026 22:29:49 +0100 Subject: [PATCH 2/2] feat: Improve version control UI by enhancing history display and interaction --- src/components/cms/VersionControl.tsx | 104 +++++++++++++------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/components/cms/VersionControl.tsx b/src/components/cms/VersionControl.tsx index 632d008c..05f29e2c 100644 --- a/src/components/cms/VersionControl.tsx +++ b/src/components/cms/VersionControl.tsx @@ -23,66 +23,66 @@ export const VersionControl: React.FC = () => {
{reversedHistory.map((snapshot, reversedIndex) => { - const originalIndex = history.length - 1 - reversedIndex; - const isCurrent = originalIndex === historyIndex; - const isPast = originalIndex < historyIndex; + const originalIndex = history.length - 1 - reversedIndex; + const isCurrent = originalIndex === historyIndex; + const isPast = originalIndex < historyIndex; - return ( -
-
+
+ }`} + /> -
-
-
- {isCurrent ? 'Current Version' : `Version ${originalIndex + 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 +
+ )}
- ); - })}{' '} +
+ ); + })}{' '} {/* Show newest first */}