|
1 |
| -import Image from 'next/image' |
2 |
| -import { Inter } from 'next/font/google' |
3 |
| -import styles from './page.module.css' |
| 1 | +"use client"; |
4 | 2 |
|
5 |
| -const inter = Inter({ subsets: ['latin'] }) |
| 3 | +import { useGetUsersQuery } from "@/redux/api/userApi"; |
| 4 | +import { decrement, increment, reset } from "@/redux/features/counter"; |
| 5 | +import { useAppDispatch, useAppSelector } from "@/redux/hooks"; |
6 | 6 |
|
7 | 7 | export default function Home() {
|
8 |
| - return ( |
9 |
| - <main className={styles.main}> |
10 |
| - <div className={styles.description}> |
11 |
| - <p> |
12 |
| - Get started by editing |
13 |
| - <code className={styles.code}>src/app/page.tsx</code> |
14 |
| - </p> |
15 |
| - <div> |
16 |
| - <a |
17 |
| - href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" |
18 |
| - target="_blank" |
19 |
| - rel="noopener noreferrer" |
20 |
| - > |
21 |
| - By{' '} |
22 |
| - <Image |
23 |
| - src="/vercel.svg" |
24 |
| - alt="Vercel Logo" |
25 |
| - className={styles.vercelLogo} |
26 |
| - width={100} |
27 |
| - height={24} |
28 |
| - priority |
29 |
| - /> |
30 |
| - </a> |
31 |
| - </div> |
32 |
| - </div> |
| 8 | + const count = useAppSelector((state) => state.counterReducer.value); |
| 9 | + const dispatch = useAppDispatch(); |
33 | 10 |
|
34 |
| - <div className={styles.center}> |
35 |
| - <Image |
36 |
| - className={styles.logo} |
37 |
| - src="/next.svg" |
38 |
| - alt="Next.js Logo" |
39 |
| - width={180} |
40 |
| - height={37} |
41 |
| - priority |
42 |
| - /> |
43 |
| - <div className={styles.thirteen}> |
44 |
| - <Image src="/thirteen.svg" alt="13" width={40} height={31} priority /> |
45 |
| - </div> |
46 |
| - </div> |
| 11 | + const { isLoading, isFetching, data, error } = useGetUsersQuery(null); |
47 | 12 |
|
48 |
| - <div className={styles.grid}> |
49 |
| - <a |
50 |
| - href="https://beta.nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" |
51 |
| - className={styles.card} |
52 |
| - target="_blank" |
53 |
| - rel="noopener noreferrer" |
54 |
| - > |
55 |
| - <h2 className={inter.className}> |
56 |
| - Docs <span>-></span> |
57 |
| - </h2> |
58 |
| - <p className={inter.className}> |
59 |
| - Find in-depth information about Next.js features and API. |
60 |
| - </p> |
61 |
| - </a> |
62 |
| - |
63 |
| - <a |
64 |
| - href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" |
65 |
| - className={styles.card} |
66 |
| - target="_blank" |
67 |
| - rel="noopener noreferrer" |
| 13 | + return ( |
| 14 | + <main style={{ maxWidth: 1200, marginInline: "auto", padding: 20 }}> |
| 15 | + <div style={{ marginBottom: "4rem", textAlign: "center" }}> |
| 16 | + <h4 style={{ marginBottom: 16 }}>{count}</h4> |
| 17 | + <button onClick={() => dispatch(increment())}>increment</button> |
| 18 | + <button |
| 19 | + onClick={() => dispatch(decrement())} |
| 20 | + style={{ marginInline: 16 }} |
68 | 21 | >
|
69 |
| - <h2 className={inter.className}> |
70 |
| - Templates <span>-></span> |
71 |
| - </h2> |
72 |
| - <p className={inter.className}>Explore the Next.js 13 playground.</p> |
73 |
| - </a> |
| 22 | + decrement |
| 23 | + </button> |
| 24 | + <button onClick={() => dispatch(reset())}>reset</button> |
| 25 | + </div> |
74 | 26 |
|
75 |
| - <a |
76 |
| - href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app" |
77 |
| - className={styles.card} |
78 |
| - target="_blank" |
79 |
| - rel="noopener noreferrer" |
| 27 | + {error ? ( |
| 28 | + <p>Oh no, there was an error</p> |
| 29 | + ) : isLoading || isFetching ? ( |
| 30 | + <p>Loading...</p> |
| 31 | + ) : data ? ( |
| 32 | + <div |
| 33 | + style={{ |
| 34 | + display: "grid", |
| 35 | + gridTemplateColumns: "1fr 1fr 1fr 1fr", |
| 36 | + gap: 20, |
| 37 | + }} |
80 | 38 | >
|
81 |
| - <h2 className={inter.className}> |
82 |
| - Deploy <span>-></span> |
83 |
| - </h2> |
84 |
| - <p className={inter.className}> |
85 |
| - Instantly deploy your Next.js site to a shareable URL with Vercel. |
86 |
| - </p> |
87 |
| - </a> |
88 |
| - </div> |
| 39 | + {data.map((user) => ( |
| 40 | + <div |
| 41 | + key={user.id} |
| 42 | + style={{ border: "1px solid #ccc", textAlign: "center" }} |
| 43 | + > |
| 44 | + <img |
| 45 | + src={`https://robohash.org/${user.id}?set=set2&size=180x180`} |
| 46 | + alt={user.name} |
| 47 | + style={{ height: 180, width: 180 }} |
| 48 | + /> |
| 49 | + <h3>{user.name}</h3> |
| 50 | + </div> |
| 51 | + ))} |
| 52 | + </div> |
| 53 | + ) : null} |
89 | 54 | </main>
|
90 |
| - ) |
| 55 | + ); |
91 | 56 | }
|
0 commit comments