MCPcopy Create free account
hub / github.com/danvk/webdiff / FileList

Function FileList

ts/FileList.tsx:15–52  ·  view source on GitHub ↗
(props: Props)

Source from the content-addressed store, hash-verified

13 * This view is simpler and generally preferable for short lists of files.
14 */
15export function FileList(props: Props) {
16 const {filePairs, selectedIndex, fileChangeHandler} = props;
17
18 const anyWithDiffstats = filePairs.some(fp => fp.num_add !== null || fp.num_delete !== null);
19 const maxDelta = React.useMemo(() => {
20 return Math.max(1, ...filePairs.map(fp => (fp.num_add ?? 0) + (fp.num_delete ?? 0)));
21 }, [filePairs]);
22
23 const lis = filePairs.map((filePair, idx) => {
24 const displayName = filePairDisplayName(filePair);
25 const content =
26 idx !== selectedIndex ? (
27 <a
28 onClick={() => {
29 fileChangeHandler(idx);
30 }}
31 href="#">
32 {displayName}
33 </a>
34 ) : (
35 <b>{displayName}</b>
36 );
37 return (
38 <li key={idx}>
39 {anyWithDiffstats ? (
40 <SparkChart
41 maxDelta={maxDelta}
42 numAdd={filePair.num_add}
43 numDelete={filePair.num_delete}
44 />
45 ) : null}
46 <span title={filePair.type} className={`diff ${filePair.type}`} />
47 {content}
48 </li>
49 );
50 });
51 return <ul className="file-list">{lis}</ul>;
52}
53
54interface SparkChartProps {
55 maxDelta: number;

Callers

nothing calls this directly

Calls 1

filePairDisplayNameFunction · 0.90

Tested by

no test coverage detected