1
+ import { useState } from "react" ;
1
2
import "./App.css" ;
2
3
import ExperienceComponent from "./features/experience/ExperienceComponent" ;
3
- import data from "./data" ;
4
4
import {
5
5
PDFDownloadLink ,
6
6
Document ,
@@ -12,6 +12,7 @@ import {
12
12
import AddEducation from "./features/education/addEducation" ;
13
13
import AddSkills from "./features/skills/addSkills" ;
14
14
import UserInformationComponent from "./features/user-information/UserInformationComponent" ;
15
+ import { API_URL } from "./constants" ;
15
16
16
17
const styles = StyleSheet . create ( {
17
18
page : {
@@ -33,78 +34,135 @@ const styles = StyleSheet.create({
33
34
} ,
34
35
} ) ;
35
36
36
- const MyDoc = ( ) => (
37
+ const MyDoc = ( { resumeData } ) => (
37
38
< Document >
38
39
< Page style = { styles . page } >
39
40
< Text style = { styles . header } > Resume</ Text >
40
41
41
- { /* Experience Section */ }
42
+ < View style = { styles . section } >
43
+ < Text style = { styles . itemTitle } > User Information</ Text >
44
+ { resumeData . user_information ?. map ( ( info , index ) => (
45
+ < View key = { index } style = { { marginBottom : 10 } } >
46
+ < Text > { `Name: ${ info . name } ` } </ Text >
47
+ < Text > { `Email: ${ info . email_address } ` } </ Text >
48
+ < Text > { `Phone: ${ info . phone_number } ` } </ Text >
49
+ </ View >
50
+ ) ) }
51
+ </ View >
52
+
42
53
< View style = { styles . section } >
43
54
< Text style = { styles . itemTitle } > Experience</ Text >
44
- { data . experience . map ( ( exp , index ) => (
55
+ { resumeData . experience ? .map ( ( exp , index ) => (
45
56
< View key = { index } style = { { marginBottom : 10 } } >
46
57
< Text > { `${ exp . title } at ${ exp . company } (${ exp . start_date } - ${ exp . end_date } )` } </ Text >
47
58
< Text > { exp . description } </ Text >
48
59
</ View >
49
60
) ) }
50
61
</ View >
51
62
52
- { /* Education Section */ }
53
63
< View style = { styles . section } >
54
64
< Text style = { styles . itemTitle } > Education</ Text >
55
- { data . education . map ( ( edu , index ) => (
65
+ { resumeData . education ? .map ( ( edu , index ) => (
56
66
< View key = { index } style = { { marginBottom : 10 } } >
57
- < Text > { `${ edu . degree } from ${ edu . institution } (${ edu . start_date } - ${ edu . end_date } )` } </ Text >
67
+ < Text > { `${ edu . course } from ${ edu . school } (${ edu . start_date } - ${ edu . end_date } )` } </ Text >
58
68
< Text > Grade: { edu . grade } </ Text >
59
69
</ View >
60
70
) ) }
61
71
</ View >
62
72
63
- { /* Skills Section */ }
64
73
< View style = { styles . section } >
65
74
< Text style = { styles . itemTitle } > Skills</ Text >
66
- { data . skill . map ( ( skill , index ) => (
67
- < Text key = { index } > { `${ skill . name } (${ skill . experience } )` } </ Text >
75
+ { resumeData . skill ? .map ( ( skill , index ) => (
76
+ < Text key = { index } > { `${ skill . name } (${ skill . proficiency } )` } </ Text >
68
77
) ) }
69
78
</ View >
70
79
</ Page >
71
80
</ Document >
72
81
) ;
73
82
74
83
function App ( ) {
84
+ const [ resumeData , setResumeData ] = useState ( null ) ;
85
+ const [ loading , setLoading ] = useState ( false ) ;
86
+ const [ error , setError ] = useState ( false ) ;
87
+
88
+ const handleGenerateResume = ( ) => {
89
+ setLoading ( true ) ;
90
+ fetch ( `${ API_URL } /resume/data` )
91
+ . then ( ( response ) => response . json ( ) )
92
+ . then ( ( data ) => {
93
+ setResumeData ( data ) ;
94
+ setLoading ( false ) ;
95
+ } )
96
+ . catch ( ( err ) => {
97
+ setError ( true ) ;
98
+ setLoading ( false ) ;
99
+ } ) ;
100
+ } ;
101
+
102
+ const handleResetData = ( ) => {
103
+ fetch ( `${ API_URL } /reset` , {
104
+ method : "POST" ,
105
+ } )
106
+ . then ( ( response ) => {
107
+ if ( ! response . ok ) {
108
+ throw new Error ( "Failed to reset data" ) ;
109
+ }
110
+ window . location . reload ( ) ;
111
+ } )
112
+ . catch ( ( err ) => {
113
+ console . error ( "Error resetting data:" , err ) ;
114
+ } ) ;
115
+ } ;
116
+
75
117
return (
76
118
< div className = "App" >
77
119
< h1 > Resume Builder</ h1 >
78
120
< div className = "resumeSection" >
79
121
< h2 > User Information</ h2 >
80
122
< UserInformationComponent />
81
- < br > </ br >
123
+ < br / >
82
124
</ div >
83
125
< div className = "resumeSection" >
84
126
< h2 > Experience</ h2 >
85
127
< ExperienceComponent />
86
- < br > </ br >
128
+ < br / >
87
129
</ div >
88
130
89
131
< div className = "resumeSection" >
90
132
< h2 > Education</ h2 >
91
133
< AddEducation />
92
- < br > </ br >
134
+ < br / >
93
135
</ div >
94
136
95
137
< div className = "resumeSection" >
96
138
< h2 > Skills</ h2 >
97
139
< AddSkills />
98
- < br > </ br >
140
+ < br / >
99
141
</ div >
100
142
101
- < br > </ br >
143
+ < br / >
102
144
103
- < button >
104
- < PDFDownloadLink document = { < MyDoc /> } fileName = "resume.pdf" >
105
- { ( { loading } ) => ( loading ? "Generating PDF..." : "Download Resume" ) }
106
- </ PDFDownloadLink >
145
+ < button onClick = { handleGenerateResume } >
146
+ { loading ? "Loading..." : "Generate Resume" }
107
147
</ button >
148
+
149
+ { resumeData && (
150
+ < button >
151
+ < PDFDownloadLink
152
+ document = { < MyDoc resumeData = { resumeData } /> }
153
+ fileName = "resume.pdf"
154
+ >
155
+ { ( { loading } ) =>
156
+ loading ? "Generating PDF..." : "Download Resume"
157
+ }
158
+ </ PDFDownloadLink >
159
+ </ button >
160
+ ) }
161
+
162
+ < br />
163
+ < br />
164
+
165
+ < button onClick = { handleResetData } > Reset Data</ button >
108
166
</ div >
109
167
) ;
110
168
}
0 commit comments