1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

Add collapsed state for storage

The root cause of this issue is that when the folder is clicked,
the router pushed the path and the StorageItem component has been
refreshed and isOpen has been reset

- Add storing collapse state for storage
- Add tests
- Default as collapsed for fallback

fix BoostIo/Boostnote#1979 BoostIo/Boostnote#1911
This commit is contained in:
Kelvin Wong
2018-06-28 13:08:39 +08:00
parent 6401016424
commit 8a6c86bf65
7 changed files with 93 additions and 5 deletions

View File

@@ -21,8 +21,10 @@ class StorageItem extends React.Component {
constructor (props) {
super(props)
const { storage } = this.props
this.state = {
isOpen: true
isOpen: !!storage.isOpen
}
}
@@ -68,8 +70,18 @@ class StorageItem extends React.Component {
}
handleToggleButtonClick (e) {
const { storage, dispatch } = this.props
const isOpen = !this.state.isOpen
dataApi.toggleStorage(storage.key, isOpen)
.then((storage) => {
dispatch({
type: 'EXPAND_STORAGE',
storage: storage,
isOpen: isOpen
})
})
this.setState({
isOpen: !this.state.isOpen
isOpen: isOpen
})
}