Fix dropdown refresh after Git init

This commit is contained in:
Gregory Schier
2025-03-19 11:35:20 -07:00
parent 6e25c26e9f
commit c300e8cbd5
5 changed files with 43 additions and 28 deletions

View File

@@ -1,4 +1,4 @@
import { gitInit } from '@yaakapp-internal/git';
import { useGitInit } from '@yaakapp-internal/git';
import type { WorkspaceMeta } from '@yaakapp-internal/models';
import { useState } from 'react';
import { upsertWorkspace } from '../commands/upsertWorkspace';
@@ -17,6 +17,7 @@ interface Props {
export function CreateWorkspaceDialog({ hide }: Props) {
const [name, setName] = useState<string>('');
const gitInit = useGitInit();
const [syncConfig, setSyncConfig] = useState<{
filePath: string | null;
initGit?: boolean;
@@ -44,7 +45,7 @@ export function CreateWorkspaceDialog({ hide }: Props) {
});
if (syncConfig.initGit && syncConfig.filePath) {
gitInit(syncConfig.filePath).catch((err) => {
gitInit.mutateAsync({ dir: syncConfig.filePath }).catch((err) => {
showErrorToast('git-init-error', String(err));
});
}

View File

@@ -1,4 +1,4 @@
import { gitInit, useGit } from '@yaakapp-internal/git';
import { useGit } from '@yaakapp-internal/git';
import type { WorkspaceMeta } from '@yaakapp-internal/models';
import classNames from 'classnames';
import type { HTMLAttributes } from 'react';
@@ -34,8 +34,10 @@ export function GitDropdown() {
function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) {
const workspace = useActiveWorkspace();
const [{ status, log }, { branch, deleteBranch, fetchAll, mergeBranch, push, pull, checkout }] =
useGit(syncDir);
const [
{ status, log },
{ branch, deleteBranch, fetchAll, mergeBranch, push, pull, checkout, init },
] = useGit(syncDir);
const localBranches = status.data?.localBranches ?? [];
const remoteBranches = status.data?.remoteBranches ?? [];
@@ -50,7 +52,9 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) {
const noRepo = status.error?.includes('not found');
if (noRepo) {
return <SetupGitDropdown workspaceId={workspace.id} initRepo={() => gitInit(syncDir)} />;
return (
<SetupGitDropdown workspaceId={workspace.id} initRepo={() => init.mutate({ dir: syncDir })} />
);
}
const tryCheckout = (branch: string, force: boolean) => {