mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-06 07:54:22 +00:00
Migrate hooks
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import { GeistProvider, CssBaseline } from '@geist-ui/core';
|
||||
import {
|
||||
MantineProvider,
|
||||
createTheme,
|
||||
@@ -29,24 +28,21 @@ function AppContent() {
|
||||
}
|
||||
|
||||
return (
|
||||
<GeistProvider themeType={settings.theme}>
|
||||
<CssBaseline />
|
||||
<MantineProvider theme={mantineTheme} defaultColorScheme={settings.theme}>
|
||||
<Notifications />
|
||||
<ModalsProvider>
|
||||
<AppShell header={{ height: 60 }} padding="md">
|
||||
<AppShell.Header>
|
||||
<Header />
|
||||
</AppShell.Header>
|
||||
<AppShell.Main>
|
||||
<Container size="xl">
|
||||
<MainContent />
|
||||
</Container>
|
||||
</AppShell.Main>
|
||||
</AppShell>
|
||||
</ModalsProvider>
|
||||
</MantineProvider>
|
||||
</GeistProvider>
|
||||
<MantineProvider theme={mantineTheme} defaultColorScheme={settings.theme}>
|
||||
<Notifications />
|
||||
<ModalsProvider>
|
||||
<AppShell header={{ height: 60 }} padding="md">
|
||||
<AppShell.Header>
|
||||
<Header />
|
||||
</AppShell.Header>
|
||||
<AppShell.Main>
|
||||
<Container size="xl">
|
||||
<MainContent />
|
||||
</Container>
|
||||
</AppShell.Main>
|
||||
</AppShell>
|
||||
</ModalsProvider>
|
||||
</MantineProvider>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,26 +108,3 @@ $navbar-height: 64px;
|
||||
.tree {
|
||||
padding-top: $padding;
|
||||
}
|
||||
|
||||
// Geist UI Tree component customization
|
||||
:global {
|
||||
.file-tree {
|
||||
.label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.icon {
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.name {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.selected {
|
||||
color: #0070f3;
|
||||
font-weight: bold;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { fetchFileList } from '../services/api';
|
||||
|
||||
export const useFileList = () => {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useToasts } from '@geist-ui/core';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { lookupFileByName } from '../services/api';
|
||||
import { DEFAULT_FILE } from '../utils/constants';
|
||||
|
||||
export const useFileNavigation = () => {
|
||||
const { setToast } = useToasts();
|
||||
|
||||
const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path);
|
||||
const [isNewFile, setIsNewFile] = useState(true);
|
||||
|
||||
@@ -21,17 +19,22 @@ export const useFileNavigation = () => {
|
||||
if (filePaths.length >= 1) {
|
||||
handleFileSelect(filePaths[0]);
|
||||
} else {
|
||||
setToast({ text: `File "${filename}" not found`, type: 'error' });
|
||||
notifications.show({
|
||||
title: 'File Not Found',
|
||||
message: `File "${filename}" not found`,
|
||||
color: 'red',
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error looking up file:', error);
|
||||
setToast({
|
||||
text: 'Failed to lookup file.',
|
||||
type: 'error',
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Failed to lookup file.',
|
||||
color: 'red',
|
||||
});
|
||||
}
|
||||
},
|
||||
[handleFileSelect, setToast]
|
||||
[handleFileSelect]
|
||||
);
|
||||
|
||||
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };
|
||||
|
||||
@@ -1,54 +1,67 @@
|
||||
import { useCallback } from 'react';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { saveFileContent, deleteFile } from '../services/api';
|
||||
import { useToasts } from '@geist-ui/core';
|
||||
|
||||
export const useFileOperations = () => {
|
||||
const { setToast } = useToasts();
|
||||
const handleSave = useCallback(async (filePath, content) => {
|
||||
try {
|
||||
await saveFileContent(filePath, content);
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
message: 'File saved successfully',
|
||||
color: 'green',
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error saving file:', error);
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Failed to save file',
|
||||
color: 'red',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleSave = useCallback(
|
||||
async (filePath, content) => {
|
||||
try {
|
||||
await saveFileContent(filePath, content);
|
||||
setToast({ text: 'File saved successfully', type: 'success' });
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error saving file:', error);
|
||||
setToast({ text: 'Failed to save file', type: 'error' });
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[setToast]
|
||||
);
|
||||
const handleDelete = useCallback(async (filePath) => {
|
||||
try {
|
||||
await deleteFile(filePath);
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
message: 'File deleted successfully',
|
||||
color: 'green',
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error deleting file:', error);
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Failed to delete file',
|
||||
color: 'red',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleDelete = useCallback(
|
||||
async (filePath) => {
|
||||
try {
|
||||
await deleteFile(filePath);
|
||||
setToast({ text: 'File deleted successfully', type: 'success' });
|
||||
return true;
|
||||
} catch (error) {
|
||||
setToast({ text: `Error deleting file`, type: 'error' });
|
||||
console.error('Error deleting file:', error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[setToast]
|
||||
);
|
||||
|
||||
const handleCreate = useCallback(
|
||||
async (fileName, initialContent = '') => {
|
||||
try {
|
||||
await saveFileContent(fileName, initialContent);
|
||||
setToast({ text: 'File created successfully', type: 'success' });
|
||||
return true;
|
||||
} catch (error) {
|
||||
setToast({ text: `Error creating new file`, type: 'error' });
|
||||
console.error('Error creating new file:', error);
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[setToast]
|
||||
);
|
||||
const handleCreate = useCallback(async (fileName, initialContent = '') => {
|
||||
try {
|
||||
await saveFileContent(fileName, initialContent);
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
message: 'File created successfully',
|
||||
color: 'green',
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error creating new file:', error);
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Failed to create new file',
|
||||
color: 'red',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}, []);
|
||||
|
||||
return { handleSave, handleDelete, handleCreate };
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useCallback } from 'react';
|
||||
import { notifications } from '@mantine/notifications';
|
||||
import { pullChanges, commitAndPush } from '../services/api';
|
||||
|
||||
export const useGitOperations = (gitEnabled) => {
|
||||
@@ -6,11 +7,19 @@ export const useGitOperations = (gitEnabled) => {
|
||||
if (!gitEnabled) return false;
|
||||
try {
|
||||
await pullChanges();
|
||||
setToast({ text: 'Successfully pulled latest changes', type: 'success' });
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
message: 'Successfully pulled latest changes',
|
||||
color: 'green',
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to pull latest changes:', error);
|
||||
setToast({ text: 'Failed to pull latest changes', type: 'error' });
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Failed to pull latest changes',
|
||||
color: 'red',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
}, [gitEnabled]);
|
||||
@@ -20,14 +29,19 @@ export const useGitOperations = (gitEnabled) => {
|
||||
if (!gitEnabled) return false;
|
||||
try {
|
||||
await commitAndPush(message);
|
||||
setToast({
|
||||
text: 'Successfully committed and pushed changes',
|
||||
type: 'success',
|
||||
notifications.show({
|
||||
title: 'Success',
|
||||
message: 'Successfully committed and pushed changes',
|
||||
color: 'green',
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to commit and push changes:', error);
|
||||
setToast({ text: 'Failed to commit and push changes', type: 'error' });
|
||||
notifications.show({
|
||||
title: 'Error',
|
||||
message: 'Failed to commit and push changes',
|
||||
color: 'red',
|
||||
});
|
||||
return false;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user