-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
180 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { api } from "@/site/api"; | ||
import { Todo } from "../todo/types"; | ||
|
||
type GetTodosResponse = { | ||
export type GetTodosResponse = { | ||
todos: Todo[]; | ||
}; | ||
|
||
export const getTodos = async ( | ||
consoleMessage?: string, | ||
init?: RequestInit, | ||
): Promise<GetTodosResponse> => { | ||
console.log("fatching todos" + " " + consoleMessage); | ||
const resJSON = await fetch(`${api.route}/todos`, init); | ||
console.log("fatching todos finished" + " " + consoleMessage); | ||
const data = (await resJSON.json()) as GetTodosResponse; | ||
return data; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { api } from "@/site/api"; | ||
import { User } from "../user/types"; | ||
|
||
export type GetUserResponse = { | ||
users: User[]; | ||
}; | ||
|
||
export const getUsers = async ( | ||
consoleMessage?: string, | ||
init?: RequestInit, | ||
): Promise<GetUserResponse> => { | ||
console.log("fatching users" + " " + consoleMessage); | ||
const resJSON = await fetch(`${api.route}/users`, init); | ||
console.log("fatching users finished" + " " + consoleMessage); | ||
const data = (await resJSON.json()) as GetUserResponse; | ||
return data; | ||
}; |
5 changes: 5 additions & 0 deletions
5
apps/bible/app/bible/data-fetching/parrallel-and-sequential/components/bad-example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { ShowTodos } from "@/app/todos/components/show-todos"; | ||
|
||
export const BadExample = () => { | ||
return <ShowTodos />; | ||
}; |
5 changes: 5 additions & 0 deletions
5
apps/bible/app/bible/data-fetching/parrallel-and-sequential/components/good-example.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { DisplayTodos } from "@/app/todos/components/display-todos"; | ||
|
||
export const GoodExample = () => { | ||
return <DisplayTodos />; | ||
}; |
22 changes: 22 additions & 0 deletions
22
apps/bible/app/bible/data-fetching/parrallel-and-sequential/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Suspense } from "react"; | ||
import { BadExample } from "./components/bad-example"; | ||
import { GoodExample } from "./components/good-example"; | ||
|
||
const ParrallelAndSequentialPage = () => { | ||
return ( | ||
<div className="grid grid-cols-2 gap-lg"> | ||
<div> | ||
<Suspense fallback="bad example loading.."> | ||
<BadExample /> | ||
</Suspense> | ||
</div> | ||
<div> | ||
<Suspense fallback="good example loading.."> | ||
<GoodExample /> | ||
</Suspense> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ParrallelAndSequentialPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getTodos } from "@/app/api/todo"; | ||
import { getUsers } from "@/app/api/users"; | ||
import { Todo } from "@/app/todo/components/todo"; | ||
import { DisplayUsers } from "@/app/user/components/display-users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
|
||
export const DisplayTodos = async () => { | ||
const todosPromise = getTodos("good example"); | ||
const usersPromise = getUsers("good example"); | ||
const [todos, users] = await Promise.all([todosPromise, usersPromise]); | ||
|
||
// One more bad example | ||
// const todos = await getTodos("good example"); | ||
// const users = await getUsers("good example"); | ||
|
||
return ( | ||
<Stack> | ||
<Text>Todos:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{todos.todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</Stack> | ||
<DisplayUsers users={users.users} /> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { getTodos } from "@/app/api/todo"; | ||
import { Todo } from "@/app/todo/components/todo"; | ||
import { ShowUsers } from "@/app/user/components/show-users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
|
||
export const ShowTodos = async () => { | ||
const { todos } = await getTodos("bad example"); | ||
return ( | ||
<Stack> | ||
<Text>Todos:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{todos.map((todo) => ( | ||
<Todo key={todo.id} {...todo} /> | ||
))} | ||
</Stack> | ||
<ShowUsers /> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { GetUserResponse } from "@/app/api/users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
import { User } from "./user"; | ||
import { FC } from "react"; | ||
|
||
export const DisplayUsers: FC<GetUserResponse> = ({ users }) => { | ||
return ( | ||
<Stack> | ||
<Text>Users:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{users.map((user) => ( | ||
<User key={user.id} {...user} /> | ||
))} | ||
</Stack> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { getUsers } from "@/app/api/users"; | ||
import { Stack } from "@/components/primitives/stack"; | ||
import { Text } from "@/components/typography/text"; | ||
import { User } from "./user"; | ||
|
||
export const ShowUsers = async () => { | ||
const { users } = await getUsers("bad exmaple"); | ||
return ( | ||
<Stack> | ||
<Text>Users:</Text> | ||
<Stack className="max-h-[200px] overflow-scroll p-md border-4"> | ||
{users.map((user) => ( | ||
<User key={user.id} {...user} /> | ||
))} | ||
</Stack> | ||
</Stack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Text } from "@/components/typography/text"; | ||
import { FC } from "react"; | ||
import { User as UserType } from "../types"; | ||
|
||
export const User: FC<UserType> = (user) => { | ||
return ( | ||
<div className="p-md border rounded"> | ||
<Text>{user.firstName}</Text> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type User = { | ||
id: number | ||
firstName: string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {}; | ||
const nextConfig = { | ||
experimental: { | ||
typedRoutes: true, | ||
}, | ||
}; | ||
|
||
export default nextConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export const routes = { | ||
todos: { | ||
index: "/todos", | ||
}, | ||
bible: { | ||
dataFetching: { | ||
parrallelAndSequential: { | ||
index: "/bible/data-fetching/parrallel-and-sequential", | ||
}, | ||
}, | ||
}, | ||
} as const; |