Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update QS with JavaScript example #7457

Merged
merged 57 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4ac2ff0
build UI additions
swaminator Apr 3, 2024
4e61171
Merge branch 'next-release/main' into next-release/dev
swaminator Apr 3, 2024
f4c7613
updates to option 1 qs vite
swaminator Apr 3, 2024
86e845b
updated option 2
swaminator Apr 3, 2024
88c4294
added titles
renebrandel Apr 5, 2024
8aa6344
Merge branch 'next-release/dev' of github.com:aws-amplify/docs into n…
renebrandel Apr 5, 2024
261c640
added language to clarify
renebrandel Apr 5, 2024
011adb5
chore: merging `next-release/main` into `next-release/dev` (#7174)
katiegoines Apr 5, 2024
d19d63c
customize form builder gen 2
swaminator Apr 9, 2024
4674e25
Next main to dev (#7193)
jacoblogan Apr 10, 2024
3358c72
chore: merging `next-release/main` into `next-release/dev` (#7211)
katiegoines Apr 15, 2024
7dab2c3
updated UI docs for forms gen 2
swaminator Apr 17, 2024
7498aa0
Merge branch 'next-release/dev' of https://github.com/aws-amplify/doc…
swaminator Apr 17, 2024
927d6bc
Merge branch 'next-release/main' of https://github.com/aws-amplify/do…
swaminator Apr 17, 2024
19209a9
Merge branch 'next-release/main' into next-release/dev
swaminator Apr 18, 2024
9774158
vite quickstart updated to be the gold standard (draft)
swaminator Apr 19, 2024
30c571f
minor edit
swaminator Apr 19, 2024
34bec92
add feedback to quickstart (#7257)
aspittel Apr 19, 2024
2dda20a
1. Consolidated quickstarts 2. Added react native 3. removed mobile s…
swaminator Apr 22, 2024
6c7bc3d
Updates to formbuilder
dbanksdesign Apr 22, 2024
18d8a89
angular tutorial
swaminator Apr 23, 2024
a6d1a9c
added angular
swaminator Apr 23, 2024
275e723
Merge branch 'next-release/dev' of https://github.com/aws-amplify/doc…
swaminator Apr 23, 2024
1e822bd
reviewed android, ios, flutter
swaminator Apr 24, 2024
4bdeb11
Merge branch 'next-release/main' of https://github.com/aws-amplify/do…
swaminator Apr 24, 2024
7fd51a7
Merge branch 'next-release/main' into next-release/dev
swaminator Apr 24, 2024
6b12283
android QS
swaminator Apr 24, 2024
36c650e
updated next.js tutorials
swaminator Apr 25, 2024
df9adfb
Next.js tweaks
swaminator Apr 25, 2024
49875a8
updated aws account setup to use IdC by default
swaminator Apr 25, 2024
52711b4
tweaks to idc setup
swaminator Apr 25, 2024
5e11069
changed the title
swaminator Apr 25, 2024
6d39a68
fixed merge issue with customize ui
swaminator Apr 25, 2024
e9dedaa
form lifecyle merges
swaminator Apr 25, 2024
6eff5aa
Fixed typos
renebrandel Apr 25, 2024
31b42da
gen1 v gen2
swaminator Apr 25, 2024
01d25c1
Merge branch 'next-release/dev' of https://github.com/aws-amplify/doc…
swaminator Apr 25, 2024
ef91281
functions title fix
swaminator Apr 25, 2024
64dd08a
functions title fix
swaminator Apr 25, 2024
4e173cc
change next title
swaminator Apr 25, 2024
02403c9
Updating formbuilder special inputs page
dbanksdesign Apr 25, 2024
33b02f7
Merge branch 'next-release/main' into next-release/dev
reesscot Apr 26, 2024
ba1ab3b
Update cspell.json
reesscot Apr 26, 2024
db21ce6
Update src/pages/[platform]/build-ui/formbuilder/customize/index.mdx
swaminator Apr 26, 2024
12cd31e
Update src/pages/[platform]/build-ui/formbuilder/special-inputs/index…
swaminator Apr 26, 2024
7b7e1aa
Merge branch 'next-release/main' of https://github.com/aws-amplify/do…
swaminator Apr 30, 2024
26ab4ea
Merge branch 'next-release/main' into next-release/dev
swaminator Apr 30, 2024
c9549f0
Merge branch 'next-release/dev' of https://github.com/aws-amplify/doc…
swaminator Apr 30, 2024
efdf5ce
gen1 gen2 updates
swaminator May 1, 2024
7df8958
renamed folder to match console link
swaminator May 2, 2024
122214a
Merge branch 'next-release/main' of https://github.com/aws-amplify/do…
swaminator May 2, 2024
5527257
Merge branch 'next-release/main' into next-release/dev
swaminator May 2, 2024
69fc93b
fixed merge conflict bug
swaminator May 2, 2024
2d4b74f
added JS quickstart, fixed TK images
swaminator May 2, 2024
ee33228
Update src/pages/[platform]/start/quickstart/index.mdx
swaminator May 2, 2024
ee74669
Update src/pages/[platform]/start/quickstart/index.mdx
aspittel May 2, 2024
5b6db02
Update src/pages/[platform]/start/quickstart/index.mdx
aspittel May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/directory/directory.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const directory = {
path: 'src/pages/[platform]/start/manual-installation/index.mdx'
},
{
path: 'src/pages/[platform]/start/gen1-gen2/index.mdx'
path: 'src/pages/[platform]/start/migrate-to-gen2/index.mdx'
}
]
},
Expand Down
264 changes: 248 additions & 16 deletions src/pages/[platform]/start/quickstart/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,246 @@ export function getStaticProps(context) {
};
}

<InlineFilter filters={["javascript"]}>

👋 Welcome to AWS Amplify! In this quickstart guide, you will:

1. Deploy a Vanilla JavaScript app with Vite
2. Build and connect to a database with real-time data updates
3. Configure authentication and authorization rules


## Create project

Create a new Vanilla JavaScript app with vite using the following commands, create the directory (`amplify-js-app`) and files for the app.

```bash
npm create vite@latest
✔ Project name: amplify-js-app
✔ Select a framework: › Vanilla
✔ Select a variant: › TypeScript
```

Initialize npm and install dependencies and dev dependencies.
```bash
cd amplify-js-app
npm install
npm run dev
```

This runs a development server and allows you to see the output generated by the build. You can see the running app by navigating to [http://localhost:5173](http://localhost:5173).

Add the following to the `index.html` file:

```html title="index.html"
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Todo App</title>
</head>
<body>
<main>
<h1>My todos</h1>
<button id="addTodo">+ new</button>
<ul id="todoList"></ul>
<div>
Try creating a new todo.
<br>
<a href="https://docs.amplify.aws/javascript/start/quickstart/">
Review next step of this tutorial.
</a>
</div>
</main>
<script type="module" src="src/main.ts"></script>
</body>
</html>
```

Add the following to `style.css` file:

{/* cSpell:disable */}

```css title="style.css"
body {
margin: 0;
background: linear-gradient(180deg, rgb(117, 81, 194), rgb(255, 255, 255));
display: flex;
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
height: 100vh;
width: 100vw;
justify-content: center;
align-items: center;
}

main {
display: flex;
flex-direction: column;
align-items: stretch;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
color: white;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

ul {
padding-inline-start: 0;
margin-block-start: 0;
margin-block-end: 0;
list-style-type: none;
display: flex;
flex-direction: column;
margin: 8px 0;
border: 1px solid black;
gap: 1px;
background-color: black;
border-radius: 8px;
overflow: auto;
}

li {
background-color: white;
padding: 8px;
}

li:hover {
background: #dadbf9;
}

a {
font-weight: 800;
text-decoration: none;
}
```
{/* cSpell:enable */}

In `main.js` remove the boilerplate code and leave it empty. Then refresh the browser to see the changes.

## Create Backend

The easiest way to get started with AWS Amplify is through npm with `create-amplify` command. You can run it from your base project directory.

```bash title="Terminal" showLineNumbers={false}
npm create amplify@latest
? Where should we create your project? (.) # press enter
```

Running this command will scaffold Amplify backend files in your current project with the following files added:

```text
├── amplify/
│ ├── auth/
│ │ └── resource.ts
│ ├── data/
│ │ └── resource.ts
│ ├── backend.ts
│ └── package.json
├── node_modules/
├── index.html
├── style.css
├── .gitignore
├── package-lock.json
├── package.json
└── tsconfig.json
```

### Set up local AWS credentials

To make backend updates, we are going to require AWS credentials to deploy backend updates from our local machine.

**Skip ahead to step 8**, if you already have an AWS profile with credentials on your local machine, and your AWS profile has the `AmplifyBackendDeployFullAccess` permission policy.

Otherwise, **[set up local AWS credentials](/[platform]/start/account-setup/)** that grant Amplify permissions to deploy backend updates from your local machine.

### Deploy cloud sandbox

To deploy your backend use Amplify's per-developer cloud sandbox. This feature provides a separate backend environment for every developer on a team, ideal for local development and testing. To run your application with a sandbox environment, you can run the following command:

```bash title="Terminal" showLineNumbers={false}
npx ampx sandbox
```

Once the sandbox environment is deployed, it will create a GraphQL API, database, and auth service. All the deployed resources will be available in the `amplify_outputs.json`. However, Xcode won't be able to recognize them. For recognizing the files, you need to drag and drop the generated files to your project.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there a mention of Xcode in this paragraph?


## Connect frontend to backend

The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource.ts` file. The default example will create a Todo model with `content` field. Update your main.js file to create new to-do items.

```typescript title="src/main.ts"
import { generateClient } from "aws-amplify/data";
import type { Schema } from "../amplify/data/resource";
import './style.css';
import { Amplify } from 'aws-amplify';
import outputs from '../amplify_outputs.json';

Amplify.configure(outputs);


const client = generateClient<Schema>();

document.addEventListener("DOMContentLoaded", function () {
const todos: Array<Schema["Todo"]["type"]> = [];
const todoList = document.getElementById("todoList") as HTMLUListElement;
const addTodoButton = document.getElementById("addTodo") as HTMLButtonElement;

addTodoButton.addEventListener("click", createTodo);

function updateUI() {
todoList.innerHTML = '';
todos.forEach(todo => {
const li = document.createElement('li');
li.textContent = todo.content ?? '';
todoList.appendChild(li);
});
}

function createTodo() {
console.log('createTodo');
const content = window.prompt("Todo content");
if (content) {
client.models.Todo.create({ content }).then(response => {
if (response.data && !response.errors) {
todos.push(response.data);
updateUI();
} else {
console.error('Error creating todo:', response.errors);
alert('Failed to create todo.');
}
}).catch(error => {
console.error('Network or other error:', error);
alert('Failed to create todo due to a network or other error.');
});
}
}


client.models.Todo.observeQuery().subscribe({
next: (data) => {
todos.splice(0, todos.length, ...data.items);
updateUI();
}
});
});
```

</InlineFilter>

<InlineFilter filters={["react"]}>

Expand Down Expand Up @@ -112,7 +352,7 @@ Let's take a tour of the project structure in this starter repository by opening

In the Amplify Console, navigate to the Data manager to see the data entered in your database.

TK IMAGE
![data-manager](/images/gen2/getting-started/data-manager.png)
aspittel marked this conversation as resolved.
Show resolved Hide resolved

## Make frontend updates

Expand Down Expand Up @@ -449,7 +689,7 @@ Let's take a tour of the project structure in this starter repository by opening

In the Amplify Console, navigate to the Data manager to see the data entered in your database.

TK IMAGE
![Amplify data manager user interface showing the ToDo model with two to do instances](/images/gen2/getting-started/data-manager.png)

## Make frontend updates

Expand Down Expand Up @@ -782,7 +1022,7 @@ Let's take a tour of the project structure in this starter repository by opening

In the Amplify Console, navigate to the Data manager to see the data entered in your database.

TK IMAGE
![data-manager](/images/gen2/getting-started/data-manager.png)
aspittel marked this conversation as resolved.
Show resolved Hide resolved

## Make frontend updates

Expand Down Expand Up @@ -1074,7 +1314,7 @@ flutter create my_amplify_app
The easiest way to get started with AWS Amplify is through npm with `create-amplify` command. You can run it from your base project directory.

```bash title="Terminal" showLineNumbers={false}
npm create amplify@beta
npm create amplify@latest
? Where should we create your project? (.) # press enter
```

Expand Down Expand Up @@ -1616,7 +1856,7 @@ Run your application in your local environment again. You should be presented wi

## Adding Data

The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource`.ts file. The default example will create a Todo model with `content` field.
The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource.ts` file. The default example will create a Todo model with `content` field.

Let's modify this to add the following:
- A boolean `isDone` field.
Expand Down Expand Up @@ -2058,7 +2298,7 @@ Now if you run the application on the Android emulator, you should see the authe

### 6. Read and write data

The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource`.ts file. The default example will create a Todo model with `content` field.
The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource.ts` file. The default example will create a Todo model with `content` field.

Amplify can automatically generate code for interacting with the backend API. The command below generates model classes from the Data schema:

Expand Down Expand Up @@ -2460,7 +2700,7 @@ Run your application in your local environment again. You should be presented wi

## Adding Data

The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource`.ts file. The default example will create a Todo model with `content` field.
The initial scaffolding already has a pre-configured data backend defined in the `amplify/data/resource.ts` file. The default example will create a Todo model with `content` field.

Let's modify this to add the following:
- A boolean `isDone` field.
Expand Down Expand Up @@ -2642,15 +2882,7 @@ For publishing the changes to cloud, you need to create a remote git repository.

</InlineFilter>

<InlineFilter filters={['react-native']
['android'],
['angular'],
['flutter'],
['javascript'],
['react'],
['react-native'],
['swift'],
['vue']}>
<InlineFilter filters={["javascript", "react-native", "angular", "nextjs", "react", "vue", "android", "swift", "flutter"]}>

## 🥳 Success

Expand Down
Loading