//@flow import React from "react"; import { Hunk, Diff as DiffComponent } from "react-diff-view"; import injectSheets from "react-jss"; import classNames from "classnames"; import {translate} from "react-i18next"; const styles = { panel: { fontSize: "1rem" }, header: { cursor: "pointer" }, title: { marginLeft: ".25rem", fontSize: "1rem" }, hunkDivider: { margin: ".5rem 0" } }; type Props = { file: any, sideBySide: boolean, // context props classes: any, t: string => string } type State = { collapsed: boolean } class DiffFile extends React.Component { constructor(props: Props) { super(props); this.state = { collapsed: false }; } toggleCollapse = () => { this.setState((state) => ({ collapsed: ! state.collapsed })); }; renderHunk = (hunk: any, i: number) => { const { classes } = this.props; let header = null; if (i > 0) { header =
; } return ; }; renderFileTitle = (file: any) => { if (file.oldPath !== file.newPath && (file.type === "copy" || file.type === "rename")) { return (<>{file.oldPath} {file.newPath}); } else if (file.type === "delete") { return file.oldPath; } return file.newPath; }; renderChangeTag = (file: any) => { const { t } = this.props; const key = "diff.changes." + file.type; let value = t(key); if (key === value) { value = file.type; } return ( {value} ); }; render() { const { file, sideBySide, classes } = this.props; const { collapsed } = this.state; const viewType = sideBySide ? "split" : "unified"; let body = null; let icon = "fa fa-angle-right"; if (!collapsed) { icon = "fa fa-angle-down"; body = (
{ file.hunks.map(this.renderHunk) }
); } return (
{this.renderFileTitle(file)}
{this.renderChangeTag(file)}
{body}
); } } export default injectSheets(styles)(translate("repos")(DiffFile));