a mighty battle against an evil opponent
This commit is contained in:
@@ -3,16 +3,45 @@ const preact = require('preact');
|
||||
const { Component } = require('preact')
|
||||
const { connect } = require('preact-redux');
|
||||
|
||||
const SERVER = process.env.NODE_ENV === 'production' ? '/' : 'http://localhost:40000';
|
||||
|
||||
function postData(url = '/', data = {}) {
|
||||
// Default options are marked with *
|
||||
return fetch(url, {
|
||||
method: "POST", // *GET, POST, PUT, DELETE, etc.
|
||||
// mode: "no-cors", // no-cors, cors, *same-origin
|
||||
cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
|
||||
credentials: "include", // include, same-origin, *omit
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'content-type': 'application/json'
|
||||
},
|
||||
redirect: "error", // manual, *follow, error
|
||||
// referrer: "", // no-referrer, *client
|
||||
body: JSON.stringify(data), // body data type must match "Content-Type" header
|
||||
})
|
||||
.then(response => response.json()); // parses response to JSON
|
||||
}
|
||||
|
||||
const addState = connect(
|
||||
(state) => {
|
||||
const { ws, account } = state;
|
||||
null,
|
||||
(dispatch) => {
|
||||
function submitLogin(name, password) {
|
||||
return ws.sendAccountLogin(name, password);
|
||||
postData(`${SERVER}/login`, { name, password })
|
||||
.then(data => console.log(JSON.stringify(data)))
|
||||
.catch(error => console.error(error));
|
||||
}
|
||||
|
||||
function submitRegister(name, password, code) {
|
||||
return ws.sendAccountCreate(name, password, code);
|
||||
postData(`${SERVER}/register`, { name, password, code })
|
||||
.then(data => console.log(JSON.stringify(data)))
|
||||
.catch(error => console.error(error));
|
||||
}
|
||||
|
||||
return {
|
||||
submitLogin,
|
||||
submitRegister,
|
||||
}
|
||||
return { account, submitLogin, submitRegister };
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user