-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackupreact.jsx
105 lines (78 loc) · 2.45 KB
/
backupreact.jsx
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
import DashboardHeader from "../../components/DashboardHeader";
import RecipeTable from "../../components/RecipeTable";
import { useState, useEffect } from "react";
import Footer from "../../components/Footer";
import FastAPIClient from "../../client";
import config from "../../config";
import jwtDecode from "jwt-decode";
import * as moment from "moment";
const client = new FastAPIClient(config);
const ProfileView = ({ blogs }) => {
const [posts, setposts] = useState(blogs);
return (
<>
<RecipeTable
blogs={ blogs }
showUpdate={true}
/>
</>
);
};
const MyProfile = () => {
const [blogs, setBlogs] = useState([]);
const [loading, setLoading] = useState(false);
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [error, setError] = useState({ label: "", url: "", source: "" });
const [showForm, setShowForm] = useState(false);
const [refreshing, setRefreshing] = useState(false);
useEffect(() => {
return () => {
};
}, [blogs]);
useEffect(() => {
const tokenString = localStorage.getItem("token");
if (tokenString) {
const token = JSON.parse(tokenString);
const decodedAccessToken = jwtDecode(token.access_token);
if (moment.unix(decodedAccessToken.exp).toDate() > new Date()) {
setIsLoggedIn(true);
fetchUserPosts();
}
}
}, []);
const fetchUserPosts = () => {
setLoading(true);
client.getUserPosts()
.then( (response) => {
setRefreshing(false);
setBlogs(response)
setLoading(false)
},
(error)=>{setError(error)})};
return (
<div>
<DashboardHeader/>
<section
className=""
style={{ minHeight: "100vh" }}
>
<div className="container">
{/*TODO - move to component*/}
<h1>
Recipes - Better than all the REST
</h1>
{loading && (<div><p>Loading...</p></div>)}
{blogs && (
<div className="">
{blogs.length && (
<ProfileView
blogs={ blogs }
/>)}
</div>)}
</div>
<Footer />
</section>
</div>
);
}
export default MyProfile;