Save explorer’s repo settings in localStorage (#263)

Test Plan:
Load the cred explorer for the first time to see two empty boxes.
Refresh to see the same thing. Then, add some content to each box.
Refresh and see the same content.

wchargin-branch: cred-explorer-localstorage
This commit is contained in:
William Chargin 2018-05-10 14:42:54 -07:00 committed by GitHub
parent ed1f17f8ca
commit bb2ec756a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -4,9 +4,10 @@ import stringify from "json-stable-stringify";
import React from "react";
import {StyleSheet, css} from "aphrodite/no-important";
import type {PagerankResult} from "./basicPagerank";
import {Graph} from "../../core/graph";
import type {PagerankResult} from "./basicPagerank";
import basicPagerank from "./basicPagerank";
import LocalStore from "./LocalStore";
type Props = {};
type State = {
@ -15,6 +16,9 @@ type State = {
graph: ?Graph<mixed, mixed>,
};
const REPO_OWNER_KEY = "repoOwner";
const REPO_NAME_KEY = "repoName";
export default class App extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
@ -25,6 +29,13 @@ export default class App extends React.Component<Props, State> {
};
}
componentDidMount() {
this.setState((state) => ({
repoOwner: LocalStore.get(REPO_OWNER_KEY, state.repoOwner),
repoName: LocalStore.get(REPO_NAME_KEY, state.repoName),
}));
}
render() {
const {graph} = this.state;
return (
@ -40,7 +51,9 @@ export default class App extends React.Component<Props, State> {
value={this.state.repoOwner}
onChange={(e) => {
const value = e.target.value;
this.setState({repoOwner: value});
this.setState({repoOwner: value}, () => {
LocalStore.set(REPO_OWNER_KEY, this.state.repoOwner);
});
}}
/>
</label>
@ -51,7 +64,9 @@ export default class App extends React.Component<Props, State> {
value={this.state.repoName}
onChange={(e) => {
const value = e.target.value;
this.setState({repoName: value});
this.setState({repoName: value}, () => {
LocalStore.set(REPO_NAME_KEY, this.state.repoName);
});
}}
/>
</label>

View File

@ -0,0 +1,5 @@
// @flow
import LocalStore from "../LocalStore";
export default new LocalStore({version: "1", keyPrefix: "cred-explorer"});