-
Notifications
You must be signed in to change notification settings - Fork 306
feat(docs): add pagination tutorial and related files #196
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
Changes from 1 commit
caf422e
82d6d14
648acd1
1eefb63
2c0b172
a0a4a68
f6999c6
55b3491
e1105cb
95391d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,19 @@ | ||
| --- | ||
| layout: tutorial | ||
| title: Build a todos app with React | ||
| description: Learn about using pagination in a React app using Appwrite backend. | ||
| title: Build a todos app with react | ||
| description: Learn about using pagination in a react app using appwrite backend. | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| step: 1 | ||
| difficulty: beginner | ||
| readtime: 10 | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --- | ||
|
|
||
| **Task App(working title)**: An app to track all your tasks that you'll need to get done. In this tutorial, you will build the Task app with Appwrite and React. | ||
| **Todos App**: An app to track all your todos that you'll need to get done. In this tutorial, you will build the todos app with appwrite and react. | ||
|
||
|
|
||
| # Overview {% #overview %} | ||
| **What is pagination in web development and why is it important?** | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Pagination is a technique used in web development to divide a large dataset into smaller manageable chunks. This practice significantly enhances user experience by facilitating easy navigation through the dataset, making the data consumption less overwhelming. It's a common feature in data-rich applications, such as search engines and task management systems, offering numerous benefits like reduced load times, easier data management, and a cleaner, more organized user interface. | ||
| Pagination is a technique used in web development to divide a large dataset into smaller manageable chunks. This practice enhances user experience by facilitating easy navigation through the dataset, making the data consumption less overwhelming. It's a common feature in data-rich applications, such as search engines and task management systems, offering benefits like reduced load times, easier data management, and a cleaner, more organized user interface. | ||
|
|
||
| In this tutorial, while building the Task App using Appwrite and React, you will implement some pagination methods that Appwrite offers to manage the display of tasks efficiently, ensuring a user-friendly interface that allows users to navigate through their tasks effortlessly. | ||
| In this tutorial, while building the Todos app using Appwrite and React, you will use some pagination methods that Appwrite offers to manage the display of tasks efficiently, ensuring a user-friendly interface that allows users to navigate through their tasks effortlessly. | ||
|
|
||
| # Concepts {% #concepts %} | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,24 +1,25 @@ | ||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||
| layout: tutorial | ||||||||||||||||||||||||||||||||||||
| title: Environment Setup | ||||||||||||||||||||||||||||||||||||
| description: setup the environment for seeding the database | ||||||||||||||||||||||||||||||||||||
| title: Environment setup | ||||||||||||||||||||||||||||||||||||
| description: Setup the environment for seeding the database | ||||||||||||||||||||||||||||||||||||
| step: 5 | ||||||||||||||||||||||||||||||||||||
| --- | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Seeding the collection {% #seeding-the-collection %} | ||||||||||||||||||||||||||||||||||||
| Now we need to create a script that will create documents from a setup.json file.Create a new file `./db/setup.js` in the root of the project directory and add the following code to it. | ||||||||||||||||||||||||||||||||||||
| Now we need to create a script that will create documents from a setup.json file.Create a new file `./db/setup.js` in the root of the project directory to hold our related code. | ||||||||||||||||||||||||||||||||||||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||
| Add the following code to it, replacing `[YOUR_DATABASE_ID]` and `[YOUR_COLLECTION_ID]` with your project ID and collection ID. | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| ```js | ||||||||||||||||||||||||||||||||||||
| import { databases } from "../src/lib/appwrite.js"; | ||||||||||||||||||||||||||||||||||||
| import { ID } from "appwrite"; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
gewenyu99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||
| export const TODOS_DATABASE_ID = "651c4c0bdba5256614d1"; | ||||||||||||||||||||||||||||||||||||
| export const TODOS_COLLECTION_ID = "651c4c2e1e86c8de7f13"; | ||||||||||||||||||||||||||||||||||||
| export const TODOS_DATABASE_ID = "[YOUR_DATABASE_ID]"; | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
| export const TODOS_DATABASE_ID = "[YOUR_DATABASE_ID]"; |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| export const TODOS_COLLECTION_ID = "[YOUR_COLLECTION_ID]"; |
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| --- | ||
| layout: tutorial | ||
| title: Adding tasks | ||
| description: Add tasks to your React application using Appwrite | ||
| description: Add tasks to your react application using appwrite | ||
| step: 6 | ||
| --- | ||
| # Add Tasks context {% #add-todos-page %} | ||
| # Add tasks context {% #add-tasks-context %} | ||
|
|
||
| Now we need to display our Todos to the page. In React, we can use [context](https://reactjs.org/docs/context.html) to share data between components. We'll use context and create a simple custom hook to manage out tasks. | ||
|
|
||
|
|
@@ -53,13 +53,13 @@ export function TasksProvider(props) { | |
| ``` | ||
| we will add more functionality to the context later | ||
|
|
||
| # Basic Routing | ||
| ## Basic Routing {% #basic-routing %} | ||
|
|
||
| First, wrap the `main` element with the `TasksProvider` component. | ||
|
|
||
| Update `src/App.jsx` to the following code. | ||
|
|
||
| ```jsx | ||
| ```js | ||
| import { TasksProvider } from "./lib/context/tasks"; | ||
| import { Tasks } from "./pages/Tasks"; | ||
|
|
||
|
|
@@ -76,13 +76,13 @@ function App() { | |
| export default App; | ||
| ``` | ||
|
|
||
| # Tasks page | ||
| ### Tasks page {% #tasks-page %} | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| We are able to create the Tasks page.This will show users a list of tasks that is just a small chuck of the large dataset. | ||
| We are now able to create the Tasks page that will show users a list of tasks that is a small chuck of the large dataset. | ||
|
|
||
| Create a new file `src/pages/Tasks.jsx` and add the following stub code to it. | ||
|
|
||
| ```jsx | ||
| ```js | ||
| import { useTasks } from "../lib/context/tasks"; | ||
| export function Tasks() { | ||
| const tasks = useTasks(); | ||
|
|
@@ -101,4 +101,6 @@ export function Tasks() { | |
| </section> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wild suggestion, is it possible to take out all this complexity, focus on pagination, and just have pagination and UI all in app.jsx? Proper practice? No
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, and would this be the way you would want the pagination methods be structured too. so the user can just overwrite the |
||
| ); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or another idea, if we have this scaffolding, why don't we have each pagination method be in it's own page so someone could look through all 3?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean having one page with three sections on it? |
||
| ``` | ||
| ``` | ||
|
|
||
| In the next two steps, we will explore how to use offset or cursor pagination in our application. | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| --- | ||
| layout: tutorial | ||
| title: Implementing the Offset Pagination | ||
| description: Learn about using offset pagination in a React app using Appwrite backend. | ||
| title: Implementing the offset pagination | ||
| description: Discover offset pagination. The react app will access our appwrite backend using offset pagination. | ||
| step: 7 | ||
| --- | ||
| In this step, we will discover how to add the offset pagination method to our app. | ||
|
|
||
| # What is Offset Pagination? {% #what-is-offset-pagination %} | ||
| # What is offset pagination? {% #what-is-offset-pagination %} | ||
|
|
||
| Offset Pagination is widely used in databases and online APIs to extract specific subsets of data from a bigger whole.It requires you to tell it where to start ("offset") and how many records to get ("limit"). In the context of software applications, offset pagination is a technique that may be employed to facilitate the navigation of content by incorporating forward and back buttons on a given page. | ||
| Offset pagination is widely used in databases and online APIs to extract specific subsets of data from a bigger whole.It requires you to tell it where to start ("offset") and how many records to get ("limit"). In the context of software applications, offset pagination is a technique that may be employed to facilitate the navigation of content by incorporating forward and back buttons on a given page. | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| In Appwrite, offset pagination can be achieved using the `Query.limit()` and `Query.offset()` methods. Here is an example using Appwrite's `listDocuments()` command to list the next four tasks: | ||
|
|
||
|
|
@@ -26,11 +27,11 @@ this will run and retrieve the next four tasks starting at task-5 | |
| # Implementation {% #implementation %} | ||
timDeHof marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| # Task context | ||
| ## Task context {% #task-context %} | ||
|
|
||
| by updating the contents of `src/lib/context/tasks.jsx` with the following: | ||
| By updating the contents of `src/lib/context/tasks.jsx` with the following code, replacing `[YOUR_DATABASE_ID]` and `[YOUR_COLLECTION_ID]` with your project ID and collection ID. | ||
|
|
||
| ```jsx | ||
| ```js | ||
| import { createContext, useContext, useEffect, useState } from "react"; | ||
| import { databases } from "../appwrite"; | ||
| import { Query } from "appwrite"; | ||
|
|
@@ -110,12 +111,12 @@ export function TasksProvider(props) { | |
| } | ||
| ``` | ||
|
|
||
| # Tasks page | ||
| ## Tasks page {% #tasks-page %} | ||
|
|
||
| In order to utilize offset pagination in our app, we want a "forward" and "back" buttons that will allow us to move through our dataset. Also we want to have a way to show the current page too. We will add these pieces of UI to the Tasks page and use the `useTasks` hook to handle the navigation and the UI will have the following: | ||
| * a "back" button that will handle subtracting a given page limit from the offset and will be disabled when at the beginning of the dataset. | ||
| For offset pagination in our app, we need "forward" and "back" buttons to navigate our dataset. We also want to display the current page. The Tasks page will contain the following UI, with navigation handled by the `useTasks` hook: | ||
| * a "back" button that will handle subtracting a given page limit from the offset and disabled when at the beginning of the dataset. | ||
| * a span tag that will show the current page. | ||
| * a "forward" button that will handle adding a given page limit to the offset and will be disabled when we reach the end of the dataset. | ||
| * a "forward" button that will handle adding a given page limit to the offset and disabled when we reach the end of the dataset. | ||
|
|
||
| Update the Tasks page in `src/pages/Tasks.jsx` to the following: | ||
|
|
||
|
|
@@ -178,4 +179,6 @@ function Pagination(props) { | |
| ); | ||
| } | ||
|
|
||
| ``` | ||
| ``` | ||
|
|
||
| In the next step, we will replace our current pagination method with the cursor pagination method. | ||
|
||
Uh oh!
There was an error while loading. Please reload this page.