File tree Expand file tree Collapse file tree 6 files changed +209
-0
lines changed Expand file tree Collapse file tree 6 files changed +209
-0
lines changed Original file line number Diff line number Diff line change 11
11
},
12
12
"dependencies" : {
13
13
"@radix-ui/react-slot" : " 1.1.0" ,
14
+ "@reduxjs/toolkit" : " 2.2.6" ,
14
15
"class-variance-authority" : " 0.7.0" ,
15
16
"clsx" : " 2.1.1" ,
16
17
"lucide-react" : " 0.399.0" ,
17
18
"react" : " ^18.3.1" ,
18
19
"react-dom" : " ^18.3.1" ,
20
+ "react-redux" : " 9.1.2" ,
19
21
"react-router-dom" : " 6.24.0" ,
20
22
"tailwind-merge" : " 2.3.0" ,
21
23
"tailwindcss-animate" : " 1.0.7"
Original file line number Diff line number Diff line change 1
1
import { Button } from "@/components/ui/button" ;
2
2
import { Link } from "react-router-dom" ;
3
+ import { increment , decrement } from "../store/features/counter/counterSlice" ;
4
+ import { useDispatch , useSelector } from "react-redux" ;
5
+ import { RootState } from "../store/store" ;
3
6
4
7
const LandingPage = ( ) => {
8
+ const count = useSelector ( ( state : RootState ) => state . counter . count ) ;
9
+ const dispatch = useDispatch ( ) ;
10
+
5
11
return (
6
12
< div className = "h-[100vh] flex flex-col justify-center items-center" >
7
13
< h1 className = "text-[128px] font-medium-" > LibraryHub</ h1 >
8
14
< p className = "text-[36px] font-medium" >
9
15
Your central place for all library needs
10
16
</ p >
17
+
18
+
19
+ < div className = "flex mt-[20px] gap-[10px]" >
20
+ < Button
21
+ onClick = { ( ) => dispatch ( decrement ( ) ) }
22
+ variant = "outline"
23
+
24
+ >
25
+ -
26
+ </ Button >
27
+ < div className = "border p-[7px] rounded-[7px]" > { count } </ div >
28
+ < Button
29
+ onClick = { ( ) => dispatch ( increment ( ) ) }
30
+ variant = "outline"
31
+
32
+ >
33
+ +
34
+ </ Button >
35
+
36
+ </ div >
37
+
38
+
11
39
< div className = "flex gap-[20px] mt-[50px]" >
12
40
< Link to = { "management/login" } >
13
41
< Button variant = "outline" > Create A Library</ Button >
Original file line number Diff line number Diff line change @@ -2,9 +2,14 @@ import React from 'react'
2
2
import ReactDOM from 'react-dom/client'
3
3
import App from './App.tsx'
4
4
import './index.css'
5
+ import store from './store/store'
6
+ import { Provider } from 'react-redux'
7
+
5
8
6
9
ReactDOM . createRoot ( document . getElementById ( 'root' ) ! ) . render (
7
10
< React . StrictMode >
11
+ < Provider store = { store } >
8
12
< App />
13
+ </ Provider >
9
14
</ React . StrictMode > ,
10
15
)
Original file line number Diff line number Diff line change
1
+ import { createSlice } from "@reduxjs/toolkit" ;
2
+
3
+ const initialState = {
4
+ count :0
5
+ }
6
+
7
+ export const counterSlice = createSlice ( {
8
+ name :'counter' ,
9
+ initialState,
10
+ reducers :{
11
+ increment :( state ) => {
12
+ state . count += 1 ;
13
+ } ,
14
+ decrement :( state ) => {
15
+ state . count -= 1 ;
16
+ }
17
+
18
+ }
19
+
20
+ } ) ;
21
+
22
+ export const { increment, decrement} = counterSlice . actions ;
23
+ export default counterSlice . reducer ;
Original file line number Diff line number Diff line change
1
+ // store.ts
2
+ import { configureStore } from '@reduxjs/toolkit' ;
3
+ import counterReducer from './features/counter/counterSlice' ; // Adjust the import path if necessary
4
+
5
+ const store = configureStore ( {
6
+ reducer : {
7
+ counter : counterReducer ,
8
+ } ,
9
+ } ) ;
10
+
11
+ export type RootState = ReturnType < typeof store . getState > ;
12
+ export type AppDispatch = typeof store . dispatch ;
13
+
14
+ export default store ;
You can’t perform that action at this time.
0 commit comments