mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Add branch refetch on dropdown open and window focus
This commit is contained in:
1 parent
0c4dbbafbc
commit
8acd0da5cb
1 file changed
+10
-3
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useCallback } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
@@ -28,12 +28,19 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
const queryClient = useQueryClient();
|
||||
const { data: gitStatus } = useGitStatus(repoId);
|
||||
|
||||
const { data: branches, isLoading: branchesLoading } = useQuery({
|
||||
const { data: branches, isLoading: branchesLoading, refetch: refetchBranches } = useQuery({
|
||||
queryKey: ["branches", repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
enabled: !!repoId,
|
||||
staleTime: 1000 * 30,
|
||||
});
|
||||
|
||||
const handleDropdownOpenChange = useCallback((open: boolean) => {
|
||||
if (open && repoId) {
|
||||
refetchBranches();
|
||||
}
|
||||
}, [repoId, refetchBranches]);
|
||||
|
||||
const switchBranchMutation = useMutation({
|
||||
mutationFn: (branch: string) => switchBranch(repoId, branch),
|
||||
onSuccess: () => {
|
||||
@@ -48,7 +55,7 @@ export function BranchSwitcher({ repoId, currentBranch, isWorktree, repoUrl, rep
|
||||
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu>
|
||||
<DropdownMenu onOpenChange={handleDropdownOpenChange}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
|
||||
Reference in new issue
Block a user