Skip to content

Commit

Permalink
WIP app unsocial update to install surge b00tc4mp#183
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudi1991 committed Oct 15, 2024
1 parent 0c9235c commit 55f092c
Show file tree
Hide file tree
Showing 23 changed files with 551 additions and 5 deletions.
14 changes: 14 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* Constructs Button instances
*
* @param {string} text The text of the button
* @param {string} type the button type
*/
function Button(text, type) {
Compo.call(this, document.createElement("button"))

this.container.innerText = text
this.container.type = type
}

Button.extends(Compo)
19 changes: 19 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Code.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
*
* @param {*} text
*/
function Code(text) {
Compo.call(this, document.createElement("code"))

this.container.innerText = text
}

Code.extends(Compo)

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

Code.prototype.getText = function () {
return this.container.innerText
}
32 changes: 32 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Compo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Constructs Compo instances
*
* @param {HTMLElement} container The DOM container of the Compo instance
*/
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.removeSelf = 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()
}

Compo.prototype.addBehavior = function (type, callback) {
this.container.addEventListener(type, callback)
}
12 changes: 12 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Constructs Form intances
*/
function Form() {
Compo.call(this, document.createElement("form"))
}

Form.extends(Compo)

Form.prototype.reset = function () {
this.container.reset()
}
13 changes: 13 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Heading.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Constructs Heading instances
*
* @param {string} text The text of the heading
* @param {number} level The heading level
*/
function Heading(text, level) {
Compo.call(this, document.createElement("h" + level))

this.container.innerText = text
}

Heading.extends(Compo)
11 changes: 11 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Image.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Constructs Image instances
*/
function Image(address) {
Compo.call(this, document.createElement("img"))

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

Image.extends(Compo)
32 changes: 32 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/Input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Constructs Input instances
*
* @param {string} type The input type
* @param {string} id The input id
*/
function Input(type, id) {
Compo.call(this, document.createElement("input"))
this.container.style.width = "100%"
this.container.style.boxSizing = "border-box"

this.container.type = type
this.container.id = id
}

Input.extends(Compo)

Input.prototype.getValue = function () {
return this.container.value
}

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
}
34 changes: 34 additions & 0 deletions staff/claudi-cano/unsocial5/Compo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Compo v0.0.0</title>
</head>

<body>
<script src="../proto-chain/index.js"></script>

<script src="Compo.js"></script>
<script src="Button.js"></script>
<script src="Code.js"></script>
<script src="Form.js"></script>
<script src="Heading.js"></script>
<script src="Image.js"></script>
<script src="Input.js"></script>
<script src="Label.js"></script>
<script src="Link.js"></script>
<script src="ListItem.js"></script>
<script src="Paragraph.js"></script>
<script src="PasswordInput.js"></script>
<script src="Preformatted.js"></script>
<script src="Snippet.js"></script>
<script src="Span.js"></script>
<script src="Time.js"></script>
<script src="UnorderedList.js"></script>

<script src="main.js"></script>
</body>

