nginx acp stuff
This commit is contained in:
+25
-14
@@ -14,10 +14,13 @@ const addState = connect(
|
||||
const {
|
||||
account,
|
||||
user,
|
||||
msg,
|
||||
} = state;
|
||||
|
||||
return {
|
||||
account, user,
|
||||
account,
|
||||
user,
|
||||
msg,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -30,8 +33,13 @@ const addState = connect(
|
||||
dispatch(actions.setGames(list));
|
||||
}
|
||||
|
||||
function setMsg(msg) {
|
||||
dispatch(actions.setMsg(msg));
|
||||
}
|
||||
|
||||
return {
|
||||
setUser,
|
||||
setMsg,
|
||||
setGames,
|
||||
};
|
||||
}
|
||||
@@ -43,12 +51,8 @@ class AcpMain extends Component {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
account: {},
|
||||
name: null,
|
||||
id: null,
|
||||
msg: '',
|
||||
user: null,
|
||||
games: [],
|
||||
name: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -56,31 +60,38 @@ class AcpMain extends Component {
|
||||
const {
|
||||
setGames,
|
||||
setUser,
|
||||
setMsg,
|
||||
|
||||
msg,
|
||||
} = args;
|
||||
|
||||
const {
|
||||
msg,
|
||||
name,
|
||||
id,
|
||||
} = state;
|
||||
|
||||
const reset = () => {
|
||||
setMsg(null);
|
||||
this.setState({ id: null, name: null });
|
||||
};
|
||||
|
||||
const getUser = () => {
|
||||
this.setState({ msg: null });
|
||||
reset();
|
||||
postData('/acp/user', { id, name })
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.error) return this.setState({ msg: data.error });
|
||||
if (data.error) return setMsg(data.error);
|
||||
setUser(data);
|
||||
})
|
||||
.catch(error => errorToast(error));
|
||||
};
|
||||
|
||||
const gameList = () => {
|
||||
this.setState({ msg: null });
|
||||
reset();
|
||||
postData('/acp/game/list', { number: 20 })
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.error) return this.setState({ msg: data.error });
|
||||
if (data.error) return setMsg(data.error);
|
||||
console.log(data);
|
||||
setGames(data.data);
|
||||
})
|
||||
@@ -88,11 +99,11 @@ class AcpMain extends Component {
|
||||
};
|
||||
|
||||
const gameOpen = () => {
|
||||
this.setState({ msg: null });
|
||||
reset();
|
||||
postData('/acp/game/open')
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.error) return this.setState({ msg: data.error });
|
||||
if (data.error) return setMsg(data.error);
|
||||
console.log(data);
|
||||
setGames(data);
|
||||
})
|
||||
@@ -102,7 +113,7 @@ class AcpMain extends Component {
|
||||
return (
|
||||
<main class='menu'>
|
||||
<div class="top">
|
||||
<div>{msg}</div>
|
||||
<div class="msg">{msg}</div>
|
||||
<AcpUser />
|
||||
<AcpGameList />
|
||||
</div>
|
||||
|
||||
+61
-8
@@ -3,8 +3,7 @@ const { Component } = require('preact');
|
||||
const { connect } = require('preact-redux');
|
||||
const linkState = require('linkstate').default;
|
||||
|
||||
const axios = require('axios');
|
||||
|
||||
const { postData, errorToast } = require('./../../client/src/utils');
|
||||
const actions = require('./actions');
|
||||
|
||||
const addState = connect(
|
||||
@@ -14,22 +13,58 @@ const addState = connect(
|
||||
} = state;
|
||||
|
||||
return {
|
||||
user
|
||||
user,
|
||||
};
|
||||
},
|
||||
function receiveDispatch(dispatch) {
|
||||
function setUser(user) {
|
||||
dispatch(actions.setUser(user));
|
||||
}
|
||||
|
||||
function setMsg(msg) {
|
||||
dispatch(actions.setMsg(msg));
|
||||
}
|
||||
|
||||
return {
|
||||
setUser,
|
||||
setMsg,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
function AcpGameList(args) {
|
||||
function AcpUser(args) {
|
||||
const {
|
||||
user,
|
||||
setUser,
|
||||
setMsg,
|
||||
} = args;
|
||||
|
||||
const {
|
||||
credits,
|
||||
} = this.state;
|
||||
|
||||
if (!user) return false;
|
||||
|
||||
const reset = () => {
|
||||
setMsg(null);
|
||||
this.setState({ credits: null });
|
||||
};
|
||||
|
||||
const addCredits = () => {
|
||||
reset();
|
||||
postData('/acp/user/credits', { id: user.id, credits })
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.error) return setMsg(data.error);
|
||||
return setUser(data);
|
||||
})
|
||||
.catch(error => setMsg(error));
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>{user.name}</h1>
|
||||
<div class="user">
|
||||
<dl>
|
||||
<h1>{user.name}</h1>
|
||||
<dt>Id</dt>
|
||||
<dd>{user.id}</dd>
|
||||
<dt>Credits</dt>
|
||||
@@ -37,8 +72,26 @@ function AcpGameList(args) {
|
||||
<dt>Subscribed</dt>
|
||||
<dd>{user.subscribed.toString()}</dd>
|
||||
</dl>
|
||||
<div>
|
||||
<label for="current">Add Credits:</label>
|
||||
<input
|
||||
class="login-input"
|
||||
type="number"
|
||||
name="credits"
|
||||
value={credits}
|
||||
onInput={linkState(this, 'credits')}
|
||||
placeholder="credits"
|
||||
/>
|
||||
<button
|
||||
onClick={addCredits}>
|
||||
Add Credits
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<h2>Constructs</h2>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = addState(AcpGameList);
|
||||
module.exports = addState(AcpUser);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
export const setAccount = value => ({ type: 'SET_ACCOUNT', value });
|
||||
export const setUser = value => ({ type: 'SET_USER', value });
|
||||
export const setMsg = value => ({ type: 'SET_MSG', value });
|
||||
export const setGames = value => ({ type: 'SET_GAMES', value });
|
||||
|
||||
@@ -13,5 +13,6 @@ function createReducer(defaultState, actionType) {
|
||||
module.exports = {
|
||||
account: createReducer(null, 'SET_ACCOUNT'),
|
||||
user: createReducer(null, 'SET_USER'),
|
||||
msg: createReducer(null, 'SET_MSG'),
|
||||
games: createReducer([], 'SET_GAMES'),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user