Skip to content

Commit

Permalink
add compos to unsocial b00tc4mp#169
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixpr27 committed Oct 9, 2024
1 parent dc4b39f commit 1b05de2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
9 changes: 9 additions & 0 deletions staff/aleix-palau/unsocial/compo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Compo(container) {
this.children = []
this.container = container
}

Compo.prototype.add = function (child) {
this.children.push(child)
this.container.appendChild(child.container)
}
3 changes: 3 additions & 0 deletions staff/aleix-palau/unsocial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<h1>UN$0C14L</h1>

<script src="data.js"></script>

<script src="logic.js"></script>

<script src="compo.js"></script>
<script src="view.js"></script>
<script src="main.js"></script>
</body>
Expand Down
4 changes: 2 additions & 2 deletions staff/aleix-palau/unsocial/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ var loggedInUser = null

var loginSection = buildLoginSection()

var body = document.querySelector('body')
body.appendChild(loginSection)
var body = new Compo(document.querySelector('body'))
body.add(loginSection)
28 changes: 17 additions & 11 deletions staff/aleix-palau/unsocial/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function buildButton(text, type) {
}

function buildHomeSection() {
var section = document.createElement('section')
var compo = new Compo(document.createElement('section'))

var section = compo.container

var title = document.createElement('h2')
title.innerText = 'Home'
Expand All @@ -40,14 +42,16 @@ function buildHomeSection() {

section.remove()

body.appendChild(loginSection)
body.add(loginSection)
})

return section
return compo
}

function buildRegisterSection() {
var section = document.createElement('section')
var compo = new Compo(document.createElement('section'))

var section = compo.container

var title = document.createElement('h2')
title.innerText = 'Register'
Expand Down Expand Up @@ -95,7 +99,7 @@ function buildRegisterSection() {

section.remove()

body.appendChild(loginSection)
body.add(loginSection)
} catch (error) {
alert(error.message)

Expand All @@ -113,14 +117,16 @@ function buildRegisterSection() {

section.remove()

body.appendChild(loginSection)
body.add(loginSection)
})

return section
return compo
}

function buildLoginSection() {
var section = document.createElement('section')
var compo = new Compo(document.createElement('section'))

var section = compo.container

var title = document.createElement('h2')
title.innerText = 'Login'
Expand Down Expand Up @@ -155,7 +161,7 @@ function buildLoginSection() {

var homeSection = buildHomeSection()

body.appendChild(homeSection)
body.add(homeSection)
} catch (error) {
passwordField[1].value = ''

Expand All @@ -177,8 +183,8 @@ function buildLoginSection() {

var registerSection = buildRegisterSection()

body.appendChild(registerSection)
body.add(registerSection)
})

return section
return compo
}

0 comments on commit 1b05de2

Please sign in to comment.