Skip to content

Commit 225d00d

Browse files
feat: format date, sort repository files
Signed-off-by: roman-kiselenko <roman.kiselenko.dev@gmail.com>
1 parent e6333b3 commit 225d00d

File tree

4 files changed

+42
-57
lines changed

4 files changed

+42
-57
lines changed

frontend/src/components/views/ColumnDef.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

frontend/src/components/views/RepoViewPage.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { useEffect, useState } from 'react';
77
import { useReposState, getRepos } from '@/store/repositories';
88
import { useRepoFilesState, getRepoFiles } from '@/store/repofiles';
99
import { Repo } from '@/types';
10-
import { DataTable } from '@/components/ui/DataTable';
11-
import columns from '@/components/views/ColumnDef';
1210
import { Input } from '@/components/ui/input';
1311
import { useAuth } from '@/context/AuthProvider';
12+
import { CardContent, CardHeader } from '@/components/ui/card';
13+
import timeAgo from '@/timeAgo';
14+
import moment from 'moment';
1415

15-
// type FileTreeItem = { name: string } | { name: string; items: FileTreeItem[] };
16+
type FileTreeItem = { name: string } | { name: string; items: FileTreeItem[] };
1617

1718
export function RepoViewPage() {
1819
const { user, repoPath } = useParams<{ user: string; repoPath: string }>();
@@ -30,12 +31,12 @@ export function RepoViewPage() {
3031

3132
useEffect(() => {
3233
if (!user || !repoPath) return;
33-
getRepoFiles(user, repoPath);
34-
}, [user]);
34+
getRepoFiles(searchQuery, user, repoPath);
35+
}, [user, searchQuery]);
3536

3637
return (
3738
<div className="flex-grow overflow-auto">
38-
<div className="flex flex-row py-2 px-2 items-center justify-between mx-3">
39+
<div className="flex flex-row py-2 px-4 items-center justify-between mx-3">
3940
<Input
4041
placeholder="Filter by name..."
4142
className="placeholder:text-muted-foreground flex h-6 w-full rounded-md bg-transparent py-2 text-sm outline-hidden disabled:cursor-not-allowed disabled:opacity-50"
@@ -48,25 +49,31 @@ export function RepoViewPage() {
4849
)}
4950
</div>
5051

51-
<div className="flex flex-row py-2 px-2 items-center justify-between mx-3">
52-
<div className="text-sm">Author: {repoFiles.author.get()}</div>
53-
<div className="text-sm">Email: {repoFiles.email.get()}</div>
54-
<div className="text-sm">Date: {repoFiles.date.get()}</div>
55-
<div className="text-sm">Hash: {repoFiles.hash.get()}</div>
52+
<div className="flex flex-row py-2 px-4 items-center justify-between mx-3">
53+
<div className="text-sm hover:text-ring">{repoFiles.author.get()}</div>
54+
<div className="text-sm hover:text-ring">{repoFiles.email.get()}</div>
55+
<div className="text-sm hover:text-ring" title={repoFiles.date.get()}>
56+
Last commit: {timeAgo.format(moment(repoFiles.date.get()).toDate(), 'mini')}
57+
</div>
58+
<div className="text-sm hover:text-ring">Last hash: {repoFiles.hash.get()}</div>
5659
</div>
57-
<div className="grid grid-cols-1">
58-
<div className="mx-3">
60+
<div className="grid grid-cols-2">
61+
<CardContent className="px-4">
5962
<div className="flex flex-col gap-1">
60-
{(repoFiles.files.get() || []).map((item) => renderItem(item))}
63+
{repoFiles.files
64+
.get()
65+
.toSorted((a: any, b: any) => b.items?.length - a.items?.length)
66+
.map((item) => renderItem(item as FileTreeItem))}
6167
</div>
62-
</div>
68+
<div className="flex flex-col gap-1"></div>
69+
</CardContent>
6370
</div>
6471
</div>
6572
);
6673
}
6774

68-
const renderItem = (fileItem: any) => {
69-
if ('items' in fileItem) {
75+
const renderItem = (fileItem: FileTreeItem) => {
76+
if ('items' in fileItem && fileItem.items.length > 0) {
7077
return (
7178
<Collapsible key={fileItem.name}>
7279
<CollapsibleTrigger asChild>

frontend/src/store/repofiles.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@ export const repoFilesState = hookstate<{
1818
date: '',
1919
});
2020

21-
export async function getRepoFiles(userName: string | undefined, repoName: string | undefined) {
21+
export async function getRepoFiles(
22+
query: string,
23+
userName: string | undefined,
24+
repoName: string | undefined,
25+
) {
2226
try {
2327
let response = await call<any[]>(`repos/files/${userName}/${repoName}`);
28+
let files = response.files;
29+
if (query !== '') {
30+
files = files.filter((c) => {
31+
return String(c.name || '')
32+
.toLowerCase()
33+
.includes(query.toLowerCase());
34+
});
35+
}
36+
2437
repoFilesState.set({
25-
files: response.files,
38+
files: files,
2639
hash: response.hash,
2740
message: response.message,
2841
author: response.author,

pkg/route/files.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,9 @@ import (
1212
"github.com/go-git/go-git/v5/plumbing/object"
1313
)
1414

15-
// type Node struct {
16-
// Name string `json:"filename"`
17-
// IsDir bool `json:"is_dir"`
18-
// Children map[string]*Node `json:"children"`
19-
// Path string `json:"path"`
20-
// }
21-
2215
type Node struct {
23-
Name string `json:"name,omitempty"`
24-
Items []Node `json:"items,omitempty"`
16+
Name string `json:"name"`
17+
Items []Node `json:"items"`
2518
}
2619

2720
// buildFileTree constructs the hierarchical tree from a list of file paths
@@ -74,7 +67,7 @@ func buildFileTree(paths []string) *Node {
7467
current.Items = append(current.Items, *newNode)
7568
} else {
7669
// Add a file node
77-
current.Items = append(current.Items, Node{Name: lastPart})
70+
current.Items = append(current.Items, Node{Name: lastPart, Items: []Node{}})
7871
}
7972
}
8073

0 commit comments

Comments
 (0)