mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Refactor WorkspaceDataContext and useFileOperations to remove settings
This commit is contained in:
@@ -126,7 +126,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
expect(result.current.currentWorkspace).toBeNull();
|
expect(result.current.currentWorkspace).toBeNull();
|
||||||
expect(result.current.loading).toBe(true);
|
expect(result.current.loading).toBe(true);
|
||||||
expect(result.current.workspaces).toEqual([]);
|
expect(result.current.workspaces).toEqual([]);
|
||||||
expect(result.current.settings).toEqual(DEFAULT_WORKSPACE_SETTINGS);
|
|
||||||
|
|
||||||
await waitFor(() => {
|
await waitFor(() => {
|
||||||
expect(result.current.loading).toBe(false);
|
expect(result.current.loading).toBe(false);
|
||||||
@@ -171,7 +170,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
|
|
||||||
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
||||||
expect(result.current.workspaces).toEqual(mockWorkspaceList);
|
expect(result.current.workspaces).toEqual(mockWorkspaceList);
|
||||||
expect(result.current.settings).toEqual(mockWorkspace);
|
|
||||||
expect(mockGetLastWorkspaceName).toHaveBeenCalledTimes(1);
|
expect(mockGetLastWorkspaceName).toHaveBeenCalledTimes(1);
|
||||||
expect(mockGetWorkspace).toHaveBeenCalledWith('test-workspace');
|
expect(mockGetWorkspace).toHaveBeenCalledWith('test-workspace');
|
||||||
expect(mockListWorkspaces).toHaveBeenCalledTimes(1);
|
expect(mockListWorkspaces).toHaveBeenCalledTimes(1);
|
||||||
@@ -258,7 +256,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
|
|
||||||
expect(result.current.currentWorkspace).toBeNull();
|
expect(result.current.currentWorkspace).toBeNull();
|
||||||
expect(result.current.workspaces).toEqual([]);
|
expect(result.current.workspaces).toEqual([]);
|
||||||
expect(result.current.settings).toEqual(DEFAULT_WORKSPACE_SETTINGS);
|
|
||||||
|
|
||||||
consoleSpy.mockRestore();
|
consoleSpy.mockRestore();
|
||||||
});
|
});
|
||||||
@@ -420,7 +417,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
||||||
expect(result.current.settings).toEqual(mockWorkspace);
|
|
||||||
expect(mockGetWorkspace).toHaveBeenCalledWith('test-workspace');
|
expect(mockGetWorkspace).toHaveBeenCalledWith('test-workspace');
|
||||||
expect(mockUpdateColorScheme).toHaveBeenCalledWith('dark');
|
expect(mockUpdateColorScheme).toHaveBeenCalledWith('dark');
|
||||||
});
|
});
|
||||||
@@ -500,7 +496,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
||||||
expect(result.current.settings).toEqual(mockWorkspace);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sets workspace to null', async () => {
|
it('sets workspace to null', async () => {
|
||||||
@@ -524,7 +519,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(result.current.currentWorkspace).toBeNull();
|
expect(result.current.currentWorkspace).toBeNull();
|
||||||
expect(result.current.settings).toEqual(DEFAULT_WORKSPACE_SETTINGS);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -603,7 +597,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
|
|
||||||
expect(result.current.currentWorkspace).toBeNull();
|
expect(result.current.currentWorkspace).toBeNull();
|
||||||
expect(result.current.workspaces).toEqual([]);
|
expect(result.current.workspaces).toEqual([]);
|
||||||
expect(result.current.settings).toEqual(DEFAULT_WORKSPACE_SETTINGS);
|
|
||||||
expect(result.current.loading).toBe(false);
|
expect(result.current.loading).toBe(false);
|
||||||
|
|
||||||
expect(typeof result.current.loadWorkspaces).toBe('function');
|
expect(typeof result.current.loadWorkspaces).toBe('function');
|
||||||
@@ -631,7 +624,6 @@ describe('WorkspaceDataContext', () => {
|
|||||||
|
|
||||||
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
expect(result.current.currentWorkspace).toEqual(mockWorkspace);
|
||||||
expect(result.current.workspaces).toEqual(mockWorkspaceList);
|
expect(result.current.workspaces).toEqual(mockWorkspaceList);
|
||||||
expect(result.current.settings).toEqual(mockWorkspace);
|
|
||||||
expect(result.current.loading).toBe(false);
|
expect(result.current.loading).toBe(false);
|
||||||
|
|
||||||
expect(typeof result.current.loadWorkspaces).toBe('function');
|
expect(typeof result.current.loadWorkspaces).toBe('function');
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
import { DEFAULT_WORKSPACE_SETTINGS, type Workspace } from '@/types/models';
|
import { type Workspace } from '@/types/models';
|
||||||
import {
|
import {
|
||||||
getWorkspace,
|
getWorkspace,
|
||||||
listWorkspaces,
|
listWorkspaces,
|
||||||
@@ -19,7 +19,6 @@ import { useTheme } from './ThemeContext';
|
|||||||
interface WorkspaceDataContextType {
|
interface WorkspaceDataContextType {
|
||||||
currentWorkspace: Workspace | null;
|
currentWorkspace: Workspace | null;
|
||||||
workspaces: Workspace[];
|
workspaces: Workspace[];
|
||||||
settings: Workspace | typeof DEFAULT_WORKSPACE_SETTINGS;
|
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
loadWorkspaces: () => Promise<Workspace[]>;
|
loadWorkspaces: () => Promise<Workspace[]>;
|
||||||
loadWorkspaceData: (workspaceName: string) => Promise<void>;
|
loadWorkspaceData: (workspaceName: string) => Promise<void>;
|
||||||
@@ -121,7 +120,6 @@ export const WorkspaceDataProvider: React.FC<WorkspaceDataProviderProps> = ({
|
|||||||
const value: WorkspaceDataContextType = {
|
const value: WorkspaceDataContextType = {
|
||||||
currentWorkspace,
|
currentWorkspace,
|
||||||
workspaces,
|
workspaces,
|
||||||
settings: currentWorkspace || DEFAULT_WORKSPACE_SETTINGS,
|
|
||||||
loading,
|
loading,
|
||||||
loadWorkspaces,
|
loadWorkspaces,
|
||||||
loadWorkspaceData,
|
loadWorkspaceData,
|
||||||
|
|||||||
@@ -13,21 +13,20 @@ vi.mock('@mantine/notifications', () => ({
|
|||||||
|
|
||||||
// Mock the workspace context and git operations
|
// Mock the workspace context and git operations
|
||||||
const mockWorkspaceData: {
|
const mockWorkspaceData: {
|
||||||
currentWorkspace: { id: number; name: string } | null;
|
currentWorkspace: {
|
||||||
settings: {
|
id: number;
|
||||||
gitAutoCommit: boolean;
|
name: string;
|
||||||
gitEnabled: boolean;
|
gitAutoCommit?: boolean;
|
||||||
gitCommitMsgTemplate: string;
|
gitEnabled?: boolean;
|
||||||
};
|
gitCommitMsgTemplate?: string;
|
||||||
|
} | null;
|
||||||
} = {
|
} = {
|
||||||
currentWorkspace: {
|
currentWorkspace: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'test-workspace',
|
name: 'test-workspace',
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
gitAutoCommit: false,
|
gitAutoCommit: false,
|
||||||
gitEnabled: false,
|
gitEnabled: false,
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
gitCommitMsgTemplate: '${action}: ${filename}',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,8 +52,6 @@ describe('useFileOperations', () => {
|
|||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'test-workspace',
|
name: 'test-workspace',
|
||||||
};
|
|
||||||
mockWorkspaceData.settings = {
|
|
||||||
gitAutoCommit: false,
|
gitAutoCommit: false,
|
||||||
gitEnabled: false,
|
gitEnabled: false,
|
||||||
gitCommitMsgTemplate: '${action} ${filename}',
|
gitCommitMsgTemplate: '${action} ${filename}',
|
||||||
@@ -155,8 +152,8 @@ describe('useFileOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enable auto-commit
|
// Enable auto-commit
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|
||||||
@@ -178,9 +175,9 @@ describe('useFileOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enable auto-commit with custom template
|
// Enable auto-commit with custom template
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
mockWorkspaceData.settings.gitCommitMsgTemplate =
|
mockWorkspaceData.currentWorkspace!.gitCommitMsgTemplate =
|
||||||
'Modified ${filename} - ${action}';
|
'Modified ${filename} - ${action}';
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
@@ -264,8 +261,8 @@ describe('useFileOperations', () => {
|
|||||||
mockDeleteFile.mockResolvedValue(undefined);
|
mockDeleteFile.mockResolvedValue(undefined);
|
||||||
|
|
||||||
// Enable auto-commit
|
// Enable auto-commit
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|
||||||
@@ -382,8 +379,8 @@ describe('useFileOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enable auto-commit
|
// Enable auto-commit
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|
||||||
@@ -407,8 +404,8 @@ describe('useFileOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enable auto-commit but disable git
|
// Enable auto-commit but disable git
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = false;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = false;
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|
||||||
@@ -428,8 +425,8 @@ describe('useFileOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enable git but disable auto-commit
|
// Enable git but disable auto-commit
|
||||||
mockWorkspaceData.settings.gitAutoCommit = false;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = false;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|
||||||
@@ -449,9 +446,10 @@ describe('useFileOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Enable auto-commit with lowercase template
|
// Enable auto-commit with lowercase template
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
mockWorkspaceData.settings.gitCommitMsgTemplate = 'updated ${filename}';
|
mockWorkspaceData.currentWorkspace!.gitCommitMsgTemplate =
|
||||||
|
'updated ${filename}';
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|
||||||
@@ -476,9 +474,9 @@ describe('useFileOperations', () => {
|
|||||||
mockDeleteFile.mockResolvedValue(undefined);
|
mockDeleteFile.mockResolvedValue(undefined);
|
||||||
|
|
||||||
// Enable auto-commit
|
// Enable auto-commit
|
||||||
mockWorkspaceData.settings.gitAutoCommit = true;
|
mockWorkspaceData.currentWorkspace!.gitAutoCommit = true;
|
||||||
mockWorkspaceData.settings.gitEnabled = true;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = true;
|
||||||
mockWorkspaceData.settings.gitCommitMsgTemplate =
|
mockWorkspaceData.currentWorkspace!.gitCommitMsgTemplate =
|
||||||
'${action}: ${filename}';
|
'${action}: ${filename}';
|
||||||
|
|
||||||
const { result } = renderHook(() => useFileOperations());
|
const { result } = renderHook(() => useFileOperations());
|
||||||
|
|||||||
@@ -19,13 +19,14 @@ interface UseFileOperationsResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useFileOperations = (): UseFileOperationsResult => {
|
export const useFileOperations = (): UseFileOperationsResult => {
|
||||||
const { currentWorkspace, settings } = useWorkspaceData();
|
const { currentWorkspace } = useWorkspaceData();
|
||||||
const { handleCommitAndPush } = useGitOperations();
|
const { handleCommitAndPush } = useGitOperations();
|
||||||
|
|
||||||
const autoCommit = useCallback(
|
const autoCommit = useCallback(
|
||||||
async (filePath: string, action: FileAction): Promise<void> => {
|
async (filePath: string, action: FileAction): Promise<void> => {
|
||||||
if (settings.gitAutoCommit && settings.gitEnabled) {
|
if (!currentWorkspace || !currentWorkspace.gitEnabled) return;
|
||||||
let commitMessage = settings.gitCommitMsgTemplate
|
if (currentWorkspace.gitAutoCommit && currentWorkspace.gitEnabled) {
|
||||||
|
let commitMessage = currentWorkspace.gitCommitMsgTemplate
|
||||||
.replace('${filename}', filePath)
|
.replace('${filename}', filePath)
|
||||||
.replace('${action}', action);
|
.replace('${action}', action);
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ export const useFileOperations = (): UseFileOperationsResult => {
|
|||||||
await handleCommitAndPush(commitMessage);
|
await handleCommitAndPush(commitMessage);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[settings, handleCommitAndPush]
|
[currentWorkspace, handleCommitAndPush]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSave = useCallback(
|
const handleSave = useCallback(
|
||||||
@@ -123,15 +124,6 @@ export const useFileOperations = (): UseFileOperationsResult => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: Implement your file upload API call
|
// TODO: Implement your file upload API call
|
||||||
// Example:
|
|
||||||
// const formData = new FormData();
|
|
||||||
// Array.from(files).forEach((file, index) => {
|
|
||||||
// formData.append(`file${index}`, file);
|
|
||||||
// });
|
|
||||||
// if (targetPath) {
|
|
||||||
// formData.append('targetPath', targetPath);
|
|
||||||
// }
|
|
||||||
// await uploadFiles(currentWorkspace.name, formData);
|
|
||||||
|
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
@@ -165,12 +157,6 @@ export const useFileOperations = (): UseFileOperationsResult => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// TODO: Implement your file move API call
|
// TODO: Implement your file move API call
|
||||||
// Example:
|
|
||||||
// await moveFiles(currentWorkspace.name, {
|
|
||||||
// sourceIds: dragIds,
|
|
||||||
// targetParentId: parentId,
|
|
||||||
// targetIndex: index
|
|
||||||
// });
|
|
||||||
|
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
|
|||||||
@@ -13,14 +13,11 @@ vi.mock('@mantine/notifications', () => ({
|
|||||||
|
|
||||||
// Mock the workspace context
|
// Mock the workspace context
|
||||||
const mockWorkspaceData: {
|
const mockWorkspaceData: {
|
||||||
currentWorkspace: { id: number; name: string } | null;
|
currentWorkspace: { id: number; name: string; gitEnabled: boolean } | null;
|
||||||
settings: { gitEnabled: boolean };
|
|
||||||
} = {
|
} = {
|
||||||
currentWorkspace: {
|
currentWorkspace: {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'test-workspace',
|
name: 'test-workspace',
|
||||||
},
|
|
||||||
settings: {
|
|
||||||
gitEnabled: true,
|
gitEnabled: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -39,8 +36,6 @@ describe('useGitOperations', () => {
|
|||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'test-workspace',
|
name: 'test-workspace',
|
||||||
};
|
|
||||||
mockWorkspaceData.settings = {
|
|
||||||
gitEnabled: true,
|
gitEnabled: true,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@@ -114,7 +109,7 @@ describe('useGitOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('returns false when git is disabled', async () => {
|
it('returns false when git is disabled', async () => {
|
||||||
mockWorkspaceData.settings.gitEnabled = false;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = false;
|
||||||
|
|
||||||
const { result } = renderHook(() => useGitOperations());
|
const { result } = renderHook(() => useGitOperations());
|
||||||
|
|
||||||
@@ -208,7 +203,7 @@ describe('useGitOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does nothing when git is disabled', async () => {
|
it('does nothing when git is disabled', async () => {
|
||||||
mockWorkspaceData.settings.gitEnabled = false;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = false;
|
||||||
|
|
||||||
const { result } = renderHook(() => useGitOperations());
|
const { result } = renderHook(() => useGitOperations());
|
||||||
|
|
||||||
@@ -306,6 +301,7 @@ describe('useGitOperations', () => {
|
|||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
id: 2,
|
id: 2,
|
||||||
name: 'different-workspace',
|
name: 'different-workspace',
|
||||||
|
gitEnabled: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
rerender();
|
rerender();
|
||||||
@@ -321,10 +317,10 @@ describe('useGitOperations', () => {
|
|||||||
const { result, rerender } = renderHook(() => useGitOperations());
|
const { result, rerender } = renderHook(() => useGitOperations());
|
||||||
|
|
||||||
// Initially git is enabled
|
// Initially git is enabled
|
||||||
expect(mockWorkspaceData.settings.gitEnabled).toBe(true);
|
expect(mockWorkspaceData.currentWorkspace!.gitEnabled).toBe(true);
|
||||||
|
|
||||||
// Disable git
|
// Disable git
|
||||||
mockWorkspaceData.settings.gitEnabled = false;
|
mockWorkspaceData.currentWorkspace!.gitEnabled = false;
|
||||||
rerender();
|
rerender();
|
||||||
|
|
||||||
let pullResult: boolean | undefined;
|
let pullResult: boolean | undefined;
|
||||||
@@ -381,6 +377,7 @@ describe('useGitOperations', () => {
|
|||||||
mockWorkspaceData.currentWorkspace = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: undefined!,
|
name: undefined!,
|
||||||
|
gitEnabled: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const { result } = renderHook(() => useGitOperations());
|
const { result } = renderHook(() => useGitOperations());
|
||||||
@@ -395,7 +392,9 @@ describe('useGitOperations', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('handles missing settings gracefully', async () => {
|
it('handles missing settings gracefully', async () => {
|
||||||
mockWorkspaceData.settings = {
|
mockWorkspaceData.currentWorkspace = {
|
||||||
|
id: 1,
|
||||||
|
name: 'test-workspace',
|
||||||
gitEnabled: undefined!,
|
gitEnabled: undefined!,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,14 @@ interface UseGitOperationsResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useGitOperations = (): UseGitOperationsResult => {
|
export const useGitOperations = (): UseGitOperationsResult => {
|
||||||
const { currentWorkspace, settings } = useWorkspaceData();
|
const { currentWorkspace } = useWorkspaceData();
|
||||||
|
|
||||||
const handlePull = useCallback(async (): Promise<boolean> => {
|
const handlePull = useCallback(async (): Promise<boolean> => {
|
||||||
if (!currentWorkspace || !settings.gitEnabled || !currentWorkspace.name)
|
if (
|
||||||
|
!currentWorkspace ||
|
||||||
|
!currentWorkspace.gitEnabled ||
|
||||||
|
!currentWorkspace.name
|
||||||
|
)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -33,11 +37,11 @@ export const useGitOperations = (): UseGitOperationsResult => {
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}, [currentWorkspace, settings.gitEnabled]);
|
}, [currentWorkspace]);
|
||||||
|
|
||||||
const handleCommitAndPush = useCallback(
|
const handleCommitAndPush = useCallback(
|
||||||
async (message: string): Promise<void> => {
|
async (message: string): Promise<void> => {
|
||||||
if (!currentWorkspace || !settings.gitEnabled) return;
|
if (!currentWorkspace || !currentWorkspace.gitEnabled) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const commitHash: CommitHash = await commitAndPush(
|
const commitHash: CommitHash = await commitAndPush(
|
||||||
@@ -60,7 +64,7 @@ export const useGitOperations = (): UseGitOperationsResult => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentWorkspace, settings.gitEnabled]
|
[currentWorkspace]
|
||||||
);
|
);
|
||||||
|
|
||||||
return { handlePull, handleCommitAndPush };
|
return { handlePull, handleCommitAndPush };
|
||||||
|
|||||||
Reference in New Issue
Block a user