Skip to content

Commit d9a8e83

Browse files
author
Lauritz Wiebusch
committed
final push
1 parent 5029162 commit d9a8e83

2 files changed

Lines changed: 123 additions & 28 deletions

File tree

src/layouts/DetailsLayout.jsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { useFileSystem } from '../providers/FileSystemProvider';
33
import DetailsPanel from '../components/explorer/DetailsPanel';
44
import './detailsLayout.css';
55

6+
/**
7+
* DetailsLayout component that provides a resizable details panel.
8+
* This component renders a main content area alongside a resizable details panel.
9+
*
10+
* @param {Object} props - Component props
11+
* @param {React.ReactNode} props.children - Child components to render in the main content area
12+
* @returns {JSX.Element} The DetailsLayout component
13+
*/
614
const DetailsLayout = ({ children }) => {
715
const { selectedItems } = useFileSystem();
816
const [panelWidth, setPanelWidth] = useState(300); // Default width
@@ -11,7 +19,12 @@ const DetailsLayout = ({ children }) => {
1119
const startXRef = useRef(0);
1220
const startWidthRef = useRef(0);
1321

14-
// Handle resize start
22+
/**
23+
* Handles the start of a resize operation.
24+
* Sets up necessary state and styles for resizing.
25+
*
26+
* @param {React.MouseEvent} e - The mouse down event
27+
*/
1528
const handleResizeStart = (e) => {
1629
setIsResizing(true);
1730
startXRef.current = e.clientX;
@@ -22,8 +35,16 @@ const DetailsLayout = ({ children }) => {
2235
document.body.style.cursor = 'col-resize';
2336
};
2437

25-
// Handle resize during mouse move
38+
/**
39+
* Effect hook to handle resizing operations.
40+
* Adds event listeners for mouse movements and cleanup.
41+
*/
2642
useEffect(() => {
43+
/**
44+
* Handles resize calculations during mouse movement.
45+
*
46+
* @param {MouseEvent} e - The mouse move event
47+
*/
2748
const handleResize = (e) => {
2849
if (!isResizing) return;
2950

@@ -37,6 +58,10 @@ const DetailsLayout = ({ children }) => {
3758
setPanelWidth(newWidth);
3859
};
3960

61+
/**
62+
* Handles the end of a resize operation.
63+
* Resets styles and state.
64+
*/
4065
const handleResizeEnd = () => {
4166
setIsResizing(false);
4267
document.body.style.userSelect = '';

src/layouts/MainLayout.jsx

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ import SettingsApplier from '../utils/SettingsApplier.js';
3737
import '../styles/layouts/mainLayout.css';
3838
import {replaceFileName} from "../utils/pathUtils.js";
3939

40+
/**
41+
* MainLayout component that serves as the primary layout structure for the application.
42+
* Manages UI state, event handling, and renders the main application interface.
43+
*
44+
* @returns {JSX.Element} The MainLayout component
45+
*/
4046
const MainLayout = () => {
4147
const { theme, toggleTheme } = useTheme();
4248
const { isLoading, currentDirData, selectedItems, loadDirectory, volumes } = useFileSystem();
@@ -67,81 +73,118 @@ const MainLayout = () => {
6773
// Get terminal height for padding calculations
6874
const terminalHeight = settings.terminal_height || 240;
6975

70-
// Update UI state when settings change
76+
/**
77+
* Effect to update UI state when settings change
78+
*/
7179
useEffect(() => {
7280
if (settings.show_details_panel !== undefined) {
7381
setIsDetailsPanelOpen(settings.show_details_panel);
7482
}
7583
}, [settings.show_details_panel]);
7684

85+
/**
86+
* Effect to update view mode when settings change
87+
*/
7788
useEffect(() => {
7889
if (settings.default_view) {
7990
setViewMode(settings.default_view);
8091
}
8192
}, [settings.default_view]);
8293

83-
// Load default location on first render
94+
/**
95+
* Effect to load default location on first render
96+
*/
8497
useEffect(() => {
8598
if (volumes.length > 0 && !currentDirData && !currentPath) {
8699
// Show This PC view by default
87100
setCurrentView('this-pc');
88101
}
89102
}, [volumes, currentDirData, currentPath]);
90103

91-
// Listen for custom events - VERBESSERT MIT DEBUG
104+
/**
105+
* Effect to listen for custom events
106+
* Improved with debug information
107+
*/
92108
useEffect(() => {
109+
/**
110+
* Handler for opening templates view
111+
*/
93112
const handleOpenTemplates = () => {
94113
setCurrentView('templates');
95114
setIsTemplatesOpen(true);
96115
};
97116

117+
/**
118+
* Handler for showing properties panel
119+
*/
98120
const handleShowProperties = (e) => {
99121
setIsDetailsPanelOpen(true);
100122
};
101123

124+
/**
125+
* Handler for opening This PC view
126+
*/
102127
const handleOpenThisPC = () => {
103128
setCurrentView('this-pc');
104129
};
105130

131+
/**
132+
* Handler for opening settings panel
133+
*/
106134
const handleOpenSettings = () => {
107135
setIsSettingsOpen(true);
108136
};
109137

138+
/**
139+
* Handler for toggling terminal visibility
140+
*/
110141
const handleToggleTerminal = () => {
111142
setIsTerminalOpen(prev => !prev);
112143
};
113144

145+
/**
146+
* Handler for opening rename modal
147+
* @param {CustomEvent} e - Event with item details
148+
*/
114149
const handleOpenRenameModal = (e) => {
115150
if (e.detail && e.detail.item) {
116151
setRenameItem(e.detail.item);
117152
setIsRenameModalOpen(true);
118153
}
119154
};
120155

121-
// VERBESSERTE HASH EVENT HANDLERS MIT DEBUG
156+
// Improved hash event handlers with debug information
157+
/**
158+
* Handler for opening hash file modal
159+
* @param {CustomEvent} e - Event with item details
160+
*/
122161
const handleOpenHashFileModal = (e) => {
123-
console.log('🎯 MainLayout: Received open-hash-file-modal event:', e.detail);
162+
console.log('MainLayout: Received open-hash-file-modal event:', e.detail);
124163
if (e.detail && e.detail.item) {
125-
console.log('Opening Hash File Modal for:', e.detail.item.name);
164+
console.log('Opening Hash File Modal for:', e.detail.item.name);
126165
setHashModalItem(e.detail.item);
127166
setIsHashFileModalOpen(true);
128167
} else {
129-
console.log('Invalid event detail:', e.detail);
168+
console.log('Invalid event detail:', e.detail);
130169
}
131170
};
132171

172+
/**
173+
* Handler for opening hash compare modal
174+
* @param {CustomEvent} e - Event with item details
175+
*/
133176
const handleOpenHashCompareModal = (e) => {
134-
console.log('🎯 MainLayout: Received open-hash-compare-modal event:', e.detail);
177+
console.log('MainLayout: Received open-hash-compare-modal event:', e.detail);
135178
if (e.detail && e.detail.item) {
136-
console.log('Opening Hash Compare Modal for:', e.detail.item.name);
179+
console.log('Opening Hash Compare Modal for:', e.detail.item.name);
137180
setHashModalItem(e.detail.item);
138181
setIsHashCompareModalOpen(true);
139182
} else {
140-
console.log('Invalid event detail:', e.detail);
183+
console.log('Invalid event detail:', e.detail);
141184
}
142185
};
143186

144-
// Event Listeners registrieren
187+
// Register event listeners
145188
document.addEventListener('open-templates', handleOpenTemplates);
146189
document.addEventListener('show-properties', handleShowProperties);
147190
document.addEventListener('open-this-pc', handleOpenThisPC);
@@ -151,7 +194,7 @@ const MainLayout = () => {
151194
document.addEventListener('open-hash-file-modal', handleOpenHashFileModal);
152195
document.addEventListener('open-hash-compare-modal', handleOpenHashCompareModal);
153196

154-
console.log('📥 MainLayout: All event listeners registered');
197+
console.log('MainLayout: All event listeners registered');
155198

156199
return () => {
157200
document.removeEventListener('open-templates', handleOpenTemplates);
@@ -162,18 +205,23 @@ const MainLayout = () => {
162205
document.removeEventListener('open-rename-modal', handleOpenRenameModal);
163206
document.removeEventListener('open-hash-file-modal', handleOpenHashFileModal);
164207
document.removeEventListener('open-hash-compare-modal', handleOpenHashCompareModal);
165-
console.log('📤 MainLayout: All event listeners removed');
208+
console.log('MainLayout: All event listeners removed');
166209
};
167210
}, []);
168211

169-
// Switch to explorer view when navigating to a directory
212+
/**
213+
* Effect to switch to explorer view when navigating to a directory
214+
*/
170215
useEffect(() => {
171216
if (currentPath && currentView !== 'explorer') {
172217
setCurrentView('explorer');
173218
}
174219
}, [currentPath]);
175220

176-
// Handle search
221+
/**
222+
* Handles search functionality
223+
* @param {string} value - The search query
224+
*/
177225
const handleSearch = useCallback((value) => {
178226
setSearchValue(value);
179227

@@ -199,8 +247,14 @@ const MainLayout = () => {
199247
}
200248
}, [currentDirData]);
201249

202-
// Handle keyboard shortcuts
250+
/**
251+
* Effect to handle keyboard shortcuts
252+
*/
203253
useEffect(() => {
254+
/**
255+
* Keyboard event handler for shortcuts
256+
* @param {KeyboardEvent} e - The keyboard event
257+
*/
204258
const handleKeyDown = (e) => {
205259
// Global search: Ctrl+Shift+F
206260
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key === 'F') {
@@ -250,7 +304,9 @@ const MainLayout = () => {
250304
return () => document.removeEventListener('keydown', handleKeyDown);
251305
}, [selectedItems]);
252306

253-
// Copy current path to clipboard
307+
/**
308+
* Copies current path to clipboard
309+
*/
254310
const copyCurrentPath = useCallback(async () => {
255311
if (!currentPath) return;
256312

@@ -279,11 +335,15 @@ const MainLayout = () => {
279335
}
280336
}, [currentPath]);
281337

282-
// Handle rename
338+
/**
339+
* Handles renaming a file or directory
340+
* @param {Object} item - The item to rename
341+
* @param {string} newName - The new name
342+
*/
283343
const handleRename = async (item, newName) => {
284344
if (!newName || newName === item.name) return;
285345

286-
console.log(`!!! Renaming "${replaceFileName(item.path, newName)}"`);
346+
console.log(`Renaming "${replaceFileName(item.path, newName)}"`);
287347

288348
try {
289349
const separator = item.path.includes('\\') ? '\\' : '/';
@@ -322,7 +382,10 @@ const MainLayout = () => {
322382
}
323383
};
324384

325-
// Handle view mode change with settings persistence
385+
/**
386+
* Handles view mode change with settings persistence
387+
* @param {string} newMode - The new view mode
388+
*/
326389
const handleViewModeChange = useCallback(async (newMode) => {
327390
setViewMode(newMode);
328391

@@ -334,7 +397,9 @@ const MainLayout = () => {
334397
}
335398
}, []);
336399

337-
// Handle details panel toggle with settings persistence
400+
/**
401+
* Handles details panel toggle with settings persistence
402+
*/
338403
const handleDetailsPanelToggle = useCallback(async () => {
339404
const newState = !isDetailsPanelOpen;
340405
setIsDetailsPanelOpen(newState);
@@ -347,7 +412,9 @@ const MainLayout = () => {
347412
}
348413
}, [isDetailsPanelOpen]);
349414

350-
// Clear search when changing directory
415+
/**
416+
* Effect to clear search when changing directory
417+
*/
351418
useEffect(() => {
352419
setSearchValue('');
353420
setSearchResults(null);
@@ -356,7 +423,10 @@ const MainLayout = () => {
356423
// Get the data to display
357424
const displayData = searchResults || currentDirData;
358425

359-
// Render main content based on current view
426+
/**
427+
* Renders the main content based on current view
428+
* @returns {JSX.Element} The main content component
429+
*/
360430
const renderMainContent = () => {
361431
switch (currentView) {
362432
case 'this-pc':
@@ -512,11 +582,11 @@ const MainLayout = () => {
512582
onRename={handleRename}
513583
/>
514584

515-
{/* Hash Modals - MIT DEBUG */}
585+
{/* Hash Modals - with debug info */}
516586
<HashFileModal
517587
isOpen={isHashFileModalOpen}
518588
onClose={() => {
519-
console.log('🔴 Closing Hash File Modal');
589+
console.log('Closing Hash File Modal');
520590
setIsHashFileModalOpen(false);
521591
setHashModalItem(null);
522592
}}
@@ -526,7 +596,7 @@ const MainLayout = () => {
526596
<HashCompareModal
527597
isOpen={isHashCompareModalOpen}
528598
onClose={() => {
529-
console.log('🔴 Closing Hash Compare Modal');
599+
console.log('Closing Hash Compare Modal');
530600
setIsHashCompareModalOpen(false);
531601
setHashModalItem(null);
532602
}}

0 commit comments

Comments
 (0)