added local forage support for config saving
This commit is contained in:
@@ -2,6 +2,7 @@ import * as React from 'react';
|
||||
import * as _ from 'lodash';
|
||||
import ServerTable from './ServerTable';
|
||||
import { Tabs, TabList, TabPanel, Tab } from 'react-tabs';
|
||||
import * as local from 'localforage';
|
||||
import './Tabs.css';
|
||||
|
||||
|
||||
@@ -17,10 +18,40 @@ export default class ServerTabLoader extends React.Component<any, any> {
|
||||
const jsonObj = JSON.parse(jsonStr);
|
||||
const tabList = _.get<any>(jsonObj, 'tabList', []);
|
||||
this.setState({ tabList });
|
||||
local.setItem('config', jsonObj).catch((err: any) => {
|
||||
console.error('error occurred when saving config', err);
|
||||
});
|
||||
})
|
||||
.catch((e) => {
|
||||
this.setState({ message: e.stack, showMessage: true });
|
||||
console.error('error occurred when loading config', e);
|
||||
});
|
||||
// TODO: enable localstore to load config
|
||||
// const onLocal = (config: any) => {
|
||||
// if (config) {
|
||||
// const tabList = _.get<any>(config, 'tabList', []);
|
||||
// this.setState({ tabList });
|
||||
// } else {
|
||||
// fetch('/config.json')
|
||||
// .then((response) => response.text())
|
||||
// .then((jsonStr) => {
|
||||
// const jsonObj = JSON.parse(jsonStr);
|
||||
// const tabList = _.get<any>(jsonObj, 'tabList', []);
|
||||
// this.setState({ tabList });
|
||||
// local.setItem('config', jsonObj).then((val: any) => {
|
||||
// console.log('saved to localstore ',val);
|
||||
// }).catch((err:any) => {
|
||||
// console.error('error occurred when saving config', err);
|
||||
// });
|
||||
// })
|
||||
// .catch((e) => {
|
||||
// this.setState({ message: e.stack, showMessage: true });
|
||||
// });
|
||||
// }
|
||||
// };
|
||||
// local.getItem('config').then(onLocal).catch((err: any) => {
|
||||
// // This code runs if there were any errors
|
||||
// console.error('error occurred when getting config from localstore', err);
|
||||
// });
|
||||
}
|
||||
|
||||
public render() {
|
||||
|
||||
Reference in New Issue
Block a user