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

📚 Documentation: Tutorial for TypeScript #269

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
216 changes: 116 additions & 100 deletions src/routes/docs/tutorials/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,109 +1,125 @@
<script lang="ts">
import { MainFooter } from '$lib/components';
import { DEFAULT_DESCRIPTION, DEFAULT_HOST } from '$lib/utils/metadata';
import { themeInUse } from '$routes/+layout.svelte';
import { DOCS_TITLE_SUFFIX } from '$routes/titles';
import { MainFooter } from '$lib/components';
import { DEFAULT_DESCRIPTION, DEFAULT_HOST } from '$lib/utils/metadata';
import { DOCS_TITLE_SUFFIX } from '$routes/titles';
Copy link
Contributor

Choose a reason for hiding this comment

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

Why were these changed?


const title = 'Tutorials' + DOCS_TITLE_SUFFIX;
const description = DEFAULT_DESCRIPTION;
const ogImage = DEFAULT_HOST + '/images/open-graph/docs.png';
const title = 'Tutorials' + DOCS_TITLE_SUFFIX;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove all the white space changes?

const description = DEFAULT_DESCRIPTION;
const ogImage = DEFAULT_HOST + '/images/open-graph/docs.png';
</script>

<svelte:head>
<!-- Titles -->
<title>{title}</title>
<meta property="og:title" content={title} />
<meta name="twitter:title" content={title} />
<!-- Desscription -->
<meta name="description" content={description} />
<meta property="og:description" content={description} />
<meta name="twitter:description" content={description} />
<!-- Image -->
<meta property="og:image" content={ogImage} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:image" content={ogImage} />
<meta name="twitter:card" content="summary_large_image" />
<!-- Titles -->
<title>{title}</title>
<meta property="og:title" content={title} />
<meta name="twitter:title" content={title} />
<!-- Desscription -->
<meta name="description" content={description} />
<meta property="og:description" content={description} />
<meta name="twitter:description" content={description} />
<!-- Image -->
<meta property="og:image" content={ogImage} />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:image" content={ogImage} />
<meta name="twitter:card" content="summary_large_image" />
</svelte:head>

<main class="aw-main-section">
<article class="aw-article">
<header class="aw-article-header">
<div class="aw-article-header-start u-flex-vertical aw-u-cross-start">
<div class="u-position-relative u-flex u-cross-center">
<h1 class="aw-title">Platforms</h1>
</div>
</div>
<div class="aw-article-header-end" />
</header>
<div class="aw-article-content aw-u-gap-80">
<section class="u-flex-vertical u-gap-24">
<h2 class="aw-eyebrow">Client</h2>
<ul class="aw-grid-row-4 aw-grid-row-4-mobile-2">
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/react" class="aw-card is-normal">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-react aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">React</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with React.
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/vue" class="aw-card is-normal">
<header class="u-flex u-cross-center u-gap-4">
<img src="/images/platforms/{$themeInUse}/vue.svg" alt="" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Vue</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with Vue.
</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">
<span class="icon-svelte aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">SvelteKit</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with SvelteKit.
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<article class="aw-card is-full-color">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-flutter aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Flutter</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">Coming soon...</p>
</article>
</li>
<li class="is-mobile-col-span-2">
<article class="aw-card is-full-color">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-apple aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Apple</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">Coming soon...</p>
</article>
</li>
<li class="is-mobile-col-span-2">
<article class="aw-card is-full-color">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-android aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Android</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">Coming soon...</p>
</article>
</li>
</ul>
</section>
</div>
</article>
<article class="aw-article">
<header class="aw-article-header">
<div class="aw-article-header-start u-flex-vertical aw-u-cross-start">
<div class="u-position-relative u-flex u-cross-center">
<h1 class="aw-title">Platforms</h1>
</div>
</div>
<div class="aw-article-header-end" />
</header>
<div class="aw-article-content aw-u-gap-80">
<section class="u-flex-vertical u-gap-24">
<h2 class="aw-eyebrow">Client</h2>
<ul class="aw-grid-row-4 aw-grid-row-4-mobile-2">
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/react" class="aw-card is-normal">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-react aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">React</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with React.
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/typescript" class="aw-card is-normal">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-typescript aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">TypeScript</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with TypeScript.
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<a href="/docs/tutorials/vue" class="aw-card is-normal">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="aw-icon-vue aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Vue</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with Vue.
</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">
<span class="icon-svelte aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">SvelteKit</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Learn Appwrite Auth, Databases, and more with SvelteKit.
</p>
</a>
</li>
<li class="is-mobile-col-span-2">
<article class="aw-card is-full-color">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-flutter aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Flutter</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Coming soon...
</p>
</article>
</li>
<li class="is-mobile-col-span-2">
<article class="aw-card is-full-color">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-apple aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Apple</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Coming soon...
</p>
</article>
</li>
<li class="is-mobile-col-span-2">
<article class="aw-card is-full-color">
<header class="u-flex u-cross-baseline u-gap-4">
<span class="icon-android aw-u-font-size-24" aria-hidden="true" />
<h4 class="aw-sub-body-500 aw-u-color-text-primary">Android</h4>
</header>
<p class="aw-sub-body-400 u-margin-block-start-4">
Coming soon...
</p>
</article>
</li>
</ul>
</section>
</div>
</article>

<MainFooter variant="docs" />
</main>
<MainFooter variant="docs" />
</main>
10 changes: 10 additions & 0 deletions src/routes/docs/tutorials/typescript/+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/typescript/+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/typescript/+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/typescript/step-1');
};
34 changes: 34 additions & 0 deletions src/routes/docs/tutorials/typescript/step-1/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
layout: tutorial
title: Build an ideas tracker with TypeScript
description: Learn to build a TypeScript app with no backend code using an Appwrite backend.
step: 1
difficulty: beginner
readtime: 10
---

**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 TypeScript with React.

{% 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. Databases and collections
4. Queries and pagination
5. Storage


# Prerequisites {% #prerequisites %}

1. Basic knowledge of TypeScript and React.
2. Have [Node.js](https://nodejs.org/en) and [NPM](https://www.npmjs.com/) installed on your computer
32 changes: 32 additions & 0 deletions src/routes/docs/tutorials/typescript/step-2/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: tutorial
title: Create app
description: Create a React app project and integrate with Appwrite.
step: 2
---

# Create React project {% #create-react-project %}

Create a React app with the `npm create` command.

```sh
npm create vite@latest ideas-tracker && cd ideas-tracker
```

Select React and then TypeScript from CLI.

![Create project screen](/images/docs/tutorials/react-typescript.png)

# Add dependencies {% #add-dependencies %}

Install the TypeScript 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 -- --open --port 3000
```
58 changes: 58 additions & 0 deletions src/routes/docs/tutorials/typescript/step-3/+page.markdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
layout: tutorial
title: Set up Appwrite
description: Import and initialize Appwrite for your react application.
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 Svelte app, we'll need to find our project ID. Find your project's ID 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/lib/appwrite.ts` to hold our 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.

```ts
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: Account = new Account(client);
export const databases: Databases = new Databases(client);

```
Loading