Skip to content

Commit 238bfa8

Browse files
authored
hide sync toggle in empty TLFs (keybase#20891)
1 parent 0ace8cc commit 238bfa8

4 files changed

Lines changed: 40 additions & 33 deletions

File tree

‎shared/fs/top-bar/index.stories.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const topBarProvider = {
1010
SyncToggle: () => ({
1111
disableSync: Sb.action('disableSync'),
1212
enableSync: Sb.action('enableSyncisableSync'),
13+
hideSyncToggle: false,
1314
syncConfig: Constants.tlfSyncEnabled,
1415
waiting: false,
1516
}),
Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {namedConnect} from '../../util/container'
1+
import * as Container from '../../util/container'
22
import SyncToggle from './sync-toggle'
33
import * as Types from '../../constants/types/fs'
44
import * 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-
3313
export 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)

‎shared/fs/top-bar/sync-toggle.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as Types from '../../constants/types/fs'
66
export type Props = {
77
disableSync: () => void
88
enableSync: () => void
9+
hideSyncToggle: boolean
910
syncConfig?: Types.TlfSyncConfig | null
1011
waiting: boolean
1112
} & Kb.OverlayParentProps
@@ -59,7 +60,7 @@ const Confirm = props => (
5960
)
6061

6162
const SyncToggle = (props: Props) =>
62-
props.syncConfig ? (
63+
props.syncConfig && !props.hideSyncToggle ? (
6364
<>
6465
<Kb.Switch
6566
align="right"

‎shared/stories/__tests__/__snapshots__/Storyshots.test.js.snap‎

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)