-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.txt
140 lines (119 loc) · 3.25 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import {fetchBlogs, deleteBlog} from '../features/blogSlice'
import BlogCard from "./BlogCard";
const Blogs = () => {
const dispatch = useDispatch()
const blogState = useSelector((state)=> state.blog)
const handleDelete=(id) =>{
dispatch(deleteBlog(id))
}
useEffect(()=>{
dispatch(fetchBlogs())
},[dispatch])
if(blogState.status ==='pending'){
return <div>loading...</div>
}
if(blogState.status ==='rejected'){
return <div>{blogState.error}</div>
}
return (
<div className="flex flex-wrap gap-2 justify-center">
{ blogState.blogs.map((blog)=>{
return <>
<BlogCard key={blog._id} imageLink={blog.imageLink} blogTitle={blog.blogTitle} blogDescription={blog.blogDescription} blogLink={blog.blogLink} />
<button onClick={handleDelete(blog._id)} key={blog._id}><ion-icon name="trash-outline"></ion-icon></button>
</>
})}
</div>
);
};
export default Blogs;
*****************************
import React, { useEffect } from "react";
import BlogCard from "./BlogCard";
import { useSelector, useDispatch } from "react-redux";
import {fetchBlogs} from '../features/blogSlice'
const Blogs = () => {
const dispatch = useDispatch()
const blogState = useSelector((state)=> state.blog)
useEffect(()=>{
dispatch(fetchBlogs())
},[dispatch])
if(blogState.status ==='pending'){
return <div>loading...</div>
}
if(blogState.status ==='rejected'){
return <div>{blogState.error}</div>
}
return (
<div className="flex flex-wrap gap-2 justify-center">
{ blogState.blogs.map((blog)=>{
return <BlogCard key={blog._id} imageLink={blog.imageLink} blogTitle={blog.blogTitle} blogDescription={blog.blogDescription} blogLink={blog.blogLink} />
})}
</div>
);
};
export default Blogs;
********************
https://fonts.google.com/specimen/Roboto+Slab
****************************
import React from "react";
import * as Yup from "yup";
import { Formik, Form, Field, ErrorMessage } from "formik";
const BlogForm = (props) => {
const validationSchema = Yup.object().shape({
blogTitle: Yup.string().required("Required"),
imageLink: Yup.string().required("Required"),
blogDescription: Yup.string().required("Required"),
blogLink: Yup.string().required("Required"),
});
console.log(props);
return (
<div className="flex flex-col">
<Formik {...props} validationSchema={validationSchema}>
<Form>
<div className="flex flex-col">
<Field name="blogTitle" type="text"/>
<ErrorMessage
name="name"
className="text-red-500"
/>
</div>
<div>
<Field name="imageLink" type="text"/>
<ErrorMessage
name="email"
className="text-red-500"
/>
</div>
<div>
<Field name="blogDescription" type="text"/>
<ErrorMessage
name="email"
className="text-red-500"
/>
</div>
<div>
<Field name="blogDescription" type="text"/>
<ErrorMessage
name="email"
className="text-red-500"
/>
</div>
<div>
<Field name="blogLink" type="text"/>
<ErrorMessage
name="email"
className="text-red-500"
/>
</div>
<button type="submit">
{props.children}
</button>
</Form>
</Formik>
</div>
);
};
export default BlogForm;