Skip to content

Commit

Permalink
update unsocial home with posts b00tc4mp#168
Browse files Browse the repository at this point in the history
  • Loading branch information
Javi2323J committed Oct 11, 2024
1 parent aef1a62 commit 2dfc502
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 54 deletions.
120 changes: 119 additions & 1 deletion staff/javier-romera/unsocial/compo.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,24 @@
function Compo(container) {
this.children = []
this.container = container
this.parent = null
}

Compo.prototype.add = function (child) {
this.children.push(child)
child.parent = this

this.container.appendChild(child.container)
}

Compo.prototype.remove = function () {
var index = this.parent.children.findIndex(function (child) {
return child === this
}.bind(this))

if (index > -1)
this.parent.children.splice(index, 1)

this.container.remove()
}

Expand Down Expand Up @@ -88,6 +98,14 @@ Input.prototype.setValue = function (value) {
this.container.value = value
}

Input.prototype.getType = function () {
return this.container.type
}

Input.prototype.setType = function (type) {
this.container.type = type
}

/**
* Constructs Heading instances
*
Expand All @@ -114,4 +132,104 @@ function Link(text) {
}

Link.prototype = Object.create(Compo.prototype)
Link.prototype.constructor = Link
Link.prototype.constructor = Link

/**
* Constructs Span instances
*
* @param {string} text The text inside span
*/
function Span(text) {
Compo.call(this, document.createElement('span'))

this.container.innerText = text
}

Span.prototype = Object.create(Compo.prototype)
Span.prototype.constructor = Span

Span.prototype.setText = function (text) {
this.container.innerText = text
}

Span.prototype.getText = function () {
return this.container.innerText
}

Span.prototype = Object.create(Compo.prototype)
Span.prototype.constructor = Span

/**
*
*/
function UnorderedList() {
Compo.call(this, document.createElement('ul'))
}

UnorderedList.prototype = Object.create(Compo.prototype)
UnorderedList.prototype.constructor = UnorderedList

/**
*
*/
function ListItem() {
Compo.call(this, document.createElement('li'))
}

ListItem.prototype = Object.create(Compo.prototype)
ListItem.prototype.constructor = ListItem

/**
*
*/
function Image(address) {
Compo.call(this, document.createElement('img'))

this.container.src = address
this.container.style.width = '100%'
}

Image.prototype = Object.create(Compo.prototype)
Image.prototype.constructor = Image

/**
*
* @param {*} text
*/
function Paragraph(text) {
Compo.call(this, document.createElement('p'))

this.container.innerText = text
}

Paragraph.prototype = Object.create(Compo.prototype)
Paragraph.prototype.constructor = Paragraph

Paragraph.prototype.setText = function (text) {
this.container.innerText = text
}

Paragraph.prototype.getText = function () {
return this.container.innerText
}

/**
*
* @param {*} text
*/
function Time(text) {
Compo.call(this, document.createElement('time'))

this.container.innerText = text
}

Time.prototype = Object.create(Compo.prototype)
Time.prototype.constructor = Time

Time.prototype.setText = function (text) {
this.container.innerText = text
}

Time.prototype.getText = function () {
return this.container.innerText
}
15 changes: 15 additions & 0 deletions staff/javier-romera/unsocial/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,19 @@ var users = [ // La "base de datos" con los usuarios
{ name: 'Peter Pan', email: '[email protected]', username: 'peterpan', password: '123123123' },
{ name: 'Wendy Darling', email: '[email protected]', username: 'wendydarling', password: '123123123' },
{ name: 'Javier', email: '[email protected]', username: 'javi', password: '123123123' }
]

var posts = [
{
image: 'https://i.pinimg.com/originals/8c/60/1a/8c601a25311a1a5098896f751a784b54.jpg',
text: 'here we are',
username: 'peterpan',
date: new Date
},
{
image: 'https://pm1.aminoapps.com/8360/ad07e2d2cdf6e1733328d6e7b7848b87db38a2bbr1-1536-2048v2_hq.jpg',
text: 'here i am',
username: 'wendydarling',
date: new Date
}
]
20 changes: 20 additions & 0 deletions staff/javier-romera/unsocial/logic.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,24 @@ function registerUser(name, email, username, password, confirmpassword) {
user = { 'name': name, 'email': email, 'username': username, 'password': password } // Insertamos el usuario entero

users.push(user)
}

function createPost(username, image, text) {
if (username.length < 4 || username.length > 12)
throw new Error('invalid username')

// TODO input validation (and throw error)

var post = {
image: image,
text: text,
username: username,
date: new Date
}

posts.push(post)
}

function getPosts() {
return posts
}
3 changes: 2 additions & 1 deletion staff/javier-romera/unsocial/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ var title = new Heading('laicosnU', 1) // Título de la página
page.add(title) // Añadimos el título a la página

var login = new Login() // Montamos el login
page.add(login) // Añadimos el login a la page, es decir a la "view" (será lo que veamos al entrar)

page.add(login) // Añadimos el login a la page, es decir a la "view" (será lo que veamos al entrar)
var home
Loading

0 comments on commit 2dfc502

Please sign in to comment.