Git推送成功后现在会自动关闭推送窗口
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
"use client"
|
||||
|
||||
import { Suspense, useEffect, useState } from "react"
|
||||
import { Suspense, useCallback, useEffect, useState } from "react"
|
||||
import { useSearchParams } from "next/navigation"
|
||||
import { useTranslations } from "next-intl"
|
||||
import { getCurrentWindow } from "@tauri-apps/api/window"
|
||||
import { Loader2 } from "lucide-react"
|
||||
import { PushWorkspace } from "@/components/layout/push-workspace"
|
||||
import { AppTitleBar } from "@/components/layout/app-title-bar"
|
||||
@@ -27,6 +28,14 @@ function PushPageInner() {
|
||||
error: null,
|
||||
})
|
||||
|
||||
const closeWindow = useCallback(() => {
|
||||
getCurrentWindow()
|
||||
.close()
|
||||
.catch((err) => {
|
||||
console.error("[PushPage] failed to close window:", err)
|
||||
})
|
||||
}, [])
|
||||
|
||||
const folderId = Number(searchParams.get("folderId") ?? "0")
|
||||
const normalizedFolderId = Number.isFinite(folderId) ? folderId : 0
|
||||
const hasValidFolderId = normalizedFolderId > 0
|
||||
@@ -89,7 +98,11 @@ function PushPageInner() {
|
||||
{error}
|
||||
</div>
|
||||
) : folder ? (
|
||||
<PushWorkspace folderPath={folder.path} folderName={folder.name} />
|
||||
<PushWorkspace
|
||||
folderPath={folder.path}
|
||||
folderName={folder.name}
|
||||
onPushed={closeWindow}
|
||||
/>
|
||||
) : null}
|
||||
</main>
|
||||
|
||||
|
||||
@@ -108,6 +108,12 @@ interface GitCommitSucceededEventPayload {
|
||||
committed_files: number
|
||||
}
|
||||
|
||||
interface GitPushSucceededEventPayload {
|
||||
folder_id: number
|
||||
pushed_commits: number
|
||||
upstream_set: boolean
|
||||
}
|
||||
|
||||
export function BranchDropdown({
|
||||
branch,
|
||||
parentBranch,
|
||||
@@ -187,6 +193,43 @@ export function BranchDropdown({
|
||||
}
|
||||
}, [folder, onBranchChange, t])
|
||||
|
||||
useEffect(() => {
|
||||
if (!folder) return
|
||||
|
||||
let unlisten: UnlistenFn | null = null
|
||||
|
||||
listen<GitPushSucceededEventPayload>(
|
||||
"folder://git-push-succeeded",
|
||||
(event) => {
|
||||
if (event.payload.folder_id !== folder.id) return
|
||||
const { pushed_commits, upstream_set } = event.payload
|
||||
let description: string
|
||||
if (upstream_set) {
|
||||
description =
|
||||
pushed_commits === 0
|
||||
? t("toasts.upstreamSet")
|
||||
: t("toasts.upstreamSetAndPushed", { count: pushed_commits })
|
||||
} else if (pushed_commits === 0) {
|
||||
description = t("toasts.noCommitsToPush")
|
||||
} else {
|
||||
description = t("toasts.pushedCommits", { count: pushed_commits })
|
||||
}
|
||||
toast.success(t("toasts.pushCodeCompleted"), { description })
|
||||
onBranchChange()
|
||||
}
|
||||
)
|
||||
.then((fn) => {
|
||||
unlisten = fn
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("[BranchDropdown] failed to listen push event:", err)
|
||||
})
|
||||
|
||||
return () => {
|
||||
disposeTauriListener(unlisten, "BranchDropdown.gitPushSucceeded")
|
||||
}
|
||||
}, [folder, onBranchChange, t])
|
||||
|
||||
async function runGitTask<T>(
|
||||
label: string,
|
||||
action: () => Promise<T>,
|
||||
|
||||
@@ -266,9 +266,14 @@ function parseDate(dateStr: string): Date | null {
|
||||
interface PushWorkspaceProps {
|
||||
folderPath: string
|
||||
folderName: string
|
||||
onPushed?: () => void
|
||||
}
|
||||
|
||||
export function PushWorkspace({ folderPath, folderName }: PushWorkspaceProps) {
|
||||
export function PushWorkspace({
|
||||
folderPath,
|
||||
folderName,
|
||||
onPushed,
|
||||
}: PushWorkspaceProps) {
|
||||
const t = useTranslations("Folder.pushWindow")
|
||||
const tLog = useTranslations("Folder.gitLogTab")
|
||||
const { withCredentialRetry } = useGitCredential()
|
||||
@@ -327,30 +332,10 @@ export function PushWorkspace({ folderPath, folderName }: PushWorkspaceProps) {
|
||||
async function handlePush() {
|
||||
setPushing(true)
|
||||
try {
|
||||
const result = await withCredentialRetry(
|
||||
(creds) => gitPush(folderPath, creds),
|
||||
{ folderPath }
|
||||
)
|
||||
let description: string | undefined
|
||||
if (result.upstream_set) {
|
||||
description =
|
||||
result.pushed_commits === 0
|
||||
? t("toasts.upstreamSet")
|
||||
: t("toasts.upstreamSetAndPushed", {
|
||||
count: result.pushed_commits,
|
||||
})
|
||||
} else if (result.pushed_commits === 0) {
|
||||
description = t("toasts.noCommitsToPush")
|
||||
} else {
|
||||
description = t("toasts.pushedCommits", {
|
||||
count: result.pushed_commits,
|
||||
})
|
||||
}
|
||||
toast.success(t("toasts.pushSuccess"), { description })
|
||||
await loadCommits()
|
||||
setSelectedFile(null)
|
||||
setSelectedCommit(null)
|
||||
setOpenByCommit({})
|
||||
await withCredentialRetry((creds) => gitPush(folderPath, creds), {
|
||||
folderPath,
|
||||
})
|
||||
onPushed?.()
|
||||
} catch (err) {
|
||||
toast.error(t("toasts.pushFailed"), {
|
||||
description: toErrorMessage(err),
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "اكتمل التزام الكود",
|
||||
"pushCodeCompleted": "اكتمل دفع الكود",
|
||||
"committedFiles": "{count, plural, one {# ملف تم الالتزام به} other {# ملفات تم الالتزام بها}}",
|
||||
"taskCompleted": "اكتمل {label}",
|
||||
"taskFailed": "فشل {label}",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "Code-Commit abgeschlossen",
|
||||
"pushCodeCompleted": "Code-Push abgeschlossen",
|
||||
"committedFiles": "{count, plural, one {# Datei committet} other {# Dateien committet}}",
|
||||
"taskCompleted": "{label} abgeschlossen",
|
||||
"taskFailed": "{label} fehlgeschlagen",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "Code commit completed",
|
||||
"pushCodeCompleted": "Code push completed",
|
||||
"committedFiles": "Committed {count, plural, one {# file} other {# files}}",
|
||||
"taskCompleted": "{label} completed",
|
||||
"taskFailed": "{label} failed",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "Commit de código completado",
|
||||
"pushCodeCompleted": "Push de código completado",
|
||||
"committedFiles": "{count, plural, one {# archivo confirmado} other {# archivos confirmados}}",
|
||||
"taskCompleted": "{label} completado",
|
||||
"taskFailed": "{label} falló",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "Commit de code terminé",
|
||||
"pushCodeCompleted": "Push de code terminé",
|
||||
"committedFiles": "{count, plural, one {# fichier commit} other {# fichiers commit}}",
|
||||
"taskCompleted": "{label} terminé",
|
||||
"taskFailed": "{label} échoué",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "コードコミットが完了しました",
|
||||
"pushCodeCompleted": "コードプッシュが完了しました",
|
||||
"committedFiles": "{count, plural, one {# 個のファイルをコミット} other {# 個のファイルをコミット}}",
|
||||
"taskCompleted": "{label} が完了しました",
|
||||
"taskFailed": "{label} が失敗しました",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "코드 커밋이 완료되었습니다",
|
||||
"pushCodeCompleted": "코드 푸시가 완료되었습니다",
|
||||
"committedFiles": "{count, plural, one {#개 파일 커밋됨} other {#개 파일 커밋됨}}",
|
||||
"taskCompleted": "{label} 완료",
|
||||
"taskFailed": "{label} 실패",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "Commit de código concluído",
|
||||
"pushCodeCompleted": "Push de código concluído",
|
||||
"committedFiles": "{count, plural, one {# arquivo commitado} other {# arquivos commitados}}",
|
||||
"taskCompleted": "{label} concluído",
|
||||
"taskFailed": "{label} falhou",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "提交代码完成",
|
||||
"pushCodeCompleted": "推送代码完成",
|
||||
"committedFiles": "已提交 {count} 个文件",
|
||||
"taskCompleted": "{label} 完成",
|
||||
"taskFailed": "{label} 失败",
|
||||
|
||||
@@ -875,6 +875,7 @@
|
||||
"branchDropdown": {
|
||||
"toasts": {
|
||||
"commitCodeCompleted": "提交程式碼完成",
|
||||
"pushCodeCompleted": "推送程式碼完成",
|
||||
"committedFiles": "已提交 {count} 個檔案",
|
||||
"taskCompleted": "{label} 完成",
|
||||
"taskFailed": "{label} 失敗",
|
||||
|
||||
Reference in New Issue
Block a user