Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
nextApplication(id?: string) {
Promise.all([
API.get("treehacks", '/judging/next_hack', { queryStringParameters: id ? { hack_id: id } : {} }),
// API.get("treehacks", '/judging/stats', {})
]).then(([hack_data]) => {
window.scrollTo(0, 0);
this.setState({ hack_data, reviewFormData: null });
}).catch((err) => {
alert("Error, " + err);
console.log(err);
});
}
countPosts = async () => {
try {
const graphqldata = await API.graphql(graphqlOperation(listPosts))
this.setState({
posts: graphqldata.data.listPosts.items, postContent: ''
})
// console.log(this.state.posts.length)
}
catch (err) {
console.log('error: ', err)
}
}
deletePost = async (post) => {
const postId = await post['id']
try {
await API.graphql(graphqlOperation(deletePost, { id: postId }))
await this.componentDidMount()
// console.log('Post successfully deleted.')
} catch (err) {
console.log('Error deleting post.', err)
}
}
try {
return { Authorization: (await Auth.currentSession()).getIdToken().getJwtToken() }
}
catch (e) {
console.warn(e, "Defaulting to stored JWT in localStorage...");
// Get JWT from SAML.
return { Authorization: await asyncLocalStorage.getItem("jwt") }
}
}
Auth.configure({
region: 'us-east-1',
userPoolId: COGNITO_USER_POOL_ID,
userPoolWebClientId: COGNITO_CLIENT_ID,
mandatorySignIn: false
});
API.configure({
endpoints: [
{
name: "treehacks",
endpoint: ENDPOINT_URL,
custom_header: custom_header
}
]
});
const authScreenLabels = {
en: {
'Sign Up': 'Create new account',
'Sign Up Account': 'New member? Create a new account',
'Sign In Account': 'Sign In'
}
};
export const editRow = (endpoint, rowId, data) => (dispatch, getState) => {
dispatch(loadingStart());
return API.patch("treehacks", `/${endpoint}/${rowId}`, {
body: data
}).then(e => {
const adminState = (getState().admin as IAdminState);
const applicationList = adminState.applicationList;
let application = find(applicationList, { "_id": rowId });
for (let key in data) {
set(application, key, data[key]);
}
dispatch(setApplicationList(applicationList, adminState.pages)); // So that the table refreshes
dispatch(loadingEnd());
}).catch(e => {
console.error(e);
dispatch(loadingEnd());
alert("Error performing edit row " + e);
});
}
handleSubmit() {
API.post("treehacks", '/review/rate', {
body: {
"application_id": this.state.application_data.user.id,
...this.state.reviewFormData
}
}).then((data) => {
if (data.results.status === "success") {
this.nextApplication();
}
}).catch(err => {
alert("Error, " + err);
console.error(err);
})
}
}
handleSubmit() {
API.post("treehacks", '/judging/rate', {
body: {
"hack_id": this.state.hack_data._id,
...this.state.reviewFormData
}
}).then((data) => {
if (data.results.status === "success") {
this.nextApplication();
}
}).catch(err => {
alert("Error, " + err);
console.error(err);
})
}
}
nextApplication() {
Promise.all([
API.get("treehacks", '/review/leaderboard', {}),
API.get("treehacks", '/review/next_application', {}),
API.get("treehacks", '/review/stats', {})
]).then(([leaderboard_data, application_data, stats_data]) => {
window.scrollTo(0, 0);
this.setState({ leaderboard_data, application_data, stats_data, reviewFormData: null });
}).catch((err) => {
alert("Error, " + err);
console.log(err);
});
}
getSortedLeaderboardByRecent(leaderboard) {
nextApplication() {
Promise.all([
API.get("treehacks", '/review/leaderboard', {}),
API.get("treehacks", '/review/next_application', {}),
API.get("treehacks", '/review/stats', {})
]).then(([leaderboard_data, application_data, stats_data]) => {
window.scrollTo(0, 0);
this.setState({ leaderboard_data, application_data, stats_data, reviewFormData: null });
}).catch((err) => {
alert("Error, " + err);
console.log(err);
});
}
getSortedLeaderboardByRecent(leaderboard) {
async loadData() {
this.setState({ refreshing: true });
Promise.all([
API.get("treehacks", '/judging/leaderboard', {}),
API.get("treehacks", '/judging/stats', {})
]).then(([leaderboard_data, stats_data]) => {
window.scrollTo(0, 0);
this.setState({ leaderboard_data, stats_data, refreshing: false });
}).catch((err) => {
alert("Error, " + err);
this.setState({ refreshing: false });
console.log(err);
});
}
render() {