</html>
14 changes: 14 additions & 0 deletions staff/claudi-cano/unsocial5/Data/posts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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
}
]
4 changes: 4 additions & 0 deletions staff/claudi-cano/unsocial5/Data/users.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var users = [
{ name: "Peter Pan", email: "[email protected]", username: "peterpan", password: "123123123" },
{ name: "Wendy Darling", email: "[email protected]", username: "wendydarling", password: "123123123" }
]
16 changes: 16 additions & 0 deletions staff/claudi-cano/unsocial5/Logic/authenticateUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function authenticateUser(username, password) {
if (username.length < 4 || username.length > 12)
throw new Error("Invalid username")

if (password.length < 8)
throw new Error("Invalid password")

var user = users.find(function (user) {
return user.username === username && user.password === password
})

if (user === undefined)
throw new Error("Wrong credentials")

return user
}
13 changes: 13 additions & 0 deletions staff/claudi-cano/unsocial5/Logic/createPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function createPost(username, image, text) {
if (username.length < 4 || username.length > 12)
throw new Error("Invalid username")

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

postMessage.push(post)
}
3 changes: 3 additions & 0 deletions staff/claudi-cano/unsocial5/Logic/getPosts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function getPosts() {
return posts
}
27 changes: 27 additions & 0 deletions staff/claudi-cano/unsocial5/Logic/registerUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function registerUser(name, email, username, password, passwordRepeat) {
if (name.length < 2)
throw new Error("Invalid name")

if (!/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test(email))
throw new Error("Invalid e-mail")

if (username.length < 4 || username.length > 12)
throw new Error("Invalid username")

if (password.length < 8)
throw new Error("Invalid password")

if (password !== passwordRepeat)
throw new Error("Passwords do not match")

var user = users.find(function (user) {
return user.username === username || user.email === email
})

if (user !== undefined)
throw new Error("User already exists")

user = { name: name, email: email, username: username, password: password }

user.push(user)
}
4 changes: 4 additions & 0 deletions staff/claudi-cano/unsocial5/Proto-Chain/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Function.prototype.extends = function (form) {
this.prototype = Object.create(form.prototype)
this.prototype.constructor = this
}
39 changes: 35 additions & 4 deletions staff/claudi-cano/unsocial5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,41 @@

<body>

<script src="data.js"></script>
<script src="logic.js"></script>
<script src="compo.js"></script>
<script src="view.js"></script>
<script src="data/users.js"></script>
<script src="data/posts.js"></script>

<script src="logic/authenticateUser.js"></script>
<script src="logic/createPost.js"></script>
<script src="logic/getPosts.js"></script>
<script src="logic/registerUser.js"></script>

<script src="proto-Chain/index.js"></script>

<script src="compo/Compo.js"></script>
<script src="compo/Button.js.js"></script>
<script src="compo/Code.js"></script>
<script src="compo/Form.js"></script>
<script src="compo/Heading.js"></script>
<script src="compo/Image.js"></script>
<script src="compo/Input.js"></script>
<script src="compo/Label.js"></script>
<script src="compo/Link.js"></script>
<script src="compo/ListItem.js"></script>
<script src="compo/Paragraph.js"></script>
<script src="compo/PasswordInput.js"></script>
<script src="compo/Preformatted.js"></script>
<script src="compo/Snippet.js"></script>
<script src="compo/Span.js"></script>
<script src="compo/Time.js"></script>
<script src="compo/UnorderedList.js"></script>

<script src="view/CreatePost.js"></script>
<script src="view/Home.js"></script>
<script src="view/Login.js"></script>
<script src="view/PostItem.js"></script>
<script src="view/PostList.js"></script>
<script src="view/Register.js"></script>

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

</body>
Expand Down
7 changes: 6 additions & 1 deletion staff/claudi-cano/unsocial5/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ var title = new Heading("Unsocial", 1)
page.add(title)

var login = new Login()
page.add(login)
page.add(login)

// loggedInUser = users[0]
var home
// home = new Home()
// page.add(home)
46 changes: 46 additions & 0 deletions staff/claudi-cano/unsocial5/view/CreatePost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function CreatePost() {
Compo.call(this, document.createElement("div"))

var title = new Heading("Create Post", 3)
this.Heading(title)

var form = new Form()

var imageLabel = new Label("Image", "image")
var imageInput = new Input("text", "image")
form.add(imageLabel)
form.add(imageInput)

var textLabel = new Label("Text", "text")
var textInput = new Input("text", "text")
form.add(textLabel)
form.add(textInput)

var submitButton = new Button("Create", "submit")
form.add(submitButton)

this.add(form)

form.addBehavior("submit", function (event) {
event.prevenDefault()

var image = imageInput.getValue()
var text = textInput.getValue()

try {
createPost(loggedInUser.username, image, text)

this.removeSelf()

var postList = new PostList()
home.add(postList)
} catch (error) {
alert(error.message)

console.error(error)
}

}.bind(this))
}

CreatePost.extends(Compo)
Loading

0 comments on commit 55f092c

Please sign in to comment.