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

Nuxt tutorial #240

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 11 additions & 0 deletions src/routes/docs/tutorials/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/nuxt" class="aw-card is-normal">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="aw-icon-nuxt aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Nuxt</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with Nuxt.
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/sveltekit" class="aw-card is-normal">
<header class="u-flex u-cross-baseline u-gap-4">
Expand Down
10 changes: 10 additions & 0 deletions src/routes/docs/tutorials/nuxt/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script lang="ts">
import { globToTutorial } from '$lib/utils/tutorials.js';
import { setContext } from 'svelte';

export let data;
const tutorials = globToTutorial(data);
setContext('tutorials', tutorials);
</script>

<slot />
11 changes: 11 additions & 0 deletions src/routes/docs/tutorials/nuxt/+layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { LayoutLoad } from './$types';

export const load: LayoutLoad = ({ url }) => {
const tutorials = import.meta.glob('./**/*.markdoc', {
eager: true
});
return {
tutorials,
pathname: url.pathname
};
};
6 changes: 6 additions & 0 deletions src/routes/docs/tutorials/nuxt/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { redirect } from '@sveltejs/kit';
import type { PageLoad } from './$types';

export const load: PageLoad = async () => {
throw redirect(303, '/docs/tutorials/nuxt/step-1');
};
33 changes: 33 additions & 0 deletions src/routes/docs/tutorials/nuxt/step-1/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
layout: tutorial
title: Build an ideas tracker with Nuxt
description: Learn to build an idea tracker app with Appwrite and Nuxt with authentication, databases and collections, queries, pagination, and file storage.
step: 1
back: /docs
---

**Idea tracker**: an app to track all the side project ideas that you'll start, but probably never finish.
In this tutorial, you will build Idea tracker with Appwrite and Nuxt.

{% only_dark %}
![Create project screen](/images/docs/tutorials/dark/idea-tracker.png)
{% /only_dark %}
{% only_light %}
![Create project screen](/images/docs/tutorials/idea-tracker.png)
{% /only_light %}

# Concepts {% #concepts %}

This tutorial will introduce the following concepts:

1. Setting up your first project
2. Authentication
3. Navigation
4. Databases and collections
5. Queries


# Prerequisites {% #prerequisites %}

1. Basic knowledge of JavaScript.
2. Have [Node.js](https://nodejs.org/en) and [NPM](https://www.npmjs.com/) installed on your computer.
107 changes: 107 additions & 0 deletions src/routes/docs/tutorials/nuxt/step-2/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
layout: tutorial
title: Build an ideas tracker with Nuxt
description: Learn to build an idea tracker app with Appwrite and Nuxt
step: 2
---

# Create Nuxt project {% #create-nuxt-project %}

Create a Nuxt app with the `npx init` command.


```sh
npx nuxi@latest init ideas-tracker
```

# Add dependencies {% #add-dependencies %}

Install the JavaScript Appwrite SDK.

```sh
npm install appwrite
```

You can start the development server to watch your app update in the browser as you make changes.

```sh
npm run dev
```

# Pages and layouts for routing {% #pages-and-layout-for-routing %}

In Nuxt, directories help organize the codebase and minimize boilerplate. The purpose is
making it easy to find and manage different aspect of your application.

The files added to the `pages` directory will automatically become a route. Nuxt will look for a layout (can be more than one) to accompany a page
in the `layouts` directory. When these files have been created we can edit the `app.vue` file to render our pages. Now we will have a working app to verify our changes in the development server throughout the tutorial.
As an additional step, by adding [Appwrite's Pink Design system]('https://pink.appwrite.io/') we will also have a global layout system to help with the layout.


### 1. Add a page

Create file `src/pages/index.vue` and add the following code:

```vue
<template>
<div>
<h1>Hello, idea tracker!</h1>
</div>
</template>
```


### 2. Add a default layout

a file `src/layouts/default.vue` and insert the following code:

```vue
<template>
<div>
<slot />
</div>
</template>

<script>
export default {
layout: "default",
};
</script>
```

### 3. Edit app

Go to `app.vue`, remove `NuxtWelcome`and insert `NuxtPage` wrapped in `NuxtLayout`

```vue
<template>
<div>
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
</div>
</template>
```


### 4. Import layout

Edit `nuxt.config.ts`to import Appwrite's design system to all pages and components.
The classes will be ready to use in the templates through auto-import.

```ts
export default defineNuxtConfig({
app: {
head: {
link: [
{ rel: "stylesheet", href: "https://unpkg.com/@appwrite.io/pink" },
{
rel: "stylesheet",
href: "https://unpkg.com/@appwrite.io/pink-icons",
},
],
},
},
devtools: { enabled: true },
});
```
57 changes: 57 additions & 0 deletions src/routes/docs/tutorials/nuxt/step-3/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
layout: tutorial
title: Set up Appwrite
description: Import and configure a project with Appwrite Cloud.
step: 3
---

# Create project {% #create-project %}

Head to the [Appwrite Console](https://cloud.appwrite.io/console).

{% only_dark %}
![Create project screen](/images/docs/quick-starts/dark/create-project.png)
{% /only_dark %}
{% only_light %}
![Create project screen](/images/docs/quick-starts/create-project.png)
{% /only_light %}

If this is your first time using Appwrite, create an account and create your first project.

Then, under **Add a platform**, add a **Web app**. The **Hostname** should be localhost.

{% only_dark %}
![Add a platform](/images/docs/quick-starts/dark/add-platform.png)
{% /only_dark %}
{% only_light %}
![Add a platform](/images/docs/quick-starts/add-platform.png)
{% /only_light %}

You can skip optional steps.

# Initialize Appwrite SDK {% #init-sdk %}

To use Appwrite in our Nuxt app, we'll need to find our project ID. It is located in the **Settings** page.

{% only_dark %}
![Project settings screen](/images/docs/quick-starts/dark/project-id.png)
{% /only_dark %}
{% only_light %}
![Project settings screen](/images/docs/quick-starts/project-id.png)
{% /only_light %}

Create a new file `src/appwrite.js` for the Appwrite related code.
Only one instance of the `Client()` class should be created per app.
Add the following code to it, replacing `<YOUR_PROJECT_ID>` with your project ID.

```js
import { Client, Databases, Account } from "appwrite";

const client = new Client();
client
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject("<YOUR_PROJECT_ID>"); // Replace with your project ID

export const account = new Account(client);
export const database = new Databases(client);
```
Loading