Skip to content

Commit 79e82dd

Browse files
committed
simplify
1 parent 262404a commit 79e82dd

1 file changed

Lines changed: 7 additions & 78 deletions

File tree

src/App.js

Lines changed: 7 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -5,93 +5,22 @@ export default class App extends React.Component {
55
constructor(props) {
66
super(props);
77

8-
this.axiom = new Axiom({ verbose: true });
8+
this.axiom = new Axiom();
99

1010
this.state = {
11-
publicKey: null,
12-
loadingMessage: null,
13-
bucket: null,
14-
counter: null
11+
message: null
1512
};
16-
17-
this.login = this.login.bind(this);
18-
this.createBucket = this.createBucket.bind(this);
19-
this.increment = this.increment.bind(this);
20-
}
21-
22-
async login() {
23-
let publicKey = await this.axiom.getPublicKey();
24-
this.setState({
25-
publicKey: publicKey
26-
});
27-
28-
this.setState({
29-
loadingMessage: "loading your data..."
30-
});
31-
32-
let bucket = await this.axiom.getBucket("counter", this.state.publicKey);
33-
if (bucket) {
34-
console.log("got bucket:", bucket);
35-
let data = await bucket.getJSON("counter.json");
36-
console.log("got data:", data);
37-
let counter = data ? data.counter : 0;
38-
this.setState({
39-
bucket: bucket,
40-
counter: counter,
41-
loadingMessage: null
42-
});
43-
} else {
44-
console.log("failed to get bucket");
45-
this.setState({
46-
loadingMessage: null
47-
});
48-
}
4913
}
5014

51-
async createBucket() {
52-
this.setState({
53-
loadingMessage: "creating a bucket..."
54-
});
55-
console.log("creating a bucket");
56-
await this.axiom.createBucket("counter", this.state.publicKey, 1);
57-
await this.login();
58-
}
59-
60-
async increment() {
61-
this.setState({
62-
loadingMessage: `saving counter = ${this.state.counter + 1}...`
63-
});
64-
this.state.bucket.setJSON("counter.json", {
65-
counter: this.state.counter + 1
66-
});
67-
console.log("uploading...");
68-
await this.state.bucket.upload();
69-
console.log("upload complete");
70-
this.setState({
71-
waiting: false,
72-
loadingMessage: null,
73-
counter: this.state.counter + 1
74-
});
15+
async onClick() {
16+
this.setState({ message: "click!" });
7517
}
7618

7719
render() {
78-
if (this.state.loadingMessage) {
79-
return <p>{this.state.loadingMessage}</p>;
80-
}
81-
82-
if (!this.state.publicKey) {
83-
return <button onClick={this.login}>Log In</button>;
84-
}
85-
86-
if (!this.state.bucket) {
87-
return <button onClick={this.createBucket}>Create a Counter</button>;
20+
if (this.state.message) {
21+
return <p>{this.state.message}</p>;
8822
}
8923

90-
return (
91-
<div>
92-
<p>Counter: {this.state.counter}</p>
93-
<button onClick={this.increment}>count!</button>
94-
</div>
95-
);
24+
return <button onClick={() => this.onClick()}>Click Me</button>;
9625
}
9726
}

0 commit comments

Comments
 (0)