diff --git a/crates/yaak-git/index.ts b/crates/yaak-git/index.ts index b90fa99b..b08d838b 100644 --- a/crates/yaak-git/index.ts +++ b/crates/yaak-git/index.ts @@ -32,22 +32,30 @@ export interface GitCallbacks { const onSuccess = () => queryClient.invalidateQueries({ queryKey: ['git'] }); -export function useGit(dir: string, callbacks: GitCallbacks) { +export function useGit(dir: string, callbacks: GitCallbacks, refreshKey?: string) { const mutations = useMemo(() => gitMutations(dir, callbacks), [dir, callbacks]); + const fetchAll = useQuery({ + queryKey: ['git', 'fetch_all', dir, refreshKey], + queryFn: () => invoke('cmd_git_fetch_all', { dir }), + refetchInterval: 10 * 60_000, + }); return [ { remotes: useQuery({ - queryKey: ['git', 'remotes', dir], + queryKey: ['git', 'remotes', dir, refreshKey], queryFn: () => getRemotes(dir), + placeholderData: (prev) => prev, }), log: useQuery({ - queryKey: ['git', 'log', dir], + queryKey: ['git', 'log', dir, refreshKey], queryFn: () => invoke('cmd_git_log', { dir }), + placeholderData: (prev) => prev, }), status: useQuery({ refetchOnMount: true, - queryKey: ['git', 'status', dir], + queryKey: ['git', 'status', dir, refreshKey, fetchAll.dataUpdatedAt], queryFn: () => invoke('cmd_git_status', { dir }), + placeholderData: (prev) => prev, }), }, mutations, @@ -152,10 +160,7 @@ export const gitMutations = (dir: string, callbacks: GitCallbacks) => { }, onSuccess, }), - fetchAll: createFastMutation({ - mutationKey: ['git', 'fetch_all', dir], - mutationFn: () => invoke('cmd_git_fetch_all', { dir }), - }), + push: createFastMutation({ mutationKey: ['git', 'push', dir], mutationFn: push, diff --git a/src-web/components/git/GitDropdown.tsx b/src-web/components/git/GitDropdown.tsx index 1915f6ec..563fef47 100644 --- a/src-web/components/git/GitDropdown.tsx +++ b/src-web/components/git/GitDropdown.tsx @@ -7,6 +7,7 @@ import { forwardRef } from 'react'; import { openWorkspaceSettings } from '../../commands/openWorkspaceSettings'; import { activeWorkspaceAtom, activeWorkspaceMetaAtom } from '../../hooks/useActiveWorkspace'; import { useKeyValue } from '../../hooks/useKeyValue'; +import { useRandomKey } from '../../hooks/useRandomKey'; import { sync } from '../../init/sync'; import { showConfirm, showConfirmDelete } from '../../lib/confirm'; import { showDialog } from '../../lib/dialog'; @@ -36,6 +37,7 @@ export function GitDropdown() { function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { const workspace = useAtomValue(activeWorkspaceAtom); + const [refreshKey, regenerateKey] = useRandomKey(); const [ { status, log }, { @@ -43,7 +45,6 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { deleteBranch, deleteRemoteBranch, renameBranch, - fetchAll, mergeBranch, push, pull, @@ -51,7 +52,7 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { resetChanges, init, }, - ] = useGit(syncDir, gitCallbacks(syncDir)); + ] = useGit(syncDir, gitCallbacks(syncDir), refreshKey); const localBranches = status.data?.localBranches ?? []; const remoteBranches = status.data?.remoteBranches ?? []; @@ -172,7 +173,7 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { { type: 'separator' }, { label: 'Push', - disabled: !hasRemotes || ahead === 0, + hidden: !hasRemotes, leftSlot: , waitForOnSelect: true, async onSelect() { @@ -191,7 +192,7 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { }, { label: 'Pull', - disabled: !hasRemotes || behind === 0, + hidden: !hasRemotes, leftSlot: , waitForOnSelect: true, async onSelect() { @@ -210,7 +211,7 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { }, { label: 'Commit...', - disabled: !hasChanges, + leftSlot: , onSelect() { showDialog({ @@ -502,15 +503,25 @@ function SyncDropdownWithSyncDir({ syncDir }: { syncDir: string }) { ]; return ( - + {currentBranch}
- {ahead > 0 && {ahead}} - {behind > 0 && {behind}} + {ahead > 0 && ( + + + {ahead} + + )} + {behind > 0 && ( + + + {behind} + + )}