added local forage support for config saving
parent
cb0c3966e1
commit
6492047c7c
|
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"localforage": "^1.7.2",
|
||||||
"lodash": "^4.17.10",
|
"lodash": "^4.17.10",
|
||||||
"namor": "^1.0.1",
|
"namor": "^1.0.1",
|
||||||
"papaparse": "^4.5.0",
|
"papaparse": "^4.5.0",
|
||||||
|
|
@ -23,6 +24,7 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^23.1.1",
|
"@types/jest": "^23.1.1",
|
||||||
|
"@types/localforage": "^0.0.34",
|
||||||
"@types/lodash": "^4.14.110",
|
"@types/lodash": "^4.14.110",
|
||||||
"@types/node": "^10.3.4",
|
"@types/node": "^10.3.4",
|
||||||
"@types/papaparse": "^4.5.0",
|
"@types/papaparse": "^4.5.0",
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import * as React from 'react';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
import ServerTable from './ServerTable';
|
import ServerTable from './ServerTable';
|
||||||
import { Tabs, TabList, TabPanel, Tab } from 'react-tabs';
|
import { Tabs, TabList, TabPanel, Tab } from 'react-tabs';
|
||||||
|
import * as local from 'localforage';
|
||||||
import './Tabs.css';
|
import './Tabs.css';
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,10 +18,40 @@ export default class ServerTabLoader extends React.Component<any, any> {
|
||||||
const jsonObj = JSON.parse(jsonStr);
|
const jsonObj = JSON.parse(jsonStr);
|
||||||
const tabList = _.get<any>(jsonObj, 'tabList', []);
|
const tabList = _.get<any>(jsonObj, 'tabList', []);
|
||||||
this.setState({ tabList });
|
this.setState({ tabList });
|
||||||
|
local.setItem('config', jsonObj).catch((err: any) => {
|
||||||
|
console.error('error occurred when saving config', err);
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.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() {
|
public render() {
|
||||||
|
|
|
||||||
22
yarn.lock
22
yarn.lock
|
|
@ -30,6 +30,12 @@
|
||||||
version "23.1.1"
|
version "23.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.1.tgz#c54ab1a5f41aa693c0957222dd10414416d0c87b"
|
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.1.tgz#c54ab1a5f41aa693c0957222dd10414416d0c87b"
|
||||||
|
|
||||||
|
"@types/localforage@^0.0.34":
|
||||||
|
version "0.0.34"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/localforage/-/localforage-0.0.34.tgz#5e31c32dd8791ec4b9ff3ef47c9cb55b2d0d9438"
|
||||||
|
dependencies:
|
||||||
|
localforage "*"
|
||||||
|
|
||||||
"@types/lodash@^4.14.110":
|
"@types/lodash@^4.14.110":
|
||||||
version "4.14.110"
|
version "4.14.110"
|
||||||
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.110.tgz#fb07498f84152947f30ea09d89207ca07123461e"
|
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.110.tgz#fb07498f84152947f30ea09d89207ca07123461e"
|
||||||
|
|
@ -3334,6 +3340,10 @@ ignore-walk@^3.0.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
minimatch "^3.0.4"
|
minimatch "^3.0.4"
|
||||||
|
|
||||||
|
immediate@~3.0.5:
|
||||||
|
version "3.0.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.0.6.tgz#9db1dbd0faf8de6fbe0f5dd5e56bb606280de69b"
|
||||||
|
|
||||||
import-lazy@^2.1.0:
|
import-lazy@^2.1.0:
|
||||||
version "2.1.0"
|
version "2.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
|
resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43"
|
||||||
|
|
@ -4264,6 +4274,12 @@ levn@~0.3.0:
|
||||||
prelude-ls "~1.1.2"
|
prelude-ls "~1.1.2"
|
||||||
type-check "~0.3.2"
|
type-check "~0.3.2"
|
||||||
|
|
||||||
|
lie@3.1.1:
|
||||||
|
version "3.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/lie/-/lie-3.1.1.tgz#9a436b2cc7746ca59de7a41fa469b3efb76bd87e"
|
||||||
|
dependencies:
|
||||||
|
immediate "~3.0.5"
|
||||||
|
|
||||||
load-json-file@^1.0.0:
|
load-json-file@^1.0.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
|
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
|
||||||
|
|
@ -4304,6 +4320,12 @@ loader-utils@^1.0.2, loader-utils@^1.1.0:
|
||||||
emojis-list "^2.0.0"
|
emojis-list "^2.0.0"
|
||||||
json5 "^0.5.0"
|
json5 "^0.5.0"
|
||||||
|
|
||||||
|
localforage@*, localforage@^1.7.2:
|
||||||
|
version "1.7.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/localforage/-/localforage-1.7.2.tgz#fa4442602f806edd2bca6a54ab4e656f031f121c"
|
||||||
|
dependencies:
|
||||||
|
lie "3.1.1"
|
||||||
|
|
||||||
locate-path@^2.0.0:
|
locate-path@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
|
resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue