Migrate hooks

This commit is contained in:
2024-10-10 21:12:37 +02:00
parent 76b4ed5d88
commit d29d402cf3
8 changed files with 105 additions and 131 deletions

View File

@@ -9,14 +9,11 @@
"version": "0.1.0", "version": "0.1.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.25.7",
"@codemirror/commands": "^6.6.2", "@codemirror/commands": "^6.6.2",
"@codemirror/lang-markdown": "^6.2.5", "@codemirror/lang-markdown": "^6.2.5",
"@codemirror/state": "^6.4.1", "@codemirror/state": "^6.4.1",
"@codemirror/theme-one-dark": "^6.1.2", "@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.34.0", "@codemirror/view": "^6.34.0",
"@geist-ui/core": "^2.3.8",
"@geist-ui/icons": "^1.0.2",
"@mantine/core": "^7.13.2", "@mantine/core": "^7.13.2",
"@mantine/hooks": "^7.13.2", "@mantine/hooks": "^7.13.2",
"@mantine/modals": "^7.13.2", "@mantine/modals": "^7.13.2",
@@ -2230,29 +2227,6 @@
"integrity": "sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==", "integrity": "sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@geist-ui/core": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/@geist-ui/core/-/core-2.3.8.tgz",
"integrity": "sha512-OKwGgTA4+fBM41eQbqDoUj4XBycZbYH7Ynrn6LPO5yKX7zeWPu/R7HN3vB4/oHt34VTDQI5sDNb1SirHvNyB5w==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.16.7"
},
"peerDependencies": {
"react": ">=16.9.0",
"react-dom": ">=16.9.0"
}
},
"node_modules/@geist-ui/icons": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@geist-ui/icons/-/icons-1.0.2.tgz",
"integrity": "sha512-Npfa0NW6fQ31qw/+iMPWbs1hAcJ/3FqBjSLYgEfITDqy/3TJFpFKeVyK04AC/hTmYTsdNruVYczqPNcham5FOQ==",
"license": "MIT",
"peerDependencies": {
"@geist-ui/core": ">=1.0.0",
"react": ">=16.13.0"
}
},
"node_modules/@jridgewell/gen-mapping": { "node_modules/@jridgewell/gen-mapping": {
"version": "0.3.5", "version": "0.3.5",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz",

View File

@@ -22,14 +22,11 @@
}, },
"homepage": "https://github.com/LordMathis/NovaMD#readme", "homepage": "https://github.com/LordMathis/NovaMD#readme",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.25.7",
"@codemirror/commands": "^6.6.2", "@codemirror/commands": "^6.6.2",
"@codemirror/lang-markdown": "^6.2.5", "@codemirror/lang-markdown": "^6.2.5",
"@codemirror/state": "^6.4.1", "@codemirror/state": "^6.4.1",
"@codemirror/theme-one-dark": "^6.1.2", "@codemirror/theme-one-dark": "^6.1.2",
"@codemirror/view": "^6.34.0", "@codemirror/view": "^6.34.0",
"@geist-ui/core": "^2.3.8",
"@geist-ui/icons": "^1.0.2",
"@mantine/core": "^7.13.2", "@mantine/core": "^7.13.2",
"@mantine/hooks": "^7.13.2", "@mantine/hooks": "^7.13.2",
"@mantine/modals": "^7.13.2", "@mantine/modals": "^7.13.2",

View File

@@ -1,5 +1,4 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { GeistProvider, CssBaseline } from '@geist-ui/core';
import { import {
MantineProvider, MantineProvider,
createTheme, createTheme,
@@ -29,8 +28,6 @@ function AppContent() {
} }
return ( return (
<GeistProvider themeType={settings.theme}>
<CssBaseline />
<MantineProvider theme={mantineTheme} defaultColorScheme={settings.theme}> <MantineProvider theme={mantineTheme} defaultColorScheme={settings.theme}>
<Notifications /> <Notifications />
<ModalsProvider> <ModalsProvider>
@@ -46,7 +43,6 @@ function AppContent() {
</AppShell> </AppShell>
</ModalsProvider> </ModalsProvider>
</MantineProvider> </MantineProvider>
</GeistProvider>
); );
} }

View File

@@ -108,26 +108,3 @@ $navbar-height: 64px;
.tree { .tree {
padding-top: $padding; 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;
}
}
}

View File

