1- import { namedConnect } from '../../util/container'
1+ import * as Container from '../../util/container'
22import SyncToggle from './sync-toggle'
33import * as Types from '../../constants/types/fs'
44import * as Constants from '../../constants/fs'
@@ -10,26 +10,31 @@ type OwnProps = {
1010 tlfPath : Types . Path
1111}
1212
13- const mapStateToProps = state => ( {
14- _tlfs : state . fs . tlfs ,
15- waiting : anyWaiting ( state , Constants . syncToggleWaitingKey ) ,
16- } )
17-
18- const mapDispatchToProps = ( dispatch , { tlfPath} : OwnProps ) => ( {
19- disableSync : ( ) => dispatch ( FsGen . createSetTlfSyncConfig ( { enabled : false , tlfPath} ) ) ,
20- enableSync : ( ) => dispatch ( FsGen . createSetTlfSyncConfig ( { enabled : true , tlfPath} ) ) ,
21- } )
22-
23- const mergeProps = (
24- stateProps : ReturnType < typeof mapStateToProps > ,
25- dispatchProps : ReturnType < typeof mapDispatchToProps > ,
26- { tlfPath} : OwnProps
27- ) => ( {
28- syncConfig : Constants . getTlfFromPath ( stateProps . _tlfs , tlfPath ) . syncConfig ,
29- waiting : stateProps . waiting ,
30- ...dispatchProps ,
31- } )
32-
3313export default ( flags . kbfsOfflineMode
34- ? namedConnect ( mapStateToProps , mapDispatchToProps , mergeProps , 'SyncToggle' ) ( SyncToggle )
14+ ? Container . connect (
15+ ( state : Container . TypedState , ownProps : OwnProps ) => ( {
16+ _tlfPathItem : Constants . getPathItem ( state . fs . pathItems , ownProps . tlfPath ) ,
17+ _tlfs : state . fs . tlfs ,
18+ waiting : anyWaiting ( state , Constants . syncToggleWaitingKey ) ,
19+ } ) ,
20+ ( dispatch , { tlfPath} : OwnProps ) => ( {
21+ disableSync : ( ) => dispatch ( FsGen . createSetTlfSyncConfig ( { enabled : false , tlfPath} ) ) ,
22+ enableSync : ( ) => dispatch ( FsGen . createSetTlfSyncConfig ( { enabled : true , tlfPath} ) ) ,
23+ } ) ,
24+ ( stateProps , dispatchProps , { tlfPath} : OwnProps ) => {
25+ const syncConfig = Constants . getTlfFromPath ( stateProps . _tlfs , tlfPath ) . syncConfig
26+ return {
27+ // Disable sync when the TLF is empty and it's not enabled yet.
28+ // Band-aid fix for when new user has a non-exisitent TLF which we
29+ // can't enable sync for yet.
30+ hideSyncToggle :
31+ syncConfig . mode === Types . TlfSyncMode . Disabled &&
32+ stateProps . _tlfPathItem . type === Types . PathType . Folder &&
33+ ! stateProps . _tlfPathItem . children . size ,
34+ syncConfig,
35+ waiting : stateProps . waiting ,
36+ ...dispatchProps ,
37+ }
38+ }
39+ ) ( SyncToggle )
3540 : ( ) => null )
0 commit comments