Skip to content

Instantly share code, notes, and snippets.

View SahanAmarsha's full-sized avatar
🏠
Working from home

Sahan Amarsha SahanAmarsha

🏠
Working from home
View GitHub Profile
@SahanAmarsha
SahanAmarsha / getServerSideProps.js
Created February 28, 2021 20:55
getServerSideProps.js
import { getUser } from "../src/graphql/queries";
import {withSSRContext} from "aws-amplify";
export async function getServerSideProps({ req, res }) {
const { Auth, API } = withSSRContext({ req });
try {
const user = await Auth.currentAuthenticatedUser();
const response = await API.graphql({
query: getUser,
variables: { id: user.attributes.sub },
});
@SahanAmarsha
SahanAmarsha / submitHandler.js
Created February 28, 2021 20:50
submitHandler.js
const submitHandler = async (event) => {
event.preventDefault();
const currentUser = await Auth.currentAuthenticatedUser();
try {
const result = await API.graphql({
query: createUser,
variables: {
input: {
id: currentUser.attributes.sub,
firstName: firstName,
@SahanAmarsha
SahanAmarsha / edit-user.js
Created February 28, 2021 20:48
edit-user.js
import React, { useState } from "react";
import { Form } from "react-bootstrap";
import { createUser, updateUser } from "../src/graphql/mutations";
import { API } from "@aws-amplify/api";
import { Auth } from "@aws-amplify/auth";
import Navbar from "../components/Navbar";
const EditUser = () => {
const [firstName, setFirstName] = useState('');
const [secondName, setSecondName] = useState('');
const [description, setDescription] = useState('');
@SahanAmarsha
SahanAmarsha / schema.graphql
Created February 28, 2021 20:38
schema.graphql
type User @model {
id: ID!
firstName: String
lastName: String
description: "String"
image: String
}
@SahanAmarsha
SahanAmarsha / index.js
Created February 28, 2021 20:36
index.js
import React from "react";
import Head from "next/head";
import Navbar from "../components/Navbar";
export default function Home() {
return (
<div className="w-100 h-100 d-flex flex-column justify-content-start">
<Head>
<title>Profile App</title>
<link rel="icon" href="/favicon.ico" />
</Head>
@SahanAmarsha
SahanAmarsha / Navbar.js
Created February 28, 2021 20:34
Navbar.js
import Link from "next/link";
import { Auth } from "aws-amplify";
import React from "react";
const Navbar = () => {
const signOutHandler = () => {};
return (
<nav className="navbar w-100 navbar-expand navbar-dark bg-dark mb-4">
<div className="container">
<a className="navbar-brand" href="#">
Profile App
@SahanAmarsha
SahanAmarsha / _app.js
Created February 28, 2021 20:32
_app.js
import { Amplify } from "aws-amplify";
import { AmplifyAuthenticator } from "@aws-amplify/ui-react";
import awsExports from "../src/aws-exports";
import "../styles/globals.css";
Amplify.configure({ ...awsExports, ssr: true });
function MyApp({ Component, pageProps }) {
return (
<AmplifyAuthenticator>
<Component {...pageProps} />
</AmplifyAuthenticator>
import Link from "next/link";
import React from "react";
const Navbar = () => {
const signOutHandler = () => {};
return (
<nav className="navbar w-100 navbar-expand navbar-dark bg-dark mb-4">
<div className="container">
<a className="navbar-brand" href="#">
Profile App
</a>
@SahanAmarsha
SahanAmarsha / bounce_animation.dart
Created June 10, 2020 17:28
How to use the Bounce Animation
body:
AnimatedBuilder(animation: _slideAnimation,
builder: (ctx, ch) => Container(
width: 100,
height: 100,
margin: EdgeInsets.only(
top: _slideAnimation.value,
left: 125
),
decoration: BoxDecoration(
@SahanAmarsha
SahanAmarsha / bounce_animation_controller.dart
Created June 10, 2020 17:26
Defining the Bounce Animation
AnimationController _controller;
Animation<double> _slideAnimation;
@override
void initState() {
// TODO: implement initState
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 1000),