mirror of
https://github.com/roleypoly/roleypoly-v1.git
synced 2025-06-17 10:39:09 +00:00
chore: prettier on UI
This commit is contained in:
parent
912b40c383
commit
4b75eaa0ab
49 changed files with 1703 additions and 1267 deletions
|
@ -1,87 +1,88 @@
|
|||
import superagent from 'superagent'
|
||||
import { push } from 'react-router-redux'
|
||||
import superagent from 'superagent';
|
||||
import { push } from 'react-router-redux';
|
||||
|
||||
export const fetchServers = async dispatch => {
|
||||
const rsp = await superagent.get('/api/servers')
|
||||
const rsp = await superagent.get('/api/servers');
|
||||
|
||||
dispatch({
|
||||
type: Symbol.for('update servers'),
|
||||
data: rsp.body
|
||||
})
|
||||
data: rsp.body,
|
||||
});
|
||||
|
||||
dispatch({
|
||||
type: Symbol.for('app ready')
|
||||
})
|
||||
}
|
||||
type: Symbol.for('app ready'),
|
||||
});
|
||||
};
|
||||
|
||||
export const userInit = async dispatch => {
|
||||
if (!window.location.pathname.startsWith('/oauth')) {
|
||||
try {
|
||||
const rsp = await superagent.get('/api/auth/user')
|
||||
const rsp = await superagent.get('/api/auth/user');
|
||||
|
||||
dispatch({
|
||||
type: Symbol.for('set user'),
|
||||
data: rsp.body
|
||||
})
|
||||
|
||||
dispatch(fetchServers)
|
||||
data: rsp.body,
|
||||
});
|
||||
|
||||
dispatch(fetchServers);
|
||||
} catch (e) {
|
||||
dispatch({
|
||||
type: Symbol.for('app ready')
|
||||
})
|
||||
type: Symbol.for('app ready'),
|
||||
});
|
||||
// window.location.href = '/oauth/flow'
|
||||
}
|
||||
} else {
|
||||
dispatch({
|
||||
type: Symbol.for('app ready')
|
||||
})
|
||||
type: Symbol.for('app ready'),
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const userLogout = async dispatch => {
|
||||
try {
|
||||
await superagent.post('/api/auth/logout')
|
||||
} catch (e) {
|
||||
}
|
||||
await superagent.post('/api/auth/logout');
|
||||
} catch (e) {}
|
||||
|
||||
dispatch({
|
||||
type: Symbol.for('reset user')
|
||||
})
|
||||
type: Symbol.for('reset user'),
|
||||
});
|
||||
|
||||
window.location.href = '/'
|
||||
}
|
||||
window.location.href = '/';
|
||||
};
|
||||
|
||||
export const startServerPolling = dispatch => {
|
||||
return poll(window.__APP_STORE__.dispatch, window.__APP_STORE__.getState) // let's not cheat... :c
|
||||
}
|
||||
return poll(window.__APP_STORE__.dispatch, window.__APP_STORE__.getState); // let's not cheat... :c
|
||||
};
|
||||
|
||||
const poll = (dispatch, getState) => {
|
||||
const { servers } = getState()
|
||||
let stop = false
|
||||
const stopPolling = () => { stop = true }
|
||||
const { servers } = getState();
|
||||
let stop = false;
|
||||
const stopPolling = () => {
|
||||
stop = true;
|
||||
};
|
||||
const pollFunc = async () => {
|
||||
if (stop) {
|
||||
return
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await fetchServers(dispatch)
|
||||
await fetchServers(dispatch);
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
setTimeout(pollFunc, 5000)
|
||||
console.error(e);
|
||||
setTimeout(pollFunc, 5000);
|
||||
}
|
||||
|
||||
const newServers = getState().servers
|
||||
const newServers = getState().servers;
|
||||
if (servers.size >= newServers.size) {
|
||||
setTimeout(pollFunc, 5000)
|
||||
setTimeout(pollFunc, 5000);
|
||||
} else {
|
||||
const old = servers.keySeq().toSet()
|
||||
const upd = newServers.keySeq().toSet()
|
||||
const newSrv = upd.subtract(old)
|
||||
stopPolling()
|
||||
dispatch(push(`/s/${newSrv.toJS()[0]}/edit`))
|
||||
const old = servers.keySeq().toSet();
|
||||
const upd = newServers.keySeq().toSet();
|
||||
const newSrv = upd.subtract(old);
|
||||
stopPolling();
|
||||
dispatch(push(`/s/${newSrv.toJS()[0]}/edit`));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
pollFunc()
|
||||
return stopPolling
|
||||
}
|
||||
pollFunc();
|
||||
return stopPolling;
|
||||
};
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
export const fadeOut = cb => dispatch => {
|
||||
dispatch({
|
||||
type: Symbol.for('app fade'),
|
||||
data: true
|
||||
})
|
||||
data: true,
|
||||
});
|
||||
|
||||
setTimeout(cb, 300)
|
||||
}
|
||||
setTimeout(cb, 300);
|
||||
};
|
||||
|
||||
export const fadeIn = {
|
||||
type: Symbol.for('app fade'),
|
||||
data: false
|
||||
}
|
||||
data: false,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue