fix: avoid duplicate key in files list when focus on tag

This commit is contained in:
Xu Quan 2025-07-13 16:57:57 +08:00
parent 47a2a03856
commit e4daa6982a
2 changed files with 6 additions and 6 deletions

View file

@ -8,7 +8,7 @@ import { ExplorerStore } from "src/store";
import { PinContainer, PinContent, PinHeader } from "../Pin";
type Props = {
renderFile: (file: TFile, disableDrag?: boolean) => ReactNode;
renderFile: (file: TFile, index: number, disableDrag?: boolean) => ReactNode;
};
const PinnedFiles = ({ renderFile }: Props) => {
const { useExplorerStore } = useExplorer();
@ -26,8 +26,8 @@ const PinnedFiles = ({ renderFile }: Props) => {
<PinContainer>
<PinHeader />
<PinContent>
{getDisplayedPinnedFiles().map((file) =>
renderFile(file, true)
{getDisplayedPinnedFiles().map((file, index) =>
renderFile(file, index, true)
)}
</PinContent>
</PinContainer>

View file

@ -27,9 +27,9 @@ const FileTree = ({ onOpenFoldersPane = () => {} }: Props) => {
);
const { files } = useChangeFile();
const renderFile = (file: TFile, disableDrag?: boolean) => (
const renderFile = (file: TFile, index: number, disableDrag?: boolean) => (
<File
key={file.path}
key={file.path + index}
file={file}
disableDrag={disableDrag}
onOpenFoldersPane={onOpenFoldersPane}
@ -48,7 +48,7 @@ const FileTree = ({ onOpenFoldersPane = () => {} }: Props) => {
return (
<div className="ffs__tree ffs__file-tree nav-files-container">
<PinnedFiles renderFile={renderFile} />
{sortedFiles.map((file) => renderFile(file))}
{sortedFiles.map((file, index) => renderFile(file, index))}
</div>
);
};