mirror of
https://github.com/lordmathis/lemma.git
synced 2025-11-05 15:44:21 +00:00
Migrate useGitOperations
This commit is contained in:
@@ -3,10 +3,15 @@ import { notifications } from '@mantine/notifications';
|
|||||||
import { pullChanges, commitAndPush } from '../api/git';
|
import { pullChanges, commitAndPush } from '../api/git';
|
||||||
import { useWorkspace } from '../contexts/WorkspaceContext';
|
import { useWorkspace } from '../contexts/WorkspaceContext';
|
||||||
|
|
||||||
export const useGitOperations = () => {
|
interface UseGitOperationsResult {
|
||||||
|
handlePull: () => Promise<boolean>;
|
||||||
|
handleCommitAndPush: (message: string) => Promise<boolean>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useGitOperations = (): UseGitOperationsResult => {
|
||||||
const { currentWorkspace, settings } = useWorkspace();
|
const { currentWorkspace, settings } = useWorkspace();
|
||||||
|
|
||||||
const handlePull = useCallback(async () => {
|
const handlePull = useCallback(async (): Promise<boolean> => {
|
||||||
if (!currentWorkspace || !settings.gitEnabled) return false;
|
if (!currentWorkspace || !settings.gitEnabled) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -29,11 +34,14 @@ export const useGitOperations = () => {
|
|||||||
}, [currentWorkspace, settings.gitEnabled]);
|
}, [currentWorkspace, settings.gitEnabled]);
|
||||||
|
|
||||||
const handleCommitAndPush = useCallback(
|
const handleCommitAndPush = useCallback(
|
||||||
async (message) => {
|
async (message: string): Promise<boolean> => {
|
||||||
if (!currentWorkspace || !settings.gitEnabled) return false;
|
if (!currentWorkspace || !settings.gitEnabled) return false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await commitAndPush(currentWorkspace.name, message);
|
const commitHash: CommitHash = await commitAndPush(
|
||||||
|
currentWorkspace.name,
|
||||||
|
message
|
||||||
|
);
|
||||||
notifications.show({
|
notifications.show({
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
message: 'Successfully committed and pushed changes',
|
message: 'Successfully committed and pushed changes',
|
||||||
Reference in New Issue
Block a user