1
1
import React from 'react'
2
2
import { remote } from 'electron'
3
+ import fs from 'fs'
4
+ import { Action } from 'redux'
3
5
4
6
import TextInput from '../form/TextInput'
5
7
import ButtonInput from '../form/ButtonInput'
6
8
import Icon from '../chrome/Icon'
7
9
import 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'
8
17
9
18
export interface CompareParams {
10
19
left : string
@@ -14,9 +23,10 @@ export interface CompareParams {
14
23
export interface CompareSidebarProps {
15
24
data : CompareParams
16
25
onChange : ( p : CompareParams ) => void
26
+ openToast : ( type : ToastType , name : string , message : string ) => Action
17
27
}
18
28
19
- const CompareSidebar : React . FC < CompareSidebarProps > = ( { data, onChange } ) => {
29
+ export const CompareSidebarComponent : React . FC < CompareSidebarProps > = ( { data, onChange, openToast , closeToast } ) => {
20
30
const pathPicker = ( side : string ) => {
21
31
const window = remote . getCurrentWindow ( )
22
32
const filePaths : string [ ] | undefined = remote . dialog . showOpenDialogSync ( window , {
@@ -32,12 +42,22 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
32
42
return
33
43
}
34
44
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
+
35
55
switch ( side ) {
36
56
case 'left' :
37
- onChange ( { left : filePaths [ 0 ] , right : data . right } )
57
+ onChange ( { left : filepath , right : data . right } )
38
58
break
39
59
case 'right' :
40
- onChange ( { right : filePaths [ 0 ] , left : data . left } )
60
+ onChange ( { right : filepath , left : data . left } )
41
61
break
42
62
}
43
63
}
@@ -54,8 +74,9 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
54
74
55
75
return (
56
76
< div className = 'compare-sidebar sidebar' >
57
- < div className = 'sidebar-header sidebar-padded-container' >
77
+ < div className = 'sidebar-header sidebar-padded-container compare-sidebar-header ' >
58
78
< p className = 'pane-title' > Compare</ p >
79
+ < div className = { classNames ( 'reset' , { disabled : ! ( data . left || data . right ) } ) } onClick = { ( ) => { onChange ( { right : '' , left : '' } ) } } > reset</ div >
59
80
</ div >
60
81
< div className = 'sidebar-padded-container' >
61
82
< div className = 'picker' >
@@ -105,4 +126,11 @@ const CompareSidebar: React.FC<CompareSidebarProps> = ({ data, onChange }) => {
105
126
)
106
127
}
107
128
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