feat: Auto-select the first file if none is selected

This commit is contained in:
linonetwo 2025-12-13 14:11:19 +08:00
parent 4853ec6061
commit e5dc4e3ffc

View file

@ -10,7 +10,7 @@ import { styled } from '@mui/material/styles';
import Tab from '@mui/material/Tab';
import Tabs from '@mui/material/Tabs';
import Typography from '@mui/material/Typography';
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import { getFileStatusStyles, type GitFileStatus } from './fileStatusStyles';
@ -85,6 +85,13 @@ export function CommitDetailsPanel(
// Use files from commit entry (already loaded in useGitLogData)
const fileChanges = commit?.files ?? [];
// Auto-select the first file if none is selected
useEffect(() => {
if (fileChanges.length > 0 && !selectedFile && onFileSelect) {
onFileSelect(fileChanges[0].path);
}
}, [commit, fileChanges, selectedFile, onFileSelect]);
const handleRevert = async () => {
if (!commit || isReverting) return;
@ -141,7 +148,7 @@ export function CommitDetailsPanel(
const handleCopyHash = () => {
if (!commit) return;
navigator.clipboard.writeText(commit.hash);
void navigator.clipboard.writeText(commit.hash);
};
const handleOpenInGitHub = async () => {