|
1 | 1 | import React from "react"; |
2 | | -import dayjs from "dayjs"; |
3 | 2 | import { List } from "antd"; |
4 | 3 | import cn from "classnames"; |
5 | | -import { Link } from "react-router-dom"; |
| 4 | +import { RepoIdentity, GitFile, GitCommit } from "models"; |
| 5 | +import { useBranch } from "../../hooks"; |
6 | 6 | import SkeletonArea from "../skeleton-area"; |
7 | | - |
8 | | -// FIXME: import as ReactComponent |
9 | | -import FileIcon from "../../assets/file.svg"; |
10 | | -import FolderIcon from "../../assets/folder.svg"; |
11 | | -import logo from "./placeholder.png"; |
| 7 | +import GitFileView from "./git-file-view"; |
| 8 | +import LastCommitHeader from "./last-commit-header"; |
12 | 9 | import "./index.scss"; |
13 | 10 |
|
14 | | -type GitFile = { type: string; name: string }; |
15 | 11 | type Props = { |
16 | 12 | loading?: boolean; |
17 | 13 | files: Array<GitFile>; |
18 | 14 | className?: string; |
19 | | - lastCommit?: { |
20 | | - message: string; |
21 | | - login?: string; |
22 | | - avatarUrl?: string; |
23 | | - name?: string | null; |
24 | | - date: string; |
25 | | - }; |
| 15 | + repo: RepoIdentity; |
| 16 | + lastCommit?: GitCommit; |
26 | 17 | }; |
27 | 18 |
|
28 | | -const EntriesView = ({ loading, files, lastCommit, className }: Props) => { |
| 19 | +const EntriesView = ({ loading, files, lastCommit, className, repo }: Props) => { |
| 20 | + const { branch } = useBranch(repo); |
29 | 21 | return ( |
30 | 22 | <div className={cn("repo-git-view", className)}> |
31 | 23 | {loading && <SkeletonArea />} |
32 | 24 | {!loading && ( |
33 | 25 | <List |
34 | 26 | header={lastCommit && <LastCommitHeader lastCommit={lastCommit} />} |
35 | 27 | dataSource={files} |
36 | | - renderItem={GitFileView} |
| 28 | + renderItem={(item) => <GitFileView {...item} repo={repo} branch={branch} />} |
37 | 29 | /> |
38 | 30 | )} |
39 | 31 | </div> |
40 | 32 | ); |
41 | 33 | }; |
42 | 34 |
|
43 | | -const GitFileView = ({ name, type }: GitFile) => ( |
44 | | - <List.Item className="repo-git-view__item"> |
45 | | - <div> |
46 | | - <img alt="type" src={type === "tree" ? FolderIcon : FileIcon} /> |
47 | | - <span>{name}</span> |
48 | | - </div> |
49 | | - </List.Item> |
50 | | -); |
51 | | - |
52 | | -const LastCommitHeader = ({ lastCommit }: { lastCommit: Props["lastCommit"] }) => ( |
53 | | - <div className="repo-git-view__last-commit"> |
54 | | - <div> |
55 | | - {lastCommit?.avatarUrl ? ( |
56 | | - <> |
57 | | - <img src={lastCommit?.avatarUrl} alt="avatar" /> |
58 | | - <Link className="author-name" to={`/${lastCommit?.login}`}> |
59 | | - {lastCommit?.login} |
60 | | - </Link> |
61 | | - </> |
62 | | - ) : ( |
63 | | - <> |
64 | | - <img src={logo} alt="avatar" /> |
65 | | - <span className="author-name">{lastCommit?.name}</span> |
66 | | - </> |
67 | | - )} |
68 | | - |
69 | | - <span className="commit-message" title={lastCommit?.message}> |
70 | | - {lastCommit?.message} |
71 | | - </span> |
72 | | - </div> |
73 | | - <div> |
74 | | - <span className="commit-date">on {dayjs(lastCommit?.date).format("D MMM YYYY")}</span> |
75 | | - </div> |
76 | | - </div> |
77 | | -); |
78 | | - |
79 | 35 | export default EntriesView; |
0 commit comments