Migrate layout

This commit is contained in:
2025-05-18 13:08:03 +02:00
parent a8a525531e
commit 834a7b1e7e
5 changed files with 50 additions and 25 deletions

View File

@@ -4,7 +4,7 @@ import UserMenu from '../navigation/UserMenu';
import WorkspaceSwitcher from '../navigation/WorkspaceSwitcher'; import WorkspaceSwitcher from '../navigation/WorkspaceSwitcher';
import WorkspaceSettings from '../settings/workspace/WorkspaceSettings'; import WorkspaceSettings from '../settings/workspace/WorkspaceSettings';
const Header = () => { const Header: React.FC = () => {
return ( return (
<Group justify="space-between" h={60} px="md"> <Group justify="space-between" h={60} px="md">
<Text fw={700} size="lg"> <Text fw={700} size="lg">

View File

@@ -7,7 +7,7 @@ import { useFileNavigation } from '../../hooks/useFileNavigation';
import { useFileList } from '../../hooks/useFileList'; import { useFileList } from '../../hooks/useFileList';
import { useWorkspace } from '../../contexts/WorkspaceContext'; import { useWorkspace } from '../../contexts/WorkspaceContext';
const Layout = () => { const Layout: React.FC = () => {
const { currentWorkspace, loading: workspaceLoading } = useWorkspace(); const { currentWorkspace, loading: workspaceLoading } = useWorkspace();
const { selectedFile, handleFileSelect } = useFileNavigation(); const { selectedFile, handleFileSelect } = useFileNavigation();
const { files, loadFileList } = useFileList(); const { files, loadFileList } = useFileList();

View File

@@ -10,11 +10,21 @@ import CommitMessageModal from '../modals/git/CommitMessageModal';
import { useFileContent } from '../../hooks/useFileContent'; import { useFileContent } from '../../hooks/useFileContent';
import { useFileOperations } from '../../hooks/useFileOperations'; import { useFileOperations } from '../../hooks/useFileOperations';
import { useGitOperations } from '../../hooks/useGitOperations'; import { useGitOperations } from '../../hooks/useGitOperations';
import { useWorkspace } from '../../contexts/WorkspaceContext';
const MainContent = ({ selectedFile, handleFileSelect, loadFileList }) => { type ViewTab = 'source' | 'preview';
const [activeTab, setActiveTab] = useState('source');
const { settings } = useWorkspace(); interface MainContentProps {
selectedFile: string | null;
handleFileSelect: (filePath: string | null) => Promise<void>;
loadFileList: () => Promise<void>;
}
const MainContent: React.FC<MainContentProps> = ({
selectedFile,
handleFileSelect,
loadFileList,
}) => {
const [activeTab, setActiveTab] = useState<ViewTab>('source');
const { const {
content, content,
hasUnsavedChanges, hasUnsavedChanges,
@@ -22,15 +32,17 @@ const MainContent = ({ selectedFile, handleFileSelect, loadFileList }) => {
handleContentChange, handleContentChange,
} = useFileContent(selectedFile); } = useFileContent(selectedFile);
const { handleSave, handleCreate, handleDelete } = useFileOperations(); const { handleSave, handleCreate, handleDelete } = useFileOperations();
const { handleCommitAndPush } = useGitOperations(settings.gitEnabled); const { handleCommitAndPush } = useGitOperations();
const handleTabChange = useCallback((value) => { const handleTabChange = useCallback((value: string | null): void => {
setActiveTab(value); if (value) {
setActiveTab(value as ViewTab);
}
}, []); }, []);
const handleSaveFile = useCallback( const handleSaveFile = useCallback(
async (filePath, content) => { async (filePath: string, fileContent: string): Promise<boolean> => {
let success = await handleSave(filePath, content); let success = await handleSave(filePath, fileContent);
if (success) { if (success) {
setHasUnsavedChanges(false); setHasUnsavedChanges(false);
} }
@@ -40,22 +52,22 @@ const MainContent = ({ selectedFile, handleFileSelect, loadFileList }) => {
); );
const handleCreateFile = useCallback( const handleCreateFile = useCallback(
async (fileName) => { async (fileName: string): Promise<void> => {
const success = await handleCreate(fileName); const success = await handleCreate(fileName);
if (success) { if (success) {
loadFileList(); await loadFileList();
handleFileSelect(fileName); await handleFileSelect(fileName);
} }
}, },
[handleCreate, handleFileSelect, loadFileList] [handleCreate, handleFileSelect, loadFileList]
); );
const handleDeleteFile = useCallback( const handleDeleteFile = useCallback(
async (filePath) => { async (filePath: string): Promise<void> => {
const success = await handleDelete(filePath); const success = await handleDelete(filePath);
if (success) { if (success) {
loadFileList(); await loadFileList();
handleFileSelect(null); await handleFileSelect(null);
} }
}, },
[handleDelete, handleFileSelect, loadFileList] [handleDelete, handleFileSelect, loadFileList]

View File

@@ -4,10 +4,23 @@ import FileActions from '../files/FileActions';
import FileTree from '../files/FileTree'; import FileTree from '../files/FileTree';
import { useGitOperations } from '../../hooks/useGitOperations'; import { useGitOperations } from '../../hooks/useGitOperations';
import { useWorkspace } from '../../contexts/WorkspaceContext'; import { useWorkspace } from '../../contexts/WorkspaceContext';
import { FileNode } from '@/types/fileApi';
const Sidebar = ({ selectedFile, handleFileSelect, files, loadFileList }) => { interface SidebarProps {
selectedFile: string | null;
handleFileSelect: (filePath: string | null) => Promise<void>;
files: FileNode[];
loadFileList: () => Promise<void>;
}
const Sidebar: React.FC<SidebarProps> = ({
selectedFile,
handleFileSelect,
files,
loadFileList,
}) => {
const { settings } = useWorkspace(); const { settings } = useWorkspace();
const { handlePull } = useGitOperations(settings.gitEnabled); const { handlePull } = useGitOperations();
useEffect(() => { useEffect(() => {
loadFileList(); loadFileList();
@@ -28,7 +41,7 @@ const Sidebar = ({ selectedFile, handleFileSelect, files, loadFileList }) => {
<FileTree <FileTree
files={files} files={files}
handleFileSelect={handleFileSelect} handleFileSelect={handleFileSelect}
showHiddenFiles={settings.showHiddenFiles} showHiddenFiles={settings.showHiddenFiles || false}
/> />
</Box> </Box>
); );

View File

@@ -5,7 +5,7 @@ import { useWorkspace } from '../contexts/WorkspaceContext';
interface UseGitOperationsResult { interface UseGitOperationsResult {
handlePull: () => Promise<boolean>; handlePull: () => Promise<boolean>;
handleCommitAndPush: (message: string) => Promise<boolean>; handleCommitAndPush: (message: string) => Promise<void>;
} }
export const useGitOperations = (): UseGitOperationsResult => { export const useGitOperations = (): UseGitOperationsResult => {
@@ -34,8 +34,8 @@ export const useGitOperations = (): UseGitOperationsResult => {
}, [currentWorkspace, settings.gitEnabled]); }, [currentWorkspace, settings.gitEnabled]);
const handleCommitAndPush = useCallback( const handleCommitAndPush = useCallback(
async (message: string): Promise<boolean> => { async (message: string): Promise<void> => {
if (!currentWorkspace || !settings.gitEnabled) return false; if (!currentWorkspace || !settings.gitEnabled) return;
try { try {
const commitHash: CommitHash = await commitAndPush( const commitHash: CommitHash = await commitAndPush(
@@ -47,7 +47,7 @@ export const useGitOperations = (): UseGitOperationsResult => {
message: 'Successfully committed and pushed changes', message: 'Successfully committed and pushed changes',
color: 'green', color: 'green',
}); });
return true; return;
} catch (error) { } catch (error) {
console.error('Failed to commit and push changes:', error); console.error('Failed to commit and push changes:', error);
notifications.show({ notifications.show({
@@ -55,7 +55,7 @@ export const useGitOperations = (): UseGitOperationsResult => {
message: 'Failed to commit and push changes', message: 'Failed to commit and push changes',
color: 'red', color: 'red',
}); });
return false; return;
} }
}, },
[currentWorkspace, settings.gitEnabled] [currentWorkspace, settings.gitEnabled]