mirror of
https://github.com/status-im/sourcecred.git
synced 2025-01-12 21:54:37 +00:00
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:
parent
ed1f17f8ca
commit
bb2ec756a4
@ -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>
|
||||
|
5
src/app/credExplorer/LocalStore.js
Normal file
5
src/app/credExplorer/LocalStore.js
Normal file
@ -0,0 +1,5 @@
|
||||
// @flow
|
||||
|
||||
import LocalStore from "../LocalStore";
|
||||
|
||||
export default new LocalStore({version: "1", keyPrefix: "cred-explorer"});
|
Loading…
x
Reference in New Issue
Block a user