Skip to content

Commit bc13aee

Browse files
committed
start frameworks logic
1 parent 021e127 commit bc13aee

4 files changed

Lines changed: 78 additions & 12 deletions

File tree

frameworks.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
<label for="aspnet2" class="radio">ASP.NET</label>
8787
</fieldset>
8888

89-
<button type="submit" class="btn-submit" disabled>Compare</button>
89+
<button type="submit" class="btn-submit">Compare</button>
9090
</form>
9191

92-
<h1 id="frameworks-heading">Compare React to Vue.js</h1>
92+
<h1 id="frameworks-heading"></h1>
9393
<p><em>Hard coded examples</em></p>
9494

9595
<!-- Start -->
@@ -234,6 +234,7 @@ <h2>codeCompare</h2>
234234
</footer>
235235

236236
<script src="./js/global.js"></script>
237+
<script src="./js/data/frameworksEls.js"></script>
237238
<script src="./js/frameworks.js"></script>
238239
<script src="./js/prism.js"></script>
239240
</body>

js/data/frameworksEls.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const React = {
2+
listEls: [],
3+
preEls: []
4+
}
5+
const Vue = {
6+
listEls: [],
7+
preEls: []
8+
}
9+
const Svelte = {
10+
listEls: [],
11+
preEls: []
12+
}
13+
const Angular = {
14+
listEls: [],
15+
preEls: []
16+
}
17+
const Django = {
18+
listEls: [],
19+
preEls: []
20+
}
21+
const Laravel = {
22+
listEls: [],
23+
preEls: []
24+
}
25+
const ASP = {
26+
listEls: [],
27+
preEls: []
28+
}

js/details.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function handleMethodSelect(e) {
148148
// 6. Form submit
149149
function handleDetailsFormSubmit(e) {
150150
e.preventDefault();
151-
console.log('Form submit')
151+
152152
setLocalStorage('type-selection', dataTypeSelect.selectedIndex);
153153
setLocalStorage('method-selection', methodsSelect.selectedIndex);
154154

js/frameworks.js

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,20 @@ const secondaryRadios = document.querySelectorAll(
1717
);
1818
const 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+
2030
const state = {
2131
primaryFW: '',
22-
secondaryFW: ''
32+
secondaryFW: '',
33+
heading: ''
2334
};
2435

2536
/**
@@ -28,24 +39,44 @@ const state = {
2839
// 1. On page visit
2940
function 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
3451
function 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
4060
function 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
4669
function 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) {
5586
document.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
68105
frameworksForm.addEventListener('submit', handleFrameworksFormSubmit);

0 commit comments

Comments
 (0)