How to use @aws-amplify/api - 10 common examples

To help you get started, we’ve selected a few @aws-amplify/api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TreeHacks / root / src / Judge / Judge.tsx View on Github external
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);
		});
	}
github yhenni1989 / Zopher / App.js View on Github external
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)
    }
  }
github yhenni1989 / Zopher / src / components / Posts.js View on Github external
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)
    }
  }
github TreeHacks / root / src / index.tsx View on Github external
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'
    }
};
github TreeHacks / root / src / store / admin / actions.ts View on Github external
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);
  });
}
github TreeHacks / root / src / Review / Review.tsx View on Github external
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);
		})
	}
}
github TreeHacks / root / src / Judge / Judge.tsx View on Github external
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);
		})
	}
}
github TreeHacks / root / src / Review / Review.tsx View on Github external
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) {
github TreeHacks / root / src / Review / Review.tsx View on Github external
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) {
github TreeHacks / root / src / Admin / JudgeLeaderboard.tsx View on Github external
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() {