fix(web): localize single-file confirmations (#2894)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useCallback } from "react";
|
||||
import { useRef, useState, useCallback } from "react";
|
||||
import { t } from "@/lib/i18n";
|
||||
import { gitOperationLabel } from "@/hooks/use-git-with-feedback";
|
||||
import type { useToast } from "@/components/toast-provider";
|
||||
@@ -202,22 +202,33 @@ function useChangesDiscardAmendHandlers(
|
||||
const [showDiscardDialog, setShowDiscardDialog] = useState(false);
|
||||
const [fileToDiscard, setFileToDiscard] = useState<string | null>(null);
|
||||
const [filesToDiscard, setFilesToDiscard] = useState<string[] | null>(null);
|
||||
const discardAnchorRef = useRef<HTMLElement | null>(null);
|
||||
// Multi-repo: remember the clicked file's repo so the discard op routes to
|
||||
// the right git repo. Path alone is ambiguous when two repos share a name.
|
||||
const [repoToDiscard, setRepoToDiscard] = useState<string | undefined>(undefined);
|
||||
|
||||
const handleDiscardClick = useCallback((filePath: string, repo?: string) => {
|
||||
setFileToDiscard(filePath);
|
||||
setRepoToDiscard(repo);
|
||||
setFilesToDiscard(null);
|
||||
setShowDiscardDialog(true);
|
||||
}, []);
|
||||
const handleBulkDiscardClick = useCallback((paths: string[]) => {
|
||||
const handleDiscardClick = useCallback(
|
||||
(filePath: string, repo?: string, anchor?: HTMLElement) => {
|
||||
discardAnchorRef.current = anchor ?? null;
|
||||
setFileToDiscard(filePath);
|
||||
setRepoToDiscard(repo);
|
||||
setFilesToDiscard(null);
|
||||
setShowDiscardDialog(true);
|
||||
},
|
||||
[],
|
||||
);
|
||||
const handleBulkDiscardClick = useCallback((paths: string[], anchor?: HTMLElement) => {
|
||||
discardAnchorRef.current = anchor ?? null;
|
||||
setFilesToDiscard(paths);
|
||||
setFileToDiscard(null);
|
||||
setRepoToDiscard(undefined);
|
||||
setShowDiscardDialog(true);
|
||||
}, []);
|
||||
const handleDiscardOpenChange = useCallback((open: boolean) => {
|
||||
setShowDiscardDialog(open);
|
||||
// Keep the anchor through the popover's close autofocus. A later discard
|
||||
// replaces it, while confirmation clears it after the mutation settles.
|
||||
}, []);
|
||||
const handleDiscardConfirm = useCallback(async () => {
|
||||
const paths = filesToDiscard ?? (fileToDiscard ? [fileToDiscard] : null);
|
||||
if (!paths) return;
|
||||
@@ -237,6 +248,7 @@ function useChangesDiscardAmendHandlers(
|
||||
});
|
||||
} finally {
|
||||
setShowDiscardDialog(false);
|
||||
discardAnchorRef.current = null;
|
||||
setFileToDiscard(null);
|
||||
setFilesToDiscard(null);
|
||||
setRepoToDiscard(undefined);
|
||||
@@ -271,6 +283,8 @@ function useChangesDiscardAmendHandlers(
|
||||
return {
|
||||
showDiscardDialog,
|
||||
setShowDiscardDialog,
|
||||
discardAnchorRef,
|
||||
handleDiscardOpenChange,
|
||||
fileToDiscard,
|
||||
filesToDiscard,
|
||||
handleDiscardClick,
|
||||
|
||||
Reference in New Issue
Block a user