From 77f8e844f7580a5ebff565ab617ddbdde51ef958 Mon Sep 17 00:00:00 2001 From: SujalTripathi Date: Sun, 5 Oct 2025 17:02:19 +0530 Subject: [PATCH] feat: Add Step Explanation UI to String Visualizer Adds the Step Explanation component to the String Visualizer page, completing the UI as discussed in issue #42. --- frontend/src/App.js | 11 +-- .../components/Sorting/ComplexityDisplay.jsx | 2 +- frontend/src/pages/StringVisualizer.jsx | 98 +++++++++++++------ 3 files changed, 73 insertions(+), 38 deletions(-) diff --git a/frontend/src/App.js b/frontend/src/App.js index 3eb8d47..af17f69 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -62,14 +62,9 @@ const AppContent = () => { path="*" element={} /> - } - /> - } - /> + } /> + } /> + diff --git a/frontend/src/components/Sorting/ComplexityDisplay.jsx b/frontend/src/components/Sorting/ComplexityDisplay.jsx index fbcb7a3..b4b33fd 100644 --- a/frontend/src/components/Sorting/ComplexityDisplay.jsx +++ b/frontend/src/components/Sorting/ComplexityDisplay.jsx @@ -33,7 +33,7 @@ const ComplexityDisplay = ({ algorithm, currentData, steps }) => {
Steps: - {steps.length} + {steps?.length || 0}
diff --git a/frontend/src/pages/StringVisualizer.jsx b/frontend/src/pages/StringVisualizer.jsx index f771049..73038ee 100644 --- a/frontend/src/pages/StringVisualizer.jsx +++ b/frontend/src/pages/StringVisualizer.jsx @@ -1,12 +1,21 @@ import React, { useState } from 'react'; -import { useTheme } from '../contexts/ThemeContext'; // Use the project's theme system -import { Play, RotateCcw, Text, Hash } from 'lucide-react'; +// STEP 1: Add 'BookOpen' to the import list +import { Play, RotateCcw, Text, Hash, BookOpen } from 'lucide-react'; +import { useTheme } from '../contexts/ThemeContext'; const StringVisualizer = () => { - const { classes } = useTheme(); // Get the theme classes + const { isDark } = useTheme(); const [text, setText] = useState('ababcabcabababd'); const [pattern, setPattern] = useState('abababd'); + // STEP 2: Add the new state for the explanation text + const [showDetailedLog, setShowDetailedLog] = useState(false); + const [explanation, setExplanation] = useState({ + operation: 'Ready to start.', + details: 'Enter text and a pattern, then click Visualize to begin the process.', + algorithmInfo: 'The Naive (or Brute-Force) search algorithm checks for a match at every possible position in the text.' + }); + const handleVisualize = () => console.log('Visualize clicked!', { text, pattern }); const handleReset = () => { setText(''); @@ -15,9 +24,8 @@ const StringVisualizer = () => { }; return ( - // Use the theme's background class -
- {/* Spacer div */} +
+ {/* Spacer to push content down from the main site navigation */}
{/* 1. Gradient Header Card */} @@ -32,16 +40,16 @@ const StringVisualizer = () => {
- {/* 2. Left Column: Inputs & Controls Card */} -
-
-

+ {/* 2. Left Column: Contains both cards now */} +
+ {/* Inputs & Controls Card */} +
+

Inputs & Controls

-
-
-
-
-
+ + {/* Step Explanation Card */} +
+
+
+

+ + Step Explanation +

+ +
+
+
+
+

Current Operation:

+

{explanation.operation}

+
+
+

What's Happening:

+

{explanation.details}

+
+
+

+ Algorithm Info: +

+

+ {explanation.algorithmInfo} +

+
+
+
{/* 3. Right Column: Display Area Card */}
-
-

+
+

Visualization

-
-

Text

-
+

Text

+
{text.split('').map((char, index) => (
-
+
{char}
- {index} + {index}
))}
-
-

Pattern

-
+

Pattern

+
{pattern.split('').map((char, index) => (
-
+
{char}
- {index} + {index}
))}