forked from b00tc4mp/isdi-bootcamp-202409
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP app unsocial update to install surge b00tc4mp#183
- Loading branch information
1 parent
0c9235c
commit 55f092c
Showing
23 changed files
with
551 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function getPosts() { | ||
return posts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Oops, something went wrong.