@@ -17,9 +17,20 @@ const secondaryRadios = document.querySelectorAll(
1717) ;
1818const h1 = document . getElementById ( 'frameworks-heading' ) ;
1919
20+ const frameworks = {
21+ React,
22+ Vue,
23+ Svelte,
24+ Angular,
25+ Django,
26+ Laravel,
27+ ASP
28+ } ;
29+
2030const state = {
2131 primaryFW : '' ,
22- secondaryFW : ''
32+ secondaryFW : '' ,
33+ heading : ''
2334} ;
2435
2536/**
@@ -28,24 +39,44 @@ const state = {
2839// 1. On page visit
2940function initFrameworksPage ( ) {
3041 console . log ( 'DOMContentLoaded' )
42+ state . primaryFW = getLocalStorage ( 'primary-fw' ) || '' ;
43+ state . secondaryFW = getLocalStorage ( 'secondary-fw' ) || '' ;
44+ state . heading = getLocalStorage ( 'fw-heading' ) || 'Choose a primary framework and a secondary framework' ;
45+
46+ h1 . textContent = state . heading ;
47+
3148}
3249
3350// 2. Primary radio button check
3451function handlePrimaryCheck ( e ) {
3552 if ( ! e . target . checked ) return ;
3653 console . log ( e . target . value )
54+
55+ state . primaryFW = e . target . value ;
56+ setLocalStorage ( 'primary-fw' , state . primaryFW ) ;
3757}
3858
3959// 3. Secondary radio button check
4060function handleSecondaryCheck ( e ) {
4161 if ( ! e . target . checked ) return ;
42- console . log ( e . target . value )
62+ console . log ( e . target . value ) ;
63+
64+ state . secondaryFW = e . target . value ;
65+ setLocalStorage ( 'secondary-fw' , state . secondaryFW ) ;
4366}
4467
4568// 4. Form submit
4669function handleFrameworksFormSubmit ( e ) {
4770 e . preventDefault ( ) ;
48- console . log ( 'Form submit' )
71+ console . log ( e )
72+
73+ state . detailsPrimary
74+ const primaryFramewrok = getLocalStorage ( 'primary-fw' ) ;
75+ const secondaryFramewrok = getLocalStorage ( 'secondary-fw' ) ;
76+ state . heading = `Compare ${ primaryFramewrok } to ${ secondaryFramewrok } ` ;
77+ h1 . textContent = state . heading ;
78+
79+ setLocalStorage ( 'fw-heading' , state . heading ) ;
4980}
5081
5182/**
@@ -55,14 +86,20 @@ function handleFrameworksFormSubmit(e) {
5586document . addEventListener ( 'DOMContentLoaded' , initFrameworksPage ) ;
5687
5788// 2. Radio button check for user's primary language
58- primaryRadios . forEach ( radio =>
59- radio . addEventListener ( 'change' , handlePrimaryCheck )
60- ) ;
89+ primaryRadios . forEach ( radio => {
90+ radio . addEventListener ( 'change' , handlePrimaryCheck ) ;
91+ getLocalStorage ( 'primary-fw' ) === radio . value
92+ ? radio . checked = true
93+ : false ;
94+ } ) ;
6195
6296// 3. Radio button check for user's language to compare to their primary
63- secondaryRadios . forEach ( radio =>
64- radio . addEventListener ( 'change' , handleSecondaryCheck )
65- ) ;
97+ secondaryRadios . forEach ( radio => {
98+ radio . addEventListener ( 'change' , handleSecondaryCheck ) ;
99+ getLocalStorage ( 'secondary-fw' ) === radio . value
100+ ? radio . checked = true
101+ : false ;
102+ } ) ;
66103
67104// 4. form listener
68105frameworksForm . addEventListener ( 'submit' , handleFrameworksFormSubmit ) ;
0 commit comments