mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +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:
28
browser/main/lib/dataApi/toggleStorage.js
Normal file
28
browser/main/lib/dataApi/toggleStorage.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const _ = require('lodash')
|
||||
const resolveStorageData = require('./resolveStorageData')
|
||||
|
||||
/**
|
||||
* @param {String} key
|
||||
* @param {Boolean} isOpen
|
||||
* @return {Object} Storage meta data
|
||||
*/
|
||||
function toggleStorage (key, isOpen) {
|
||||
let cachedStorageList
|
||||
try {
|
||||
cachedStorageList = JSON.parse(localStorage.getItem('storages'))
|
||||
if (!_.isArray(cachedStorageList)) throw new Error('invalid storages')
|
||||
} catch (err) {
|
||||
console.log('error got')
|
||||
console.error(err)
|
||||
return Promise.reject(err)
|
||||
}
|
||||
const targetStorage = _.find(cachedStorageList, {key: key})
|
||||
if (targetStorage == null) return Promise.reject('Storage')
|
||||
|
||||
targetStorage.isOpen = isOpen
|
||||
localStorage.setItem('storages', JSON.stringify(cachedStorageList))
|
||||
|
||||
return resolveStorageData(targetStorage)
|
||||
}
|
||||
|
||||
module.exports = toggleStorage
|
||||
Reference in New Issue
Block a user