Skip to content

Commit bb3c10f

Browse files
committed
feat(repo): Optimize warehouse file path display and navigation
1 parent d3fd0c9 commit bb3c10f

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

git/src/tree/msg_tree.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,34 @@ impl AppGit {
124124
for delta in diff.deltas() {
125125
let file = delta.new_file();
126126
if let Some(path) = file.path() {
127+
if let Some(Some(parent_dir)) = path.parent().map(|x|x.to_str().map(|x|x.to_string())) {
128+
if !has.contains(&parent_dir.to_string()) {
129+
if let Some(item) = state_tree.iter().find(|x| x.to_path().starts_with(&parent_dir)) {
130+
if item.rtype == "tree".to_string() {
131+
let msg_index = result.insert_data(msg.clone());
132+
result.file.push((item.clone(), msg_index));
133+
has.push(parent_dir.to_string());
134+
}
135+
}
136+
}
137+
}
127138
if let Some(path) = path.to_str().map(|x| x.to_string()) {
128139
if has.contains(&path) {
129140
continue;
130141
}
131142
if let Some(item) = state_tree.iter().find(|x| x.to_path() == path) {
132-
let msg_index = result.insert_data(msg.clone());
133-
result.file.push((item.clone(), msg_index));
134-
has.push(item.to_path());
143+
if item.rtype == "blob".to_string() {
144+
let msg_index = result.insert_data(msg.clone());
145+
result.file.push((item.clone(), msg_index));
146+
has.push(item.to_path());
147+
}
135148
}
136149
}
137150
}
138151
}
152+
if has.len() == state_tree.len() {
153+
break;
154+
}
139155
commit = parent;
140156
}
141157
Ok(result)

views/src/app/repository/files.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface FileApiResponse {
4646
}
4747

4848
export const RepoFiles = () => {
49-
const { owner, repo, path } = useParams<{ owner: string; repo: string; path?: string }>();
49+
const { owner, repo, '*': path } = useParams();
5050
const navigate = useNavigate();
5151
const [loading, setLoading] = useState(true);
5252
const [error, setError] = useState<string | null>(null);
@@ -112,14 +112,26 @@ export const RepoFiles = () => {
112112
{files.length ? (
113113
<div className="h-[calc(100vh-250px)] overflow-auto">
114114
<div>
115+
{
116+
path != "" && path && (
117+
<div>
118+
<div className="flex items-center" onClick={() => {
119+
navigate(`/${owner}/${repo}/tree/${path.split('/').slice(0, -1).join('/')}`);
120+
}}>
121+
<GitBranch size={18} className="mr-2 text-blue-500" />
122+
<div>...</div>
123+
</div>
124+
</div>
125+
)
126+
}
115127
{files.map(([file, idx], index) => (
116128
<div
117129
key={index}
118130
className={`cursor-pointer ${index === files.length - 1 ? '' : 'border-b border-gray-200'} flex items-center justify-between`}
119131
onClick={() => {
120132
if (file.rtype === 'tree') {
121133
const newPath = path ? `${path}/${file.name}` : file.name;
122-
navigate(`/repo/${owner}/${repo}/tree/${newPath}`);
134+
navigate(`/${owner}/${repo}/tree/${newPath}`);
123135
}
124136
}}
125137
>

views/src/routes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export default function AppRoutes() {
6262
element: <RepoCommit/>
6363
},
6464
{
65-
path: 'tree/:path*',
65+
path: 'tree/*',
6666
element: <RepoFiles/>
6767
}
6868
]

0 commit comments

Comments
 (0)