Skip to content

Commit 91125af

Browse files
committed
Required changes to step 5-7
1 parent 70e8783 commit 91125af

3 files changed

Lines changed: 204 additions & 116 deletions

File tree

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,58 @@
11
---
22
layout: tutorial
33
title: Add navigation
4-
description: Add navigation to your Nuxt applicating.
4+
description: Add navigation to your app.
55
step: 5
66
---
77

8-
In our app we want to show a navigation bar. We will add it to the `app.vue` component and use the `useUserSession` composable to show either:
9-
- a logout button if the user is logged in
10-
- or a login button if the user is not logged in
11-
12-
Update the `app.vue` file:
8+
To help our users navigate the app we want it to have a navigation bar that's visible on all pages.
9+
We will use the `useUserSession` composable to show a login button when no user is logged in and a logout button when logged in.
10+
Open the `app.vue` file and add the navbar in the `template`, just above the `<NuxtPage />` tag.
1311

1412
```vue
15-
template>
16-
<div>
17-
<NuxtLayout>
18-
<nav class="main-header u-padding-inline-end-0">
19-
<h3 class="u-stretch eyebrow-heading-1">Idea Tracker</h3>
20-
<div
21-
class="main-header-end u-margin-inline-end-16"
22-
v-if="user.isLoggedIn.value === true"
23-
>
24-
<p>
25-
{{ user.current.value.providerUid }}
26-
</p>
27-
<button class="button" type="button" @click="user.logout()">
28-
Logout
29-
</button>
30-
</div>
31-
<NuxtLink v-else href="/login" class="button u-margin-inline-end-16"
32-
>Login</NuxtLink
33-
>
34-
</nav>
35-
<NuxtPage />
36-
</NuxtLayout>
37-
</div>
38-
</template>
13+
...
14+
<NuxtLayout>
15+
16+
<!--- Navbar -->
17+
<nav class="main-header u-padding-inline-end-0">
18+
<h3 class="u-stretch eyebrow-heading-1">Idea Tracker</h3>
19+
20+
<!-- Email and logout button if logged in user -->
21+
<div
22+
class="main-header-end u-margin-inline-end-16"
23+
v-if="user.isLoggedIn.value === true"
24+
>
25+
<p>
26+
{{ user.current.value.providerUid }}
27+
</p>
28+
<button class="button" type="button" @click="user.logout()">
29+
Logout
30+
</button>
31+
</div>
32+
33+
<!-- Login button if no user logged in -->
34+
<NuxtLink v-else href="/login" class="button u-margin-inline-end-16">
35+
Login
36+
</NuxtLink>
37+
</nav>
38+
<NuxtPage />
39+
</NuxtLayout>
40+
...
41+
```
3942

43+
Add a new script below the template to get information about the user session from the `useUserSession`composable.
44+
45+
```vue
4046
<script>
4147
export default {
4248
setup() {
43-
const user = useUserSession();
44-
49+
const user = useUserSession(); //Access the user session composable
4550
return {
4651
user,
4752
};
4853
},
4954
};
5055
</script>
5156
```
57+
58+
You might wonder about the v-

src/routes/docs/tutorials/nuxt/step-6/+page.markdoc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Add database
44
description: Add databases and queries for ideas in your Nuxt project.
55
step: 6
66
---
7-
# Create collection {% #create-collection %}
7+
88
In Appwrite, data is stored as a collection of documents. Create a collection in the [Appwrite Console](https://cloud.appwrite.io/) to store our ideas.
99

1010
{% only_dark %}
@@ -21,11 +21,14 @@ Create a new collection with the following attributes:
2121
| title | String | Yes |
2222
| description | String | No |
2323

24-
Change the collection's permissions settings to give any role access to it.
24+
Change the collection's permissions in the settings to give access.
25+
First, add an "Any" role and check the `READ` box.
26+
Next, add a "Users" role and give them access to create, update and delete.
2527

2628
# Query methods {% #query-methods %}
27-
Now that you have a collection to hold ideas, we can read and write to it from our app.
28-
Create a new file in the composables directory, `src/composables/useIdeas.js` and add the following code to it.
29+
Now that you have a collection to hold ideas, we can use it to get, add and remove data from our app.
30+
We will create a new composable to manage the data fetching and their global state.
31+
Create a new file in the composables directory, `src/composables/useIdeas.js` and add the following code.
2932

3033
```js
3134
import { ID, Query } from "appwrite";
@@ -35,9 +38,12 @@ import { ref } from "vue";
3538
const IDEAS_DATABASE_ID = "YOUR_DATABASE_ID";
3639
const IDEAS_COLLECTION_ID = "YOUR_COLLECTION_ID";
3740

38-
const current = ref(null);
41+
const current = ref(null); //Reference for the fetched data
3942

4043
export const useIdeas = () => {
44+
45+
/* Fetch the 10 most recent ideas from the database
46+
and passes the list to the current reference object */
4147
const init = async () => {
4248
const response = await database.listDocuments(
4349
IDEAS_DATABASE_ID,
@@ -46,6 +52,9 @@ export const useIdeas = () => {
4652
);
4753
current.value = response.documents;
4854
};
55+
56+
/* Add new idea to the database, add it to the current
57+
object and remove the last to still have 10 ideas */
4958
const add = async (idea) => {
5059
const response = await database.createDocument(
5160
IDEAS_DATABASE_ID,
@@ -54,12 +63,10 @@ export const useIdeas = () => {
5463
idea
5564
);
5665
current.value = [response, ...current.value].slice(0, 10);
57-
};
5866

5967
const remove = async (id) => {
6068
await database.deleteDocument(IDEAS_DATABASE_ID, IDEAS_COLLECTION_ID, id);
61-
current.value = current.value.filter((idea) => idea.$id !== id);
62-
await init(); // Refetch ideas to ensure we have 10 items
69+
await init(); //Refetch ideas to ensure we have 10 items
6370
};
6471

6572
return {

0 commit comments

Comments
 (0)