11import React from 'react'
22import { remote } from 'electron'
3+ import fs from 'fs'
4+ import { Action } from 'redux'
35
46import TextInput from '../form/TextInput'
57import ButtonInput from '../form/ButtonInput'
68import Icon from '../chrome/Icon'
79import ExternalLink from '../ExternalLink'
10+ import { connect } from 'react-redux'
11+ import Store , { ToastType } from '../../models/store'
12+
13+ import {
14+ openToast
15+ } from '../../actions/ui'
16+ import classNames from 'classnames'
817
918export interface CompareParams {
1019 left : string
@@ -14,9 +23,10 @@ export interface CompareParams {
1423export interface CompareSidebarProps {
1524 data : CompareParams
1625 onChange : ( p : CompareParams ) => void
26+ openToast : ( type : ToastType , name : string , message : string ) => Action
1727}
1828
19- const CompareSidebar : React . FC < CompareSidebarProps > = ( { data, onChange } ) => {
29+ export const CompareSidebarComponent : React . FC < CompareSidebarProps > = ( { data, onChange, openToast , closeToast } ) => {
2030 const pathPicker = ( side : string ) => {
2131 const window = remote . getCurrentWindow ( )
2232 const filePaths : string [ ] | undefined = remote . dialog . showOpenDialogSync ( window , {
@@ -32,12 +42,22 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
3242 return
3343 }
3444
45+ let filepath = filePaths [ 0 ]
46+
47+ const stats = fs . statSync ( filepath )
48+
49+ // if over 10 mb reject
50+ if ( stats . size > ( 1024 * 1000 * 10 ) ) {
51+ filepath = ''
52+ openToast ( "error" , "file size" , "file must be under 10MB" )
53+ }
54+
3555 switch ( side ) {
3656 case 'left' :
37- onChange ( { left : filePaths [ 0 ] , right : data . right } )
57+ onChange ( { left : filepath , right : data . right } )
3858 break
3959 case 'right' :
40- onChange ( { right : filePaths [ 0 ] , left : data . left } )
60+ onChange ( { right : filepath , left : data . left } )
4161 break
4262 }
4363 }
@@ -54,8 +74,9 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
5474
5575 return (
5676 < div className = 'compare-sidebar sidebar' >
57- < div className = 'sidebar-header sidebar-padded-container' >
77+ < div className = 'sidebar-header sidebar-padded-container compare-sidebar-header ' >
5878 < p className = 'pane-title' > Compare</ p >
79+ < div className = { classNames ( 'reset' , { disabled : ! ( data . left || data . right ) } ) } onClick = { ( ) => { onChange ( { right : '' , left : '' } ) } } > reset</ div >
5980 </ div >
6081 < div className = 'sidebar-padded-container' >
6182 < div className = 'picker' >
@@ -105,4 +126,11 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
105126 )
106127}
107128
108- export default CompareSidebar
129+ const mapStateToProps = ( state : Store , ownProps : CompareSidebarProps ) => {
130+ return ownProps
131+ }
132+
133+ // TODO (b5) - this component doesn't need to be a container. Just feed it the right data
134+ export default connect ( mapStateToProps , {
135+ openToast
136+ } ) ( CompareSidebarComponent )
0 commit comments