@@ -1,4 +1,4 @@
import { useState, useEffect, useCallback } from 'react'; import { useState, useCallback } from 'react';
import { fetchFileList } from '../services/api'; import { fetchFileList } from '../services/api';
export const useFileList = () => { export const useFileList = () => {

View File

@@ -1,11 +1,9 @@
import { useState, useCallback } from 'react'; import { useState, useCallback } from 'react';
import { useToasts } from '@geist-ui/core'; import { notifications } from '@mantine/notifications';
import { lookupFileByName } from '../services/api'; import { lookupFileByName } from '../services/api';
import { DEFAULT_FILE } from '../utils/constants'; import { DEFAULT_FILE } from '../utils/constants';
export const useFileNavigation = () => { export const useFileNavigation = () => {
const { setToast } = useToasts();
const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path); const [selectedFile, setSelectedFile] = useState(DEFAULT_FILE.path);
const [isNewFile, setIsNewFile] = useState(true); const [isNewFile, setIsNewFile] = useState(true);
@@ -21,17 +19,22 @@ export const useFileNavigation = () => {
if (filePaths.length >= 1) { if (filePaths.length >= 1) {
handleFileSelect(filePaths[0]); handleFileSelect(filePaths[0]);
} else { } else {
setToast({ text: `File "${filename}" not found`, type: 'error' }); notifications.show({
title: 'File Not Found',
message: `File "${filename}" not found`,
color: 'red',
});
} }
} catch (error) { } catch (error) {
console.error('Error looking up file:', error); console.error('Error looking up file:', error);
setToast({ notifications.show({
text: 'Failed to lookup file.', title: 'Error',
type: 'error', message: 'Failed to lookup file.',
color: 'red',
}); });
} }
}, },
[handleFileSelect, setToast] [handleFileSelect]
); );
return { handleLinkClick, selectedFile, isNewFile, handleFileSelect }; return { handleLinkClick, selectedFile, isNewFile, handleFileSelect };

View File

@@ -1,54 +1,67 @@
import { useCallback } from 'react'; import { useCallback } from 'react';
import { notifications } from '@mantine/notifications';
import { saveFileContent, deleteFile } from '../services/api'; import { saveFileContent, deleteFile } from '../services/api';
import { useToasts } from '@geist-ui/core';
export const useFileOperations = () => { export const useFileOperations = () => {
const { setToast } = useToasts(); const handleSave = useCallback(async (filePath, content) => {
const handleSave = useCallback(
async (filePath, content) => {
try { try {
await saveFileContent(filePath, content); await saveFileContent(filePath, content);
setToast({ text: 'File saved successfully', type: 'success' }); notifications.show({
title: 'Success',
message: 'File saved successfully',
color: 'green',
});
return true; return true;
} catch (error) { } catch (error) {
console.error('Error saving file:', error); console.error('Error saving file:', error);
setToast({ text: 'Failed to save file', type: 'error' }); notifications.show({
title: 'Error',
message: 'Failed to save file',
color: 'red',
});
return false; return false;
} }
}, }, []);
[setToast]
);
const handleDelete = useCallback( const handleDelete = useCallback(async (filePath) => {
async (filePath) => {
try { try {
await deleteFile(filePath); await deleteFile(filePath);
setToast({ text: 'File deleted successfully', type: 'success' }); notifications.show({
title: 'Success',
message: 'File deleted successfully',
color: 'green',
});
return true; return true;
} catch (error) { } catch (error) {
setToast({ text: `Error deleting file`, type: 'error' });
console.error('Error deleting file:', error); console.error('Error deleting file:', error);
notifications.show({
title: 'Error',
message: 'Failed to delete file',
color: 'red',
});
return false; return false;
} }
}, }, []);
[setToast]
);
const handleCreate = useCallback( const handleCreate = useCallback(async (fileName, initialContent = '') => {
async (fileName, initialContent = '') => {
try { try {
await saveFileContent(fileName, initialContent); await saveFileContent(fileName, initialContent);
setToast({ text: 'File created successfully', type: 'success' }); notifications.show({
title: 'Success',
message: 'File created successfully',
color: 'green',
});
return true; return true;
} catch (error) { } catch (error) {
setToast({ text: `Error creating new file`, type: 'error' });
console.error('Error creating new file:', error); console.error('Error creating new file:', error);
notifications.show({
title: 'Error',
message: 'Failed to create new file',
color: 'red',
});
return false; return false;
} }
}, }, []);
[setToast]
);
return { handleSave, handleDelete, handleCreate }; return { handleSave, handleDelete, handleCreate };
}; };

View File

@@ -1,4 +1,5 @@
import { useCallback } from 'react'; import { useCallback } from 'react';
import { notifications } from '@mantine/notifications';
import { pullChanges, commitAndPush } from '../services/api'; import { pullChanges, commitAndPush } from '../services/api';
export const useGitOperations = (gitEnabled) => { export const useGitOperations = (gitEnabled) => {
@@ -6,11 +7,19 @@ export const useGitOperations = (gitEnabled) => {
if (!gitEnabled) return false; if (!gitEnabled) return false;
try { try {
await pullChanges(); await pullChanges();
setToast({ text: 'Successfully pulled latest changes', type: 'success' }); notifications.show({
title: 'Success',
message: 'Successfully pulled latest changes',
color: 'green',
});
return true; return true;
} catch (error) { } catch (error) {
console.error('Failed to pull latest changes:', 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; return false;
} }
}, [gitEnabled]); }, [gitEnabled]);
@@ -20,14 +29,19 @@ export const useGitOperations = (gitEnabled) => {
if (!gitEnabled) return false; if (!gitEnabled) return false;
try { try {
await commitAndPush(message); await commitAndPush(message);
setToast({ notifications.show({
text: 'Successfully committed and pushed changes', title: 'Success',
type: 'success', message: 'Successfully committed and pushed changes',
color: 'green',
}); });
return true; return true;
} catch (error) { } catch (error) {
console.error('Failed to commit and push changes:', 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; return false;
} }
}, },