代码提交/推送时,右侧边栏的提交列表实时更新最新状态
This commit is contained in:
@@ -75,6 +75,8 @@ import {
|
||||
CollapsibleTrigger,
|
||||
} from "@/components/ui/collapsible"
|
||||
import { Skeleton } from "@/components/ui/skeleton"
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
|
||||
import { disposeTauriListener } from "@/lib/tauri-listener"
|
||||
import { useFolderContext } from "@/contexts/folder-context"
|
||||
import { useWorkspaceContext } from "@/contexts/workspace-context"
|
||||
import {
|
||||
@@ -862,6 +864,39 @@ export function GitLogTab() {
|
||||
void fetchLog()
|
||||
}, [fetchLog])
|
||||
|
||||
// Refresh branches & log on branch change, commit, or push
|
||||
useEffect(() => {
|
||||
if (!folder) return
|
||||
|
||||
const events = [
|
||||
"folder://git-branch-changed",
|
||||
"folder://git-commit-succeeded",
|
||||
"folder://git-push-succeeded",
|
||||
] as const
|
||||
|
||||
const unlistens: (UnlistenFn | null)[] = events.map(() => null)
|
||||
|
||||
events.forEach((eventName, i) => {
|
||||
listen<{ folder_id: number }>(eventName, (event) => {
|
||||
if (event.payload.folder_id !== folder.id) return
|
||||
void refreshBranches()
|
||||
void fetchLog({ inline: true })
|
||||
})
|
||||
.then((fn) => {
|
||||
unlistens[i] = fn
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(`[GitLogTab] failed to listen ${eventName}:`, err)
|
||||
})
|
||||
})
|
||||
|
||||
return () => {
|
||||
events.forEach((eventName, i) => {
|
||||
disposeTauriListener(unlistens[i], `GitLogTab.${eventName}`)
|
||||
})
|
||||
}
|
||||
}, [folder, refreshBranches, fetchLog])
|
||||
|
||||
const handleScroll = useCallback((e: UIEvent<HTMLDivElement>) => {
|
||||
const nextScrolled = e.currentTarget.scrollTop > 0
|
||||
setScrolled((prev) => (prev === nextScrolled ? prev : nextScrolled))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useRef, useCallback, useMemo, useEffect } from "react"
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event"
|
||||
import { emit, listen, type UnlistenFn } from "@tauri-apps/api/event"
|
||||
import {
|
||||
GitBranch,
|
||||
ChevronDown,
|
||||
@@ -245,6 +245,9 @@ export function BranchDropdown({
|
||||
const successDescription = getSuccessDescription?.(result)
|
||||
updateTask(taskId, { status: "completed" })
|
||||
onBranchChange()
|
||||
void emit("folder://git-branch-changed", {
|
||||
folder_id: folder?.id,
|
||||
})
|
||||
if (successDescription !== false) {
|
||||
toast.success(
|
||||
t("toasts.taskCompleted", { label }),
|
||||
|
||||
Reference in New Issue
Block a user