From 6dbb3c5ecd119f7b451eb09367512a4b3289e8b8 Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Tue, 28 May 2024 10:12:30 +0200 Subject: [PATCH 01/21] add my folder #9 --- staff/lucas-orts/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 staff/lucas-orts/.gitkeep diff --git a/staff/lucas-orts/.gitkeep b/staff/lucas-orts/.gitkeep new file mode 100644 index 000000000..e69de29bb From dc3ab7bb1ee8ee0bf47ffb734c254cd81eaa1a7f Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Tue, 28 May 2024 12:47:23 +0200 Subject: [PATCH 02/21] add cv and blog #27 --- staff/lucas-orts/playground/blog/index.html | 18 ++++++++++++++++++ staff/lucas-orts/playground/cv/index.html | 0 2 files changed, 18 insertions(+) create mode 100644 staff/lucas-orts/playground/blog/index.html create mode 100644 staff/lucas-orts/playground/cv/index.html diff --git a/staff/lucas-orts/playground/blog/index.html b/staff/lucas-orts/playground/blog/index.html new file mode 100644 index 000000000..33183a3f8 --- /dev/null +++ b/staff/lucas-orts/playground/blog/index.html @@ -0,0 +1,18 @@ + + + + + + Mi blog + + +
+

Mi Blog

+

Bienvenidos a mi blog

+
+ + +
+ + \ No newline at end of file diff --git a/staff/lucas-orts/playground/cv/index.html b/staff/lucas-orts/playground/cv/index.html new file mode 100644 index 000000000..e69de29bb From 6a5e63bccd57af20a42d8cef7a53d7e95338e008 Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Wed, 29 May 2024 09:33:12 +0200 Subject: [PATCH 03/21] implement car #27 WIP --- staff/lucas-orts/playground/car/index.html | 0 staff/lucas-orts/playground/car/style.css | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 staff/lucas-orts/playground/car/index.html create mode 100644 staff/lucas-orts/playground/car/style.css diff --git a/staff/lucas-orts/playground/car/index.html b/staff/lucas-orts/playground/car/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/playground/car/style.css b/staff/lucas-orts/playground/car/style.css new file mode 100644 index 000000000..e69de29bb From bebf724438b918e2aa45e0641fcbc83aaf5ea5b6 Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Thu, 30 May 2024 17:43:23 +0200 Subject: [PATCH 04/21] add objects y array #27 --- staff/lucas-orts/playground/arrays/index.js | 55 +++++++++++ .../lucas-orts/playground/building/index.html | 0 .../lucas-orts/playground/building/style.css | 0 staff/lucas-orts/playground/face/index.html | 0 staff/lucas-orts/playground/face/style.css | 0 staff/lucas-orts/playground/objects/index.js | 91 +++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 staff/lucas-orts/playground/arrays/index.js create mode 100644 staff/lucas-orts/playground/building/index.html create mode 100644 staff/lucas-orts/playground/building/style.css create mode 100644 staff/lucas-orts/playground/face/index.html create mode 100644 staff/lucas-orts/playground/face/style.css create mode 100644 staff/lucas-orts/playground/objects/index.js diff --git a/staff/lucas-orts/playground/arrays/index.js b/staff/lucas-orts/playground/arrays/index.js new file mode 100644 index 000000000..c5dfd88fb --- /dev/null +++ b/staff/lucas-orts/playground/arrays/index.js @@ -0,0 +1,55 @@ +console.log('Test arrays') + +console.log('CASE add elements to array') + +var a = new Array + +a[0] = 10 +a[1] = 20 +a[2] = 30 + +console.log(a) +//[10, 20, 30] + +var a = new Array + +a[0] = 10 +a[1] = 20 +a[2] = 30 + +console.log(a) +//[10, 20, 30] + +//a.length= a.length - 1 +//a.length -=1 +a.length-- + +console.log(a) +//[10, 20] + +console.log('CASE remove last 2 elements from array') + +var colors = new Array +colors[0] = 'red' +colors[1] = 'green' +colors[2] = 'blue' +colors[3] = 'yellow' + + + + + +console.log('CASE push an element to array') +var cars = new Array +cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } +cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } +cars[2] = { brand: 'fiat', model: '500', year: 2017 } + +console.log(cars) + +console.log(cars.length) + +cars.push({ brand: 'ford', model: 'fiesta', year: 2005 }) + +console.log(cars) +console.log(cars.length) \ No newline at end of file diff --git a/staff/lucas-orts/playground/building/index.html b/staff/lucas-orts/playground/building/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/playground/building/style.css b/staff/lucas-orts/playground/building/style.css new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/playground/face/index.html b/staff/lucas-orts/playground/face/index.html new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/playground/face/style.css b/staff/lucas-orts/playground/face/style.css new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/playground/objects/index.js b/staff/lucas-orts/playground/objects/index.js new file mode 100644 index 000000000..6ab2e5292 --- /dev/null +++ b/staff/lucas-orts/playground/objects/index.js @@ -0,0 +1,91 @@ +console.log('Test objects') +console.log('CASE add elements to object') + +var o = new Object // {} +o[0] = 10 +o[1] = 20 +o[2] = 30 +o.length = 3 + +console.log(o) +// { 0: 10, 1: 20, 2:30, length: 3 } + +console.log('CASE remove las element from object') + +var o = new Object + +o[0] = 10 +o[1] = 20 +o[2] = 30 +o.length = 3 + +console.log(o) +// { 0: 10, 1: 20, 2:30, length: 3 } + +delete o[2] +//o.length = o.length - 1 +// o.length -= 1 +o.length-- + +console.log(o) +// { 0: 10, 1: 20, length: 2} + +console.log('CASE remove last 2 elements from object') + +var colors = new Object + +colors[0] = 'red' +colors[1] = "green" +colors[2] = 'blue' +colors[3] = 'yellow' +colors.length = 4 + +console.log(colors) +// { 0: red, 1: green, 2: blue, 3: yellow, length: 4} + +delete colors[3] +delete colors[2] +// colors.length = colors.length - 2 +colors.length -= 2 +console.log(colors) + +// { 0: red, 1: green, length: 2} + + +console.log('CASE push an element to object') +var cars = new Object +cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } +cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } +cars[2] = { brand: 'fiat', model: '500', year: 2017 } +cars.length = 3 + +console.log(cars) + +console.log(cars.length) + +cars.push = function (element) { + this[this.length] = element + return this.length++ +} + +cars.push({ brand: 'ford', model: 'fiesta', year: 2005 }) + +console.log(cars) +// { 0: {...}, 1: {...}, 2: {...}, 3: {...}, length: 4 } +console.log(cars.length) + +//cars.pop = function () { +// delete this[this.length - 1] +// return this.length-- +//} +cars.pop = function () { + var lastElement = this[this.length - 1] + delete this[this.length - 1] + this.length-- + + return lastElement +} +console.log(cars.pop()) +console.log(cars) +// { 0: {...}, 1: {...}, 2: {...}, 3: {...}, length: 4 } +console.log(cars.length) \ No newline at end of file From 47b3fcf429ddc92e1cf99044f764ade4519c2958 Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Tue, 4 Jun 2024 18:15:22 +0200 Subject: [PATCH 05/21] implement map.js mob programming #27 --- staff/lucas-orts/playground/objects/map.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 staff/lucas-orts/playground/objects/map.js diff --git a/staff/lucas-orts/playground/objects/map.js b/staff/lucas-orts/playground/objects/map.js new file mode 100644 index 000000000..f350f1521 --- /dev/null +++ b/staff/lucas-orts/playground/objects/map.js @@ -0,0 +1,15 @@ +var numbers = { 0: 1, 1: 4, 2: 9, 3: 16, length: 4 } +numbers.map = function (callbackFn) { + var newObject = { length: 0 } + for (var i = 0; i < this.length; i++) { + + newObject[newObject.length++] = callbackFn(this[i], i, this) + + } + return newObject +} + +const map1 = numbers.map((x) => x + 3); + +console.log(map1); +// Expected output: Array [4, 7, 12, 19] \ No newline at end of file From 9d2328c1b953d09bda2635648cdd90cb80f64355 Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Sun, 9 Jun 2024 21:51:45 +0200 Subject: [PATCH 06/21] implement Array and prototypes until push #27 --- .../Array/Array.prototype.at.test.js | 39 +++++++++++ .../Array/Array.prototype.concat.test.js | 42 ++++++++++++ .../Array/Array.prototype.copyWithin.test.js | 42 ++++++++++++ .../Array/Array.prototype.every.test.js | 29 ++++++++ .../Array/Array.prototype.filter.test.js | 12 ++++ .../Array/Array.prototype.find.test.js | 9 +++ .../Array/Array.prototype.forEach.test.js | 67 +++++++++++++++++++ .../Array/Array.prototype.includes.test.js | 28 ++++++++ .../Array/Array.prototype.indexOf.test.js | 19 ++++++ .../Array/Array.prototype.join.test.js | 38 +++++++++++ .../Array/Array.prototype.lastIndexOf.test.js | 17 +++++ .../Array/Array.prototype.map.test.js | 13 ++++ .../Array/Array.prototype.pop.test.js | 32 +++++++++ .../Array/Array.prototype.push.test.js | 27 ++++++++ .../lucas-orts/playground/Array/Array.test.js | 46 +++++++++++++ 15 files changed, 460 insertions(+) create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.at.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.concat.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.every.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.filter.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.find.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.includes.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.join.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.map.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.pop.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.prototype.push.test.js create mode 100644 staff/lucas-orts/playground/Array/Array.test.js diff --git a/staff/lucas-orts/playground/Array/Array.prototype.at.test.js b/staff/lucas-orts/playground/Array/Array.prototype.at.test.js new file mode 100644 index 000000000..52dabdd45 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.at.test.js @@ -0,0 +1,39 @@ +console.info('TEST Array.prototye.at') + +console.info('CASE element a positive index') + +var nums = [5, 12, 8, 130, 44] +var num = nums.at(3) + +console.assert(num === 130, 'num is 130') + + +console.info('CASE element at index 0') + +var nums = [5, 12, 8, 130, 44] +var num = nums.at(0) + +console.assert(num === 5, 'num is 5') + + +console.info('CASE element a negative index') + +var nums = [5, 12, 8, 130, 44] +var num = nums.at(-3) + +console.assert(num === 8, 'num i 8') + + +console.info('CASE element a positive index greater than length') + +var nums = [5, 12, 8, 130, 44] +var num = nums.at(100) + +console.assert(num === undefined, 'num is undefined') + +console.info('CASE element a negative index greater than -length') + +var nums = [5, 12, 8, 130, 44] +var num = nums.at(-100) + +console.assert(num === undefined, 'num is undefined') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.concat.test.js b/staff/lucas-orts/playground/Array/Array.prototype.concat.test.js new file mode 100644 index 000000000..6582a2465 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.concat.test.js @@ -0,0 +1,42 @@ +console.info('TEST Array.prototype.concat') + +console.info('CASE concat elements from two arrays') + +var chars1 = ['a', 'b', 'c'] +var chars2 = ['d', 'e', 'f'] + +var chars3 = chars1.concat(chars2) + +console.assert(chars3.length === 6, 'chars3 length is 6') + +console.assert(chars3[0] === 'a', 'chars3 at 0 is a') +console.assert(chars3[1] === 'b', 'chars3 at 1 is b') +console.assert(chars3[2] === 'c', 'chars3 at 2 is c') +console.assert(chars3[3] === 'd', 'chars3 at 3 is d') +console.assert(chars3[4] === 'e', 'chars3 at 4 is e') +console.assert(chars3[5] === 'f', 'chars3 at 3 is f') + + +console.info('CASE concat elements from 5 arrays') + + +var nums1 = [10, 20, 30] +var nums2 = [400, 500] +var nums3 = [-60, -70] +var nums4 = [800, 900] +var nums5 = [-1000] + +var nums6 = nums1.concat(nums2, nums3, nums4, nums5) + +console.assert(nums6.length === 10, 'nums6 length is 10') + +console.assert(nums6[0] === 10, 'nums6 at 0 is 10') +console.assert(nums6[1] === 20, 'nums6 at 1 is 20') +console.assert(nums6[2] === 30, 'nums6 at 2 is 30') +console.assert(nums6[3] === 400, 'nums6 at 3 is 400') +console.assert(nums6[4] === 500, 'nums6 at 4 is 500') +console.assert(nums6[5] === -60, 'nums6 at 5 is -60') +console.assert(nums6[6] === -70, 'nums6 at 6 is -70') +console.assert(nums6[7] === 800, 'nums6 at 7 is 800') +console.assert(nums6[8] === 900, 'nums6 at 8 is 900') +console.assert(nums6[9] === -1000, 'nums6 at 9 is -1000') diff --git a/staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js b/staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js new file mode 100644 index 000000000..f6ba98c59 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js @@ -0,0 +1,42 @@ +console.info('TEST Array.prototype.copyWithin') + +console.info('CASE copyWithin 3 parametres and target> start in array') + +var animals = ['Dodo', 'Tiger', 'Pengui', 'Leo', 'Elephant'] + +var animals2 = animals.copyWithin(3, 1, 2) + +console.assert(animals2[0] === 'Dodo', 'animals2 at 0 is Dodo') +console.assert(animals2[1] === 'Tiger', 'animals2 at 1 is Tiger') +console.assert(animals2[2] === 'Pengui', 'animals2 at 2 is Pengui') +console.assert(animals2[3] === 'Tiger', 'animals2 at 3 is Tiger') +console.assert(animals2[4] === 'Elephant', 'animals2 at 4 is Elephant') +console.assert(animals2.length === 5, 'animals2 length is 5') + +console.info('CASE copyWithin 2 parametres and target> start in array') + +var animals = ['Dodo', 'Tiger', 'Pengui', 'Leo', 'Elephant'] + +var animals2 = animals.copyWithin(3, 1) + +console.assert(animals2[0] === 'Dodo', 'animals2 at 0 is Dodo') +console.assert(animals2[1] === 'Tiger', 'animals2 at 1 is Tiger') +console.assert(animals2[2] === 'Pengui', 'animals2 at 2 is Pengui') +console.assert(animals2[3] === 'Tiger', 'animals2 at 3 is Tiger') +console.assert(animals2[4] === 'Pengui', 'animals2 at 4 is Elephant') +console.assert(animals2.length === 5, 'animals2 length is 5') + + +var animals3 = ['Dodo', 'Tiger', 'Pengui', 'Leo', 'Elephant'] + + +console.info('CASE copyWithin 3 parameters and target = 0 in Array') + +var animals4 = animals3.copyWithin(0, 1, 4) + +console.assert(animals4[0] === 'Tiger', 'animals4 at 0 is Tiger') +console.assert(animals4[1] === 'Pengui', 'animals4 at 1 is Pengui') +console.assert(animals4[2] === 'Leo', 'animals4 at 2 is Dodo') +console.assert(animals4[3] === 'Leo', 'animals4 at 3 is Dodo') +console.assert(animals4[4] === 'Elephant', 'animals4 at 4 is Elephant') +console.assert(animals4.length === 5, 'animals4 length is 5') diff --git a/staff/lucas-orts/playground/Array/Array.prototype.every.test.js b/staff/lucas-orts/playground/Array/Array.prototype.every.test.js new file mode 100644 index 000000000..72fc1434f --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.every.test.js @@ -0,0 +1,29 @@ +console.info('TEST Array.prototype.every') + +console.info('CASE every true in Array') + +var numeros = [1, 30, 39, 29, 10, 13] + +var isBelowThreshold = function (currentValue) { + + return currentValue < 40 + +} + +var numeros1 = numeros.every(isBelowThreshold) + +console.assert(numeros1 === true, 'isBelowThreshold is true') + + +console.info('CASE every false in Array') + +var isBelowThreshold1 = function (currentValue) { + + return currentValue < 30 + +} + +var numeros2 = numeros.every(isBelowThreshold1) + + +console.assert(numeros2 === false, 'isBelowThreshold1 is false') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.filter.test.js b/staff/lucas-orts/playground/Array/Array.prototype.filter.test.js new file mode 100644 index 000000000..52531196d --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.filter.test.js @@ -0,0 +1,12 @@ +console.info('TEST Array.prototype.filter') + +console.info('CASE filter word.length > 6 in Array') + +var words = new Curray['spray', 'elite', 'exuberant', 'destruction', 'present'] + +var result = words.filter((word) => word.length > 6) + +console.assert(result[0] === 'exuberant', 'rsult at 0 is exuberant') +console.assert(result[1] === 'destruction', 'rsult at 1 is destruction') +console.assert(result[2] === 'present', 'rsult at 2 is present') +console.assert(result.length === 3, 'result length is 3') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.find.test.js b/staff/lucas-orts/playground/Array/Array.prototype.find.test.js new file mode 100644 index 000000000..cb3d45bf2 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.find.test.js @@ -0,0 +1,9 @@ +console.info('TEST Array.prototype.find') + +console.info('CASE find in array') + +var numbers = [5, 12, 8, 130, 44] + +var found = numbers.find((element) => element > 10) + +console.assert(found === 12, 'found is 12') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js b/staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js new file mode 100644 index 000000000..cf6bf0374 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js @@ -0,0 +1,67 @@ +console.info('TEST Array.prototype.forEach') + +console.info('CASE copy chars into new array') + +var chars = ['a', 'b', 'c'] +var copy = [] + +chars.forEach(function (element) { + copy[copy.length] = element +}) + +console.assert(copy.length === chars.length, 'copy length equals chars length') +console.assert(copy[0] === chars[0], 'copy at 0 equals chars at 0') +console.assert(copy[1] === chars[1], 'copy at 1 equals chars at 1') +console.assert(copy[2] === chars[2], 'copy at 2 equals chars at 2') + +console.info('CASE copy chars with index and self-reference into new array') + +var chars = ['a', 'b', 'c'] +var copy = [] + +var indexes = [] +var arrays = [] + +chars.forEach(function (element, index, array) { + copy[copy.length] = element + indexes[indexes.length] = index + arrays[arrays.length] = array +}) + +console.assert(copy.length === chars.length, 'copy length equals chars length') + +console.assert(copy[0] === chars[0], 'copy at 0 equals chars at 0') +console.assert(indexes[0] === 0, 'indexes at 0 equals 0') +console.assert(arrays[0] === chars, 'arrays at 0 equals chars') + +console.assert(copy[1] === chars[1], 'copy at 1 equals chars at 1') +console.assert(indexes[1] === 1, 'indexes at 1 equals 1') +console.assert(arrays[1] === chars, 'arrays at 1 equals chars') + +console.assert(copy[2] === chars[2], 'copy at 2 equals chars at 2') +console.assert(indexes[2] === 2, 'indexes at 2 equals 2') +console.assert(arrays[2] === chars, 'arrays at 2 equals chars') + +console.info('CASE calculate percentages') + +var amounts = [100, 50, 4, 450, 100, 2000] +var results = [] + +amounts.forEach(function (amount, index, amounts) { + var total = 0 + + amounts.forEach(function (amount) { + total += amount + }) + + results[index] = amount / total * 100 +}) + +console.assert(results.length === amounts.length, 'results length equals amounts length') + +console.assert(results[0] === 3.698224852071006, 'results at 0 is 3.698224852071006') +console.assert(results[1] === 1.849112426035503, 'results at 1 is 1.849112426035503') +console.assert(results[2] === 0.14792899408284024, 'results at 2 is 0.14792899408284024') +console.assert(results[3] === 16.642011834319526, 'results at 3 is 16.642011834319526') +console.assert(results[4] === 3.698224852071006, 'results at 4 is 3.698224852071006') +console.assert(results[5] === 73.96449704142012, 'results at 5 is 73.96449704142012') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.includes.test.js b/staff/lucas-orts/playground/Array/Array.prototype.includes.test.js new file mode 100644 index 000000000..a050f3666 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.includes.test.js @@ -0,0 +1,28 @@ +console.info('TEST Array.prototype.includes') + +console.info('CASE includes in array') + +var numeros = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] + +var numeros1 = numeros.includes(6) + +var numeros2 = numeros.includes(50) + +console.assert(numeros1 === true, 'numeros1 includes 6') +console.assert(numeros2 === false, 'numeros2 do not includes 50') + +console.info('TEST array includes color from index') + +var colors = ['red', 'green', 'blue', 'yellow', 'orange', 'pink', 'skyblue', 'red', 'white', 'black', 'grey'] + +var included = colors.includes('pink', 2) + +console.assert(included === true, 'included includes pink') + +var included = colors.includes('red', 4) + +console.assert(included === true, 'included includes red') + +var included = colors.includes('red', 8) + +console.assert(included === false, 'included does not include red') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js b/staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js new file mode 100644 index 000000000..61b05ca6f --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js @@ -0,0 +1,19 @@ +console.info('TEST Array.prototype.indexOf') + +console.info('CASE indexOf in array') + +var animals = ['ant', 'bison', 'camel', 'duck', 'bison'] + +var animals1 = animals.indexOf('ant') +var animals2 = animals.indexOf('bison') +var animals3 = animals.indexOf('camel', 1) +var animals4 = animals.indexOf('giraffa') +var animals5 = animals.indexOf('ant', -5) +var animals6 = animals.indexOf('bison', 2) + +console.assert(animals1 === 0, 'animals1 is 0') +console.assert(animals2 === 1, 'animals2 is 1') +console.assert(animals3 === 2, 'animals3 is 2') +console.assert(animals4 === -1, 'animals4 is -1') +console.assert(animals5 === 0, 'animals5 is 0') +console.assert(animals6 === 4, 'animals6 is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.join.test.js b/staff/lucas-orts/playground/Array/Array.prototype.join.test.js new file mode 100644 index 000000000..279c34121 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.join.test.js @@ -0,0 +1,38 @@ +console.info('TEST Array.prototype.join') + +console.info('CASE join in array') + +var animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo', 'Elephant'] + +console.assert(animals[0] === 'Dodo', 'animal at 0 is Dodo') +console.assert(animals[1] === 'Tiger', 'animal at 1 is Tiger') +console.assert(animals[2] === 'Penguin', 'animal at 2 is Penguin') +console.assert(animals[3] === 'Dodo', 'animal at 3 is Dodo') +console.assert(animals[4] === 'Elephant', 'animal at 4 is Elephant') +console.assert(animals.length === 5, 'animals length is 5') + +var animals2 = animals.join() +var animals22 = 'Dodo,Tiger,Penguin,Dodo,Elephant' + +console.assert(animals2 === animals22, 'animals2 is equal to animals22') + + +var animals3 = animals.join(" + ") +var animals33 = 'Dodo + Tiger + Penguin + Dodo + Elephant' + +console.assert(animals3 === animals33, 'animals3 ie equal to animals33') + +var animals4 = animals.join("/") +var animals44 = 'Dodo/Tiger/Penguin/Dodo/Elephant' + +console.assert(animals4 === animals44, 'animals4 is equal to animals44') + + +console.info('CASE join elements with separator $') + +var things = [true, 'hello world', 100, { name: 'Oswald' }, [10, 20, 30], function () { }] + +var joined = things.join(' $ ') +var joined1 = 'true $ hello world $ 100 $ [object Object] $ 10,20,30 $ function () { }' + +console.assert(joined === joined1, 'joined is equal to joined1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js b/staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js new file mode 100644 index 000000000..4010d8440 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js @@ -0,0 +1,17 @@ +console.info('TEST Array.prototype.lastIndexOf') + +console.info('CASE lastIndexOf in array') + +var animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo', 'Elephant'] + +var animals1 = animals.lastIndexOf('Penguin') +var animals2 = animals.lastIndexOf('Dodo') +var animals3 = animals.lastIndexOf('Dodo', 1) +var animals4 = animals.lastIndexOf('Giraffa') +var animals5 = animals.lastIndexOf('Tiger', -4) + +console.assert(animals1 === 2, 'animals1 is 2') +console.assert(animals2 === 3, 'animals2 is 3') +console.assert(animals3 === 0, 'animals3 is 0') +console.assert(animals4 === -1, 'animals4 is -1') +console.assert(animals5 === 1, 'animals5 is 1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.map.test.js b/staff/lucas-orts/playground/Array/Array.prototype.map.test.js new file mode 100644 index 000000000..0ec658aa4 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.map.test.js @@ -0,0 +1,13 @@ +console.info('TEST Array.prototype.map') + +console.info('CASE map in array') + +var numeros = [1, 4, 9, 16] + +var map1 = numeros.map((x) => x * 2) + +console.assert(map1[0] === 2, 'map1 at 0 is 2') +console.assert(map1[1] === 8, 'map1 at 1 is 8') +console.assert(map1[2] === 18, 'map1 at 2 is 18') +console.assert(map1[3] === 32, 'map1 at 3 is 32') +console.assert(map1.length === 4, 'map1 length is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.pop.test.js b/staff/lucas-orts/playground/Array/Array.prototype.pop.test.js new file mode 100644 index 000000000..090484a95 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.pop.test.js @@ -0,0 +1,32 @@ +console.info('TEST pop') + +console.info('CASE pop the last element from array') + +var cars = new Array + +cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } +cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } +cars[2] = { brand: 'fiat', model: '500', year: 2017 } + +var car0 = cars[0] +var car1 = cars[1] +var car2 = cars[2] + +var last = cars.pop() + +console.assert(cars.length === 2, 'cars length is 2') + +console.assert(cars[0] === car0, 'cars at 0 is car0') +console.assert(cars[0].brand === 'ferrari', 'cars at 0 brand is ferrari') +console.assert(cars[0].model === 'gto', 'cars at 0 model is gto') +console.assert(cars[0].year === 1990, 'cars at 0 year is 1990') + +console.assert(cars[1] === car1, 'cars at 1 is car1') +console.assert(cars[1].brand === 'lamborghini', 'cars at 1 brand is lamborghini') +console.assert(cars[1].model === 'murcielago', 'cars at 1 model is murcielago') +console.assert(cars[1].year === 2010, 'cars at 1 year is 2010') + +console.assert(last === car2, 'last is car2') +console.assert(last.brand === 'fiat', 'last brand is fiat') +console.assert(last.model === '500', 'last model is 500') +console.assert(last.year === 2017, 'last year is 2017') diff --git a/staff/lucas-orts/playground/Array/Array.prototype.push.test.js b/staff/lucas-orts/playground/Array/Array.prototype.push.test.js new file mode 100644 index 000000000..6015b18dd --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.prototype.push.test.js @@ -0,0 +1,27 @@ +console.info('TEST push') + +console.info('CASE push an element to array') + +var cars = new Array + +cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } +cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } +cars[2] = { brand: 'fiat', model: '500', year: 2017 } + +var newCar = { brand: 'ford', model: 'fiesta', year: 2005 } +var count = cars.push(newCar) + +console.assert(cars[3] === newCar, 'cars at 4 is newCar') +console.assert(cars.length === 4, 'cars length is 4') +console.assert(count === 4, 'count is 4') + +console.info('CASE push multiple elements to array') + +var animals = ['pigs', 'goats', 'sheep', 'cows'] +var count = animals.push('chickens', 'cats', 'dogs') + +console.assert(animals[4] === 'chickens', 'animals at 4 is chickens') +console.assert(animals[5] === 'cats', 'animals at 5 is cats') +console.assert(animals[6] === 'dogs', 'animals at 6 is dogs') +console.assert(animals.length === 7, 'animals length is 7') +console.assert(count === 7, 'count is 7') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.test.js b/staff/lucas-orts/playground/Array/Array.test.js new file mode 100644 index 000000000..711437a51 --- /dev/null +++ b/staff/lucas-orts/playground/Array/Array.test.js @@ -0,0 +1,46 @@ +console.info('TEST constructor') + +console.info('CASE builds a new instance of Array') + +var a = new Array // new Array() // [] + +console.assert(a instanceof Array, 'a is an Array') +console.assert(a instanceof Object, 'a is an Object') + + +console.info('CASE builds a new Array with values') + +var a = new Array(10, 20, 30) // [10, 20, 30] + +console.assert(a instanceof Array, 'a is an Array') +console.assert(a[0] === 10, 'a at 0 is 10') +console.assert(a[1] === 20, 'a at 1 is 20') +console.assert(a[2] === 30, 'a at 2 is 30') +console.assert(a.length === 3, 'a length is 3') + + +console.info('CASE builds a new Array with only one numeric argument') + +var a = new Array(10) + +console.assert(a instanceof Array, 'a is an Array') +console.assert(a.length === 10, 'a length is 10') + + +console.info('CASE builds a new Array with only one non-numeric argument') + +var a = new Array('hola mundo') + +console.assert(a instanceof Array, 'a is an Array') +console.assert(a[0] === 'hola mundo', 'a at 0 is hola mundo') +console.assert(a.length === 1, 'a length is 1') + + +console.info('CASE builds a new Array with two values') + +var a = new Array(10, 20) + +console.assert(a instanceof Array, 'a is an Array') +console.assert(a[0] === 10, 'a at 0 is 10') +console.assert(a[1] === 20, 'a at 1 is 20') +console.assert(a.length === 2, 'a length is 2') From e6efa13e2b82a1b5b6d8c6a641c27d420490f52b Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Sun, 9 Jun 2024 21:53:10 +0200 Subject: [PATCH 07/21] implement Curray and prototypes until push #27 --- staff/lucas-orts/playground/Curray/Curray.js | 15 +++++ .../playground/Curray/Curray.prototype.at.js | 10 ++++ .../Curray/Curray.prototype.at.test.js | 43 ++++++++++++++ .../Curray/Curray.prototype.concat.js | 29 +++++++++ .../Curray/Curray.prototype.concat.test.js | 44 ++++++++++++++ .../Curray/Curray.prototype.copyWithin.js | 45 ++++++++++++++ .../Curray.prototype.copyWithin.test.js | 59 +++++++++++++++++++ .../Curray/Curray.prototype.every.js | 16 +++++ .../Curray/Curray.prototype.every.test.js | 33 +++++++++++ .../Curray/Curray.prototype.filter.js | 18 ++++++ .../Curray/Curray.prototype.filter.test.js | 16 +++++ .../Curray/Curray.prototype.find.js | 15 +++++ .../Curray/Curray.prototype.find.test.js | 18 ++++++ .../Curray/Curray.prototype.forEach.js | 11 ++++ .../Curray/Curray.prototype.forEach.test.js | 19 ++++++ .../Curray/Curray.prototype.includes.js | 0 .../Curray/Curray.prototype.includes.test.js | 59 +++++++++++++++++++ .../Curray/Curray.prototype.indexOf.js | 24 ++++++++ .../Curray/Curray.prototype.indexOf.test.js | 30 ++++++++++ .../Curray/Curray.prototype.join.js | 20 +++++++ .../Curray/Curray.prototype.join.test.js | 48 +++++++++++++++ .../Curray/Curray.prototype.lastIndexOf.js | 17 ++++++ .../Curray.prototype.lastIndexOf.test.js | 21 +++++++ .../playground/Curray/Curray.prototype.map.js | 14 +++++ .../Curray/Curray.prototype.map.test.js | 17 ++++++ .../playground/Curray/Curray.prototype.pop.js | 9 +++ .../Curray/Curray.prototype.pop.test.js | 36 +++++++++++ .../Curray/Curray.prototype.push.js | 11 ++++ .../Curray/Curray.prototype.push.test.js | 32 ++++++++++ .../playground/Curray/Curray.test.js | 40 +++++++++++++ 30 files changed, 769 insertions(+) create mode 100644 staff/lucas-orts/playground/Curray/Curray.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.at.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.concat.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.every.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.filter.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.find.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.includes.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.join.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.map.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.pop.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.push.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js create mode 100644 staff/lucas-orts/playground/Curray/Curray.test.js diff --git a/staff/lucas-orts/playground/Curray/Curray.js b/staff/lucas-orts/playground/Curray/Curray.js new file mode 100644 index 000000000..e4c822f6c --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.js @@ -0,0 +1,15 @@ +function Curray() { + if (arguments.length === 1 && typeof arguments[0] === 'number') { + this.length = arguments[0] + } + else { + for (var i = 0; i < arguments.length; i++) { + var argument = arguments[i] + this[i] = argument + } + + this.length = arguments.length + } + +} +module.exports = Curray \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.at.js b/staff/lucas-orts/playground/Curray/Curray.prototype.at.js new file mode 100644 index 000000000..828586098 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.at.js @@ -0,0 +1,10 @@ +var Curray = require('./Curray') + +Curray.prototype.at = function (index) { + if (index > -1) { + return this[index] + } + else { + return this[this.length + index] + } +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js new file mode 100644 index 000000000..8ada1b0bb --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js @@ -0,0 +1,43 @@ +var Curray = require('./Curray') +require('./Curray.prototype.at') + +console.info('Test Curray.prototype.at') + +console.info('CASE element a positive index') + +var nums = new Curray(5, 12, 8, 130, 44) +var num = nums.at(3) + +console.assert(num === 130, 'num is 130') + + +console.info('CASE element at index 0') + +var nums = new Curray(5, 12, 8, 130, 44) +var num = nums.at(0) + +console.assert(num === 5, 'num is 5') + + +console.info('CASE element a negative index') + +var nums = new Curray(5, 12, 8, 130, 44) +var num = nums.at(-3) + +console.assert(num === 8, 'num is 8') + + +console.info('CASE element a positive index greater than length') + +var num = new Curray(5, 12, 8, 130, 44) +var num = nums.at(100) + +console.assert(num === undefined, 'num is undefined') + + +console.info('CASE element a negative index greater than -length') + +var num = new Curray(5, 12, 8, 130, 44) +var num = nums.at(-100) + +console.assert(num === undefined, 'num is undefined') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.concat.js b/staff/lucas-orts/playground/Curray/Curray.prototype.concat.js new file mode 100644 index 000000000..74b8e4d03 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.concat.js @@ -0,0 +1,29 @@ +var Curray = require('./Curray') + +Curray.prototype.concat = function () { + + var newObject = { length: 0 } + + for (var i = 0; i < this.length; i++) { + var elem = this[i] + + newObject[newObject.length++] = elem + } + + for (var i = 0; i < arguments.length; i++) { + + var argument = arguments[i] + + for (var j = 0; j < argument.length; j++) { + + var elem = argument[j] + + newObject[newObject.length++] = elem + + } + + } + + return newObject + +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js new file mode 100644 index 000000000..722199346 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js @@ -0,0 +1,44 @@ +var Curray = require('./Curray') +require('./Curray.prototype.concat') + +console.info('TEST Curray.prototype.concat') + +console.info('CASE concat elements from two Currays') + +var chars1 = new Curray('a', 'b', 'c') +var chars2 = new Curray('d', 'e', 'f') + +var chars3 = chars1.concat(chars2) + +console.assert(chars3.length === 6, 'chars3 length is 6') + +console.assert(chars3[0] === 'a', 'chars3 at 0 is a') +console.assert(chars3[1] === 'b', 'chars3 at 1 is b') +console.assert(chars3[2] === 'c', 'chars3 at 2 is c') +console.assert(chars3[3] === 'd', 'chars3 at 3 is d') +console.assert(chars3[4] === 'e', 'chars3 at 4 is e') +console.assert(chars3[5] === 'f', 'chars3 at 3 is f') + + +console.info('CASE concat elements from 5 Currays') + +var nums1 = new Curray(10, 20, 30) +var nums2 = new Curray(400, 500) +var nums3 = new Curray(-60, -70) +var nums4 = new Curray(800, 900) +var nums5 = new Curray("-1000") + +var nums6 = nums1.concat(nums2, nums3, nums4, nums5) + +console.assert(nums6.length === 10, 'nums6 length is 10') + +console.assert(nums6[0] === 10, 'nums6 at 0 is 10') +console.assert(nums6[1] === 20, 'nums6 at 1 is 20') +console.assert(nums6[2] === 30, 'nums6 at 2 is 30') +console.assert(nums6[3] === 400, 'nums6 at 3 is 400') +console.assert(nums6[4] === 500, 'nums6 at 4 is 500') +console.assert(nums6[5] === -60, 'nums6 at 5 is -60') +console.assert(nums6[6] === -70, 'nums6 at 6 is -70') +console.assert(nums6[7] === 800, 'nums6 at 7 is 800') +console.assert(nums6[8] === 900, 'nums6 at 8 is 900') +console.assert(nums6[9] === "-1000", 'nums6 at 9 is -1000') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js b/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js new file mode 100644 index 000000000..7cdbc9ab6 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js @@ -0,0 +1,45 @@ +var Curray = require('./Curray') + +Curray.prototype.copyWithin = function (target, start, end) { + if (end === undefined || end > this.length) { + end = this.length + } + + else if (end < 0) { + end = this.length + end + } + + else if (end < -this.length) { + end = 0 + } + + if (start < 0) { + start = this.length + start + } + else if (start < -this.length) { + start = 0 + } + + if (end <= start) { + return this + } + + if (target < 0) { + target = this.length + target + } + + else if (target < -this.length) { + target = 0 + } + + else if (target > this.length) { + return this + } + + var temporal = target; + for (var i = start; i < end; i++) { + this[temporal] = this[i] + temporal++ + } + return this +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js new file mode 100644 index 000000000..d410267de --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js @@ -0,0 +1,59 @@ +var Curray = require('./Curray') +require('./Curray.prototype.copyWithin') + +console.info('TEST Curray.prototype.copyWithin') + +console.info('CASE copyWithin 3 parameters and target> start in Curray') + +var animals = new Curray + +animals[0] = 'Dodo' +animals[1] = 'Tiger' +animals[2] = 'Pengui' +animals[3] = 'Leo' +animals[4] = 'Elephant' +animals.length = 5 + +var animals2 = animals.copyWithin(3, 1, 2) + + +console.info('CASE copyWithin 2 parameters and target> start in Curray') + +var animals = new Curray + +animals[0] = 'Dodo' +animals[1] = 'Tiger' +animals[2] = 'Pengui' +animals[3] = 'Leo' +animals[4] = 'Elephant' +animals.length = 5 + +var animals2 = animals.copyWithin(3, 1) + +console.assert(animals2[0] === 'Dodo', 'animals2 at 0 is Dodo') +console.assert(animals2[1] === 'Tiger', 'animals2 at 1 is Tiger') +console.assert(animals2[2] === 'Pengui', 'animals2 at 2 is Pengui') +console.assert(animals2[3] === 'Tiger', 'animals2 at 3 is Tiger') +console.assert(animals2[4] === 'Pengui', 'animals2 at 4 is Elephant') +console.assert(animals2.length === 5, 'animals2 length is 5') + +var animals3 = new Curray + +animals3[0] = 'Dodo' +animals3[1] = 'Tiger' +animals3[2] = 'Pengui' +animals3[3] = 'Leo' +animals3[4] = 'Elephant' +animals3.length = 5 + + +console.info('CASE copyWithin 3 parameters and target = 0 in Curray') + +var animals4 = animals3.copyWithin(0, 1, 4) + +console.assert(animals4[0] === 'Tiger', 'animals4 at 0 is Tiger') +console.assert(animals4[1] === 'Pengui', 'animals4 at 1 is Pengui') +console.assert(animals4[2] === 'Leo', 'animals4 at 2 is Dodo') +console.assert(animals4[3] === 'Leo', 'animals4 at 3 is Dodo') +console.assert(animals4[4] === 'Elephant', 'animals4 at 4 is Elephant') +console.assert(animals4.length === 5, 'animals4 length is 5') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.every.js b/staff/lucas-orts/playground/Curray/Curray.prototype.every.js new file mode 100644 index 000000000..6236db6f7 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.every.js @@ -0,0 +1,16 @@ +var Curray = require('./Curray') + +Curray.prototype.every = function (callback) { + + for (var i = 0; i < this.length; i++) { + + // if (callback(this[i]) === false) + if (!callback(this[i])) { + return false + } + + } + + return true + +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js new file mode 100644 index 000000000..4207fed01 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js @@ -0,0 +1,33 @@ +var Curray = require('./Curray') +require('./Curray.prototype.every') + + +console.info('TEST Curray.prototype.every') + +console.info('CASE every true in Curray') + +var numeros = new Curray(1, 30, 39, 29, 10, 13) + +var isBelowThreshold = function (currentValue) { + + return currentValue < 40 + +} + +var numeros1 = numeros.every(isBelowThreshold) + +console.assert(numeros1 === true, 'isBelowThreshold is true') + + +console.info('CASE every false in Curray') + +var isBelowThreshold1 = function (currentValue) { + + return currentValue < 30 + +} + +var numeros2 = numeros.every(isBelowThreshold1) + + +console.assert(numeros2 === false, 'isBelowThreshold1 is false') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.filter.js b/staff/lucas-orts/playground/Curray/Curray.prototype.filter.js new file mode 100644 index 000000000..324fd5754 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.filter.js @@ -0,0 +1,18 @@ +var Curray = require('./Curray') + +Curray.prototype.filter = function (callbackFunction) { + var newObject = new Curray + + for (var i = 0; i < this.length; i++) { + + if (callbackFunction(this[i], i, this)) { + + newObject[newObject.length++] = this[i] + + } + + } + + return newObject + +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js new file mode 100644 index 000000000..1218408be --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js @@ -0,0 +1,16 @@ +var Curray = require('./Curray') +require('./Curray.prototype.filter') + + +console.info('TEST Curray.prototype.filter') + +console.info('CASE filter word.length > 6 in Curray') + +var words = new Curray('spray', 'elite', 'exuberant', 'destruction', 'present') + +var result = words.filter((word) => word.length > 6) + +console.assert(result[0] === 'exuberant', 'rsult at 0 is exuberant') +console.assert(result[1] === 'destruction', 'rsult at 1 is destruction') +console.assert(result[2] === 'present', 'rsult at 2 is present') +console.assert(result.length === 3, 'result length is 3') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.find.js b/staff/lucas-orts/playground/Curray/Curray.prototype.find.js new file mode 100644 index 000000000..723f8ca0a --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.find.js @@ -0,0 +1,15 @@ +var Curray = require('./Curray') + +Curray.prototype.find = function (callbackFunction) { + + for (var i = 0; i < this.length; i++) { + + if (callbackFunction(this[i], i, this)) + + return this[i] + + } + + return undefined + +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js new file mode 100644 index 000000000..b2549c56a --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js @@ -0,0 +1,18 @@ +var Curray = require('./Curray') +require('./Curray.prototype.find') + + +console.info('TEST Curray.prototype.find') + +console.info('CASE find in curray') + +var numbers = new Curray(5, 12, 8, 130, 44) + +var found = numbers.find((element) => element > 10) +console.assert(found === 12, 'found is 12') + +var found = numbers.find((element) => element > 100) +console.assert(found === 130, 'found is 130') + +var found = numbers.find((element) => element > 130) +console.assert(found === undefined, 'found is undefined') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js b/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js new file mode 100644 index 000000000..06753ed36 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js @@ -0,0 +1,11 @@ +var Curray = ('./Curray') + +Curray.prototype.forEach = function (callback) { + for (var i = 0; i < this.length; i++) { + var elem = this[i] + + callback(elem) + + // callback(this[i]) + } +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js new file mode 100644 index 000000000..0af04c1eb --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js @@ -0,0 +1,19 @@ +var Curray = require('./Curray') +require('./Curray.prototype.forEach') + +onsole.info('TEST Array.prototype.forEach') + +console.info('CASE forEach in array') + +var chars = new Curray('a', 'b', 'c') +var copy = new Curray + +var chars1 = chars.forEach(function (element) { + copy[copy.length] = element + +}) + +console.assert(copy.length === chars1.length, 'copy length equals chars length') +console.assert(copy[0] === chars1[0], 'copy at 0 equals at 0') +console.assert(copy[1] === chars1[1], 'copy at 1 equals at 1') +console.assert(copy[2] === chars1[2], 'copy at 2 equals at 2') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.includes.js b/staff/lucas-orts/playground/Curray/Curray.prototype.includes.js new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js new file mode 100644 index 000000000..9cd83c555 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js @@ -0,0 +1,59 @@ +var Curray = require('./Curray') +require('./Curray.prototype.includes') + +console.info('TEST Curray.prototype.includes') + +console.info('CASE includes in Curray') + +var numeros = new Curray + +numeros[0] = 1 +numeros[1] = 2 +numeros[2] = 3 +numeros[3] = 4 +numeros[4] = 5 +numeros[5] = 6 +numeros[6] = 7 +numeros[7] = 8 +numeros[8] = 9 +numeros[9] = 10 +numeros.length = 10 + +var numeros1 = numeros.includes(6) + +var numeros2 = numeros.includes(50) + +console.assert(numeros1 === true, 'numeros1 includes 6') +console.assert(numeros2 === false, 'numeros2 do not includes 50') + + +console.info('TEST Curray includes color from index') + +var colors = new Curray + +colors[0] = 'red' +colors[1] = 'green' +colors[2] = 'blue' +colors[3] = 'yellow' +colors[4] = 'orange' +colors[5] = 'pink' +colors[6] = 'skyblue' +colors[7] = 'red' +colors[8] = 'white' +colors[9] = 'black' +colors[10] = 'grey' +colors.length = 11 + +var colors = ['red', 'green', 'blue', 'yellow', 'orange', 'pink', 'skyblue', 'red', 'white', 'black', 'grey'] + +var included = colors.includes('pink', 2) + +console.assert(included === true, 'included includes pink') + +var included = colors.includes('red', 4) + +console.assert(included === true, 'included includes red') + +var included = colors.includes('red', 8) + +console.assert(included === false, 'included does not include red') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js b/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js new file mode 100644 index 000000000..983a3862b --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js @@ -0,0 +1,24 @@ +var Curray = require('./Curray') + +Curray.prototype.indexOf = function (searchElement, fromIndex) { + + if (fromIndex === undefined) + fromIndex = 0 + + else if (fromIndex < 0) { + fromIndex = this.length + fromIndex + + if (fromIndex < 0) + fromIndex = 0 + } + + for (var i = fromIndex; i < this.length; i++) { + var element = this[i] + + if (searchElement === element) + return i + } + + return -1 + +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js new file mode 100644 index 000000000..8dbb8ced0 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js @@ -0,0 +1,30 @@ +var Curray = require('./Curray') +require('./Curray.prototype.indexOf') + + +console.info('TEST Curray.prototype.indexOf') + +console.info('CASE indexOf in Curray') + +var animals = new Curray + +animals[0] = 'ant' +animals[1] = 'bison' +animals[2] = 'camel' +animals[3] = 'duck' +animals[4] = 'bison' +animals.length = 5 + +var animals1 = animals.indexOf('ant') +var animals2 = animals.indexOf('bison') +var animals3 = animals.indexOf('camel', 1) +var animals4 = animals.indexOf('giraffa') +var animals5 = animals.indexOf('ant', -5) +var animals6 = animals.indexOf('bison', 2) + +console.assert(animals1 === 0, 'animals1 is 0') +console.assert(animals2 === 1, 'animals2 is 1') +console.assert(animals3 === 2, 'animals3 is 2') +console.assert(animals4 === -1, 'animals4 is -1') +console.assert(animals5 === 0, 'animals5 is 0') +console.assert(animals6 === 4, 'animals6 is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.join.js b/staff/lucas-orts/playground/Curray/Curray.prototype.join.js new file mode 100644 index 000000000..16a6b4597 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.join.js @@ -0,0 +1,20 @@ +var Curray = require('./Curray') + +Curray.prototype.join = function (separator) { + if (separator === undefined) + separator = ',' + + var res = "" + + for (var i = 0; i < this.length; i++) { + var elem = this[i] + + res += elem + + if (i < this.length - 1) + res += separator + + } + + return res +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js new file mode 100644 index 000000000..a68e79d7a --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js @@ -0,0 +1,48 @@ +var Curray = require('./Curray') +require('./Curray.prototype.join') + +console.info('TEST Curray.prototype.join') + +console.info('CASE join in Curray') + +var animals = new Curray + +animals[0] = 'Dodo' +animals[1] = 'Tiger' +animals[2] = 'Penguin' +animals[3] = 'Dodo' +animals[4] = 'Elephant' +animals.length = 5 + +var animals2 = animals.join() +var animals22 = 'Dodo,Tiger,Penguin,Dodo,Elephant' + +console.assert(animals2 === animals22, 'animals2 is equal to animals22') + +var animals3 = animals.join(" + ") +var animals33 = 'Dodo + Tiger + Penguin + Dodo + Elephant' + +console.assert(animals3 === animals33, 'animals3 ie equal to animals33') + +var animals4 = animals.join("/") +var animals44 = 'Dodo/Tiger/Penguin/Dodo/Elephant' + +console.assert(animals4 === animals44, 'animals4 is equal to animals44') + + +console.info('CASE join elements with separator $') + +var things = new Curray + +things[0] = true +things[1] = 'hello world' +things[2] = 100 +things[3] = { name: 'Oswald' } +things[4] = [10, 20, 30] +things[5] = function () { } +things.length = 6 + +var joined = things.join(' $ ') +var joined1 = 'true $ hello world $ 100 $ [object Object] $ 10,20,30 $ function () { }' + +console.assert(joined === joined1, 'joined is equal to joined1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js b/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js new file mode 100644 index 000000000..b3d49f22f --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js @@ -0,0 +1,17 @@ +var Curray = require('./Curray') + +Curray.prototype.lastIndexOf = function (searchElement, fromIndex) { + + if (fromIndex === undefined) + fromIndex = this.length - 1 + + else if (fromIndex < 0) + fromIndex = this.length + fromIndex + + for (var i = fromIndex; i > -1; i--) { + var element = this[i] + if (searchElement === element) + return i + } + return -1 +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js new file mode 100644 index 000000000..dc21e5c9f --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js @@ -0,0 +1,21 @@ +var Curray = require('./Curray') +require('./Curray.prototype.lastIndexOf') + + +console.info('TEST Curray.prototype.lastIndexOf') + +console.info('CASE lastIndexOf in array') + +var animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo', 'Elephant'] + +var animals1 = animals.lastIndexOf('Penguin') +var animals2 = animals.lastIndexOf('Dodo') +var animals3 = animals.lastIndexOf('Dodo', 1) +var animals4 = animals.lastIndexOf('Giraffa') +var animals5 = animals.lastIndexOf('Tiger', -4) + +console.assert(animals1 === 2, 'animals1 is 2') +console.assert(animals2 === 3, 'animals2 is 3') +console.assert(animals3 === 0, 'animals3 is 0') +console.assert(animals4 === -1, 'animals4 is -1') +console.assert(animals5 === 1, 'animals5 is 1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.map.js b/staff/lucas-orts/playground/Curray/Curray.prototype.map.js new file mode 100644 index 000000000..b0d0456d8 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.map.js @@ -0,0 +1,14 @@ +var Curray = require('./Curray') + +Curray.prototype.map = function (callbackFunction) { + var newObject = { length: 0 } + + for (var i = 0; i < this.length; i++) { + + newObject[newObject.length++] = callbackFunction(this[i], i, this) + + } + + return newObject + +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js new file mode 100644 index 000000000..0278efb5b --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js @@ -0,0 +1,17 @@ +var Curray = require('./Curray') +require('./Curray.prototype.map') + + +console.info('TEST Curray.prototype.map') + +console.info('CASE map in curray') + +var numeros = new Curray(1, 4, 9, 16) + +var map1 = numeros.map((x) => x * 2) + +console.assert(map1[0] === 2, 'map1 at 0 is 2') +console.assert(map1[1] === 8, 'map1 at 1 is 8') +console.assert(map1[2] === 18, 'map1 at 2 is 18') +console.assert(map1[3] === 32, 'map1 at 3 is 32') +console.assert(map1.length === 4, 'map1 length is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.pop.js b/staff/lucas-orts/playground/Curray/Curray.prototype.pop.js new file mode 100644 index 000000000..dff594266 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.pop.js @@ -0,0 +1,9 @@ +var Curray = require('./Curray') + +Curray.prototype.pop = function () { + var element = this[this.length - 1] + + delete this[--this.length] + + return element +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js new file mode 100644 index 000000000..206205ebd --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js @@ -0,0 +1,36 @@ +var Curray = require('./Curray') +require('./Curray.prototype.pop') + +console.info('TEST pop') + +console.info('CASE pop the last element from Curray') + +var cars = new Curray + +cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } +cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } +cars[2] = { brand: 'fiat', model: '500', year: 2017 } +cars.length = 3 + +var car0 = cars[0] +var car1 = cars[1] +var car2 = cars[2] + +var last = cars.pop() + +console.assert(cars.length === 2, 'cars length is 2') + +console.assert(cars[0] === car0, 'cars at 0 is car0') +console.assert(cars[0].brand === 'ferrari', 'cars at 0 brand is ferrari') +console.assert(cars[0].model === 'gto', 'cars at 0 model is gto') +console.assert(cars[0].year === 1990, 'cars at 0 year is 1990') + +console.assert(cars[1] === car1, 'cars at 1 is car1') +console.assert(cars[1].brand === 'lamborghini', 'cars at 1 brand is lamborghini') +console.assert(cars[1].model === 'murcielago', 'cars at 1 model is murcielago') +console.assert(cars[1].year === 2010, 'cars at 1 year is 2010') + +console.assert(last === car2, 'last is car2') +console.assert(last.brand === 'fiat', 'last brand is fiat') +console.assert(last.model === '500', 'last model is 500') +console.assert(last.year === 2017, 'last year is 2017') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.push.js b/staff/lucas-orts/playground/Curray/Curray.prototype.push.js new file mode 100644 index 000000000..a02671a50 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.push.js @@ -0,0 +1,11 @@ +var Curray = require('./Curray') + +Curray.prototype.push = function () { + for (var index = 0; index < arguments.length; index++) { + var argument = arguments[index] + + this[this.length++] = argument + } + + return this.length +} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js new file mode 100644 index 000000000..d1c37ad89 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js @@ -0,0 +1,32 @@ +var Curray = require('./Curray') +require('./Curray.prototype.push') + +console.info('TEST push') + +console.info('CASE push an element to Curray') + +var cars = new Curray + +cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } +cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } +cars[2] = { brand: 'fiat', model: '500', year: 2017 } +cars.length = 3 + +var newCar = { brand: 'ford', model: 'fiesta', year: 2005 } +var count = cars.push(newCar) + +console.assert(cars[3] === newCar, 'cars at 4 is newCar') +console.assert(cars.length === 4, 'cars length is 4') +console.assert(count === 4, 'count is 4') + + +console.info('CASE push multiple elements to Curray') + +var animals = new Curray('pigs', 'goats', 'sheep', 'cows') +var count = animals.push('chickens', 'cats', 'dogs') + +console.assert(animals[4] === 'chickens', 'animals at 4 is chickens') +console.assert(animals[5] === 'cats', 'animals at 5 is cats') +console.assert(animals[6] === 'dogs', 'animals at 6 is dogs') +console.assert(animals.length === 7, 'animals length is 7') +console.assert(count === 7, 'count is 7') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.test.js b/staff/lucas-orts/playground/Curray/Curray.test.js new file mode 100644 index 000000000..5dabb7962 --- /dev/null +++ b/staff/lucas-orts/playground/Curray/Curray.test.js @@ -0,0 +1,40 @@ +var Curray = require('./Curray') + +console.info('Test constructor') + +console.info('CASE builds a new instance of Curray') + +var c = new Curray // new Curray() + +console.assert(c instanceof Curray, 'c is a Curray') +console.assert(c instanceof Object, 'c is an Object') + + +console.info('CASE builds a new Curray with values') + +var c = new Curray(10, 20, 30) + +console.assert(c instanceof Curray, 'c is a Curray') +console.assert(c[0] === 10, 'c at 0 is 10') +console.assert(c[1] === 20, 'c at 1 is 20') +console.assert(c[2] === 30, 'c at 2 is 30') +console.assert(c.length === 3, 'c length is 3') + + +console.info('CASE builds a new Curray with only one numeric argument') + +var c = new Curray(10) + +console.assert(c instanceof Curray, 'c is a Curray') +console.assert(c.length == 10, 'c length is 10 ') + + +console.info('CASE builds a new Curray with only one non numeric argument') + +var c = new Curray('hola mundo') + +console.assert(c instanceof Curray, 'c is a Curray') +console.assert(c[0] === 'hola mundo', 'c at 0 is hola mundo') +console.assert(c.length === 1, 'c length is 1') + + From bc6b5f1f3a1321cb9924ed3f5de78d6bc7279a1c Mon Sep 17 00:00:00 2001 From: Lucas Orts Date: Mon, 10 Jun 2024 13:24:06 +0200 Subject: [PATCH 08/21] add ponies base code #60 --- staff/lucas-orts/ponies/app/home.html | 0 staff/lucas-orts/ponies/app/login.html | 0 staff/lucas-orts/ponies/app/register.html | 0 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 staff/lucas-orts/ponies/app/home.html create mode 100644 staff/lucas-orts/ponies/app/login.html create mode 100644 staff/lucas-orts/ponies/app/register.html diff --git a/staff/lucas-orts/ponies/app/home.html b/staff/lucas-orts/ponies/app/home.html new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/ponies/app/login.html b/staff/lucas-orts/ponies/app/login.html new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/ponies/app/register.html b/staff/lucas-orts/ponies/app/register.html new file mode 100644 index 000000000..e69de29bb From c41a71a5de9a0017d890295f664c04e987e4a039 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 16 Jun 2024 15:54:50 +0200 Subject: [PATCH 09/21] implement all ponies app until delete post #60 --- staff/lucas-orts/ponies/app/home.html | 0 .../lucas-orts/ponies/app/logic/createPost.js | 19 +++ .../lucas-orts/ponies/app/logic/deletePost.js | 14 ++ .../ponies/app/logic/getAllPosts.js | 5 + .../ponies/app/logic/getUserName.js | 13 ++ .../ponies/app/logic/getUserUsername.js | 3 + .../lucas-orts/ponies/app/logic/loginUser.js | 27 ++++ .../lucas-orts/ponies/app/logic/logoutUser.js | 3 + .../ponies/app/logic/registerUser.js | 59 ++++++++ staff/lucas-orts/ponies/app/login.html | 0 staff/lucas-orts/ponies/app/register.html | 0 .../lucas-orts/ponies/app/utils/formatTime.js | 41 ++++++ .../ponies/app/utils/generateRandomId.js | 3 + .../ponies/app/views/home/index.html | 32 +++++ .../lucas-orts/ponies/app/views/home/index.js | 135 ++++++++++++++++++ .../ponies/app/views/login/index.html | 33 +++++ .../ponies/app/views/login/index.js | 27 ++++ .../ponies/app/views/register/index.html | 45 ++++++ .../ponies/app/views/register/index.js | 37 +++++ 19 files changed, 496 insertions(+) delete mode 100644 staff/lucas-orts/ponies/app/home.html create mode 100644 staff/lucas-orts/ponies/app/logic/createPost.js create mode 100644 staff/lucas-orts/ponies/app/logic/deletePost.js create mode 100644 staff/lucas-orts/ponies/app/logic/getAllPosts.js create mode 100644 staff/lucas-orts/ponies/app/logic/getUserName.js create mode 100644 staff/lucas-orts/ponies/app/logic/getUserUsername.js create mode 100644 staff/lucas-orts/ponies/app/logic/loginUser.js create mode 100644 staff/lucas-orts/ponies/app/logic/logoutUser.js create mode 100644 staff/lucas-orts/ponies/app/logic/registerUser.js delete mode 100644 staff/lucas-orts/ponies/app/login.html delete mode 100644 staff/lucas-orts/ponies/app/register.html create mode 100644 staff/lucas-orts/ponies/app/utils/formatTime.js create mode 100644 staff/lucas-orts/ponies/app/utils/generateRandomId.js create mode 100644 staff/lucas-orts/ponies/app/views/home/index.html create mode 100644 staff/lucas-orts/ponies/app/views/home/index.js create mode 100644 staff/lucas-orts/ponies/app/views/login/index.html create mode 100644 staff/lucas-orts/ponies/app/views/login/index.js create mode 100644 staff/lucas-orts/ponies/app/views/register/index.html create mode 100644 staff/lucas-orts/ponies/app/views/register/index.js diff --git a/staff/lucas-orts/ponies/app/home.html b/staff/lucas-orts/ponies/app/home.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/ponies/app/logic/createPost.js b/staff/lucas-orts/ponies/app/logic/createPost.js new file mode 100644 index 000000000..8458c7a03 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/createPost.js @@ -0,0 +1,19 @@ +function createPost(image, caption) { + if (!image.startsWith('http')) { + throw new Error('invalid image') + } + + var posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + var post = { + image: image, + caption: caption, + author: sessionStorage.username, + date: new Date().toISOString(), + id: generateRandomId() + } + + posts.push(post) + + localStorage.posts = JSON.stringify(posts) +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/deletePost.js b/staff/lucas-orts/ponies/app/logic/deletePost.js new file mode 100644 index 000000000..4eda5ad83 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/deletePost.js @@ -0,0 +1,14 @@ +function deletePost(id) { + + var posts = getAllPosts() + var index = posts.findIndex(function (element) { + + return element.id === id + + }) + + posts.splice(index, 1) + + localStorage.posts = JSON.stringify(posts) + +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getAllPosts.js b/staff/lucas-orts/ponies/app/logic/getAllPosts.js new file mode 100644 index 000000000..fa27f6e8d --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getAllPosts.js @@ -0,0 +1,5 @@ +function getAllPosts() { + var posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + return posts.reverse() +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getUserName.js b/staff/lucas-orts/ponies/app/logic/getUserName.js new file mode 100644 index 000000000..3aec79a50 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getUserName.js @@ -0,0 +1,13 @@ +function getUserName() { + var users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + var user = users.find(function (user) { + return user.username === sessionStorage.username + }) + + if (user === undefined) { + throw new Error('user not found') + } + + return user.name +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getUserUsername.js b/staff/lucas-orts/ponies/app/logic/getUserUsername.js new file mode 100644 index 000000000..660002cf1 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getUserUsername.js @@ -0,0 +1,3 @@ +function getUserUsername() { + return sessionStorage.username +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/loginUser.js b/staff/lucas-orts/ponies/app/logic/loginUser.js new file mode 100644 index 000000000..ff8ebe07f --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/loginUser.js @@ -0,0 +1,27 @@ +var USER_REGEX = /^(?!.*\s{2})[a-zA-Z0-9._-]{4,16}$/ + +function loginUser(username, password) { + if (!USER_REGEX.test(username)) { + throw new Error('invalid username') + } + + if (password.trim().length < 8) { + throw new Error('invalid password') + } + + var users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + var user = users.find(function (user) { + return user.username === username + }) + + if (user === undefined) { + throw new Error('username does not exist') + } + + if (user.password !== password) { + throw new Error('wrong password') + } + + sessionStorage.username = username +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/logoutUser.js b/staff/lucas-orts/ponies/app/logic/logoutUser.js new file mode 100644 index 000000000..1307bfdaf --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/logoutUser.js @@ -0,0 +1,3 @@ +function logoutUser() { + delete sessionStorage.username +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/registerUser.js b/staff/lucas-orts/ponies/app/logic/registerUser.js new file mode 100644 index 000000000..3e1573fdb --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/registerUser.js @@ -0,0 +1,59 @@ +var EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/ +var NAME_REGEX = /^(?!.*\s{2})[a-zA-Z ]{3,16}$/ +var USER_REGEX = /^(?!.*\s{2})[a-zA-Z0-9._-]{4,16}$/ + +function registerUser(name, surname, email, username, password, passwordRepeat) { + if (!NAME_REGEX.test(name.trim())) { + throw new Error('invalid name') + } + + if (!NAME_REGEX.test(surname.trim())) { + throw new Error('ivalid surname') + } + + if (!EMAIL_REGEX.test(email)) { + throw new Error('invalid email') + } + + if (!USER_REGEX.test(username)) { + throw new Error('invalid username') + } + + if (password.trim().length < 8) { + throw new Error('invalid password') + } + + if (password !== passwordRepeat) { + throw new Error('passwords do not match') + } + + var users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + var user = users.find(function (user) { + return user.email === email + }) + + if (user !== undefined) { + throw new Error('email already exists') + } + + var user = users.find(function (user) { + return user.username === username + }) + + if (user !== undefined) { + throw new Error('username already exists') + } + + user = { + name: name, + surname: surname, + email: email, + username: username, + password: password + } + + users.push(user) + + localStorage.users = JSON.stringify(users) +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/login.html b/staff/lucas-orts/ponies/app/login.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/ponies/app/register.html b/staff/lucas-orts/ponies/app/register.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/ponies/app/utils/formatTime.js b/staff/lucas-orts/ponies/app/utils/formatTime.js new file mode 100644 index 000000000..c54838bf7 --- /dev/null +++ b/staff/lucas-orts/ponies/app/utils/formatTime.js @@ -0,0 +1,41 @@ +function formatTime(date) { + var seconds = Math.round((Date.now() - date.getTime()) / 1000) + + if (seconds < 60) { + return seconds + ' second' + (seconds === 1 ? '' : 's') + } + + var minutes = Math.round(seconds / 60) + + if (minutes < 60) { + return minutes + ' minute' + (minutes === 1 ? '' : 's') + } + + var hours = Math.round(minutes / 60) + + if (hours < 24) { + return hours + ' hour' + (hours === 1 ? '' : 's') + } + + var days = Math.round(hours / 24) + + if (days < 7) { + return days + ' day' + (days === 1 ? '' : 's') + } + + var weeks = Math.round(days / 7) + + if (weeks < 4) { + return weeks + ' week' + (weeks === 1 ? '' : 's') + } + + var months = Math.round(weeks / 4) + + if (months < 12) { + return months + ' month' + (months === 1 ? '' : 's') + } + + var years = Math.round(months / 12) + + return years + ' year' + (years === 1 ? '' : 's') +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/utils/generateRandomId.js b/staff/lucas-orts/ponies/app/utils/generateRandomId.js new file mode 100644 index 000000000..6e3866900 --- /dev/null +++ b/staff/lucas-orts/ponies/app/utils/generateRandomId.js @@ -0,0 +1,3 @@ +function generateRandomId() { + return Math.random().toString() + Date.now().toString() +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.html b/staff/lucas-orts/ponies/app/views/home/index.html new file mode 100644 index 000000000..3345b80cb --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/index.html @@ -0,0 +1,32 @@ + + + + + + + Home + + + + + +

Home

+ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.js b/staff/lucas-orts/ponies/app/views/home/index.js new file mode 100644 index 000000000..89bc69b6d --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/index.js @@ -0,0 +1,135 @@ +try { + var name = getUserName() + + var title = document.querySelector('h1') + + title.innerText = 'Hello, ' + name + '!' +} catch (error) { + alert(error.message) +} + +var logoutButton = document.getElementById('logout-button') + +logoutButton.onclick = function () { + try { + logoutUser() + + location.href = '../login' + } catch (error) { + alert(error.message) + } +} + +var addPostButton = document.getElementById('add-post-button') + +addPostButton.onclick = function () { + var createPostSection = document.createElement('section') + document.body.appendChild(createPostSection) + + var createPostTitle = document.createElement('h2') + createPostTitle.innerText = 'Create Post' + createPostSection.appendChild(createPostTitle) + + var createPostForm = document.createElement('form') + createPostSection.appendChild(createPostForm) + + createPostForm.onsubmit = function (event) { + event.preventDefault() + + // var postImageInput = document.getElementById('post-image-input') + var postImage = postImageInput.value + var postCaption = postCaptionInput.value + + try { + createPost(postImage, postCaption) + + document.body.removeChild(createPostSection) + + for (var i = postListSection.children.length - 1; i > -1; i--) { + var child = postListSection.children[i] + + postListSection.removeChild(child) + } + + listPosts() + } catch (error) { + alert(error.message) + } + } + + var postImageLabel = document.createElement('label') + postImageLabel.htmlFor = 'post-image-input' + postImageLabel.innerText = 'Image' + createPostForm.appendChild(postImageLabel) + + var postImageInput = document.createElement('input') + postImageInput.id = postImageLabel.htmlFor + createPostForm.appendChild(postImageInput) + + var postCaptionLabel = document.createElement('label') + postCaptionLabel.htmlFor = 'post-caption-input' + postCaptionLabel.innerText = 'Caption' + createPostForm.appendChild(postCaptionLabel) + + var postCaptionInput = document.createElement('input') + postCaptionInput.id = postCaptionLabel.htmlFor + createPostForm.appendChild(postCaptionInput) + + var postButtonSubmit = document.createElement('button') + postButtonSubmit.type = 'submit' + postButtonSubmit.innerText = 'Submit' + createPostForm.appendChild(postButtonSubmit) + + var postCancelButton = document.createElement('button') + postCancelButton.innerText = 'Cancel' + postCancelButton.type = 'reset' + createPostForm.appendChild(postCancelButton) + + postCancelButton.onclick = function () { + document.body.removeChild(createPostSection) + } +} + +var postListSection = document.createElement('section') +document.body.appendChild(postListSection) + +function listPosts() { + var posts = getAllPosts() + + posts.forEach(function (post) { + var postArticle = document.createElement('article') + postListSection.appendChild(postArticle) + + var postAuthorTitle = document.createElement('h3') + postAuthorTitle.innerText = post.author + postArticle.appendChild(postAuthorTitle) + + var postImage = document.createElement('img') + postImage.src = post.image + postArticle.appendChild(postImage) + + var postCaptionText = document.createElement('p') + postCaptionText.innerText = post.caption + postArticle.appendChild(postCaptionText) + + var postDateTime = document.createElement('time') + postDateTime.innerText = formatTime(new Date(post.date)) + postArticle.appendChild(postDateTime) + + if (post.author === getUserUsername()) { + var postDeleteButton = document.createElement('button') + postDeleteButton.innerText = 'Delete' + postArticle.appendChild(postDeleteButton) + + postDeleteButton.onclick = function () { + + var id = post.id + + deletePost(id) + postListSection.removeChild(postArticle) + } + } + }) +} + +listPosts() \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.html b/staff/lucas-orts/ponies/app/views/login/index.html new file mode 100644 index 000000000..1e853f2e0 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/login/index.html @@ -0,0 +1,33 @@ + + + + + + + Login + + + + + +

Login

+ +
+ + + + + + + +
+ + Register + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.js b/staff/lucas-orts/ponies/app/views/login/index.js new file mode 100644 index 000000000..0a9f6879f --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/login/index.js @@ -0,0 +1,27 @@ +var form = document.querySelector('form') + +form.onsubmit = function (event) { + event.preventDefault() + + var usernameInput = document.getElementById('username-input') + var passwordInput = document.getElementById('password-input') + + var username = usernameInput.value + var password = passwordInput.value + + try { + loginUser(username, password) + + location.href = '../home' + } catch (error) { + alert(error.message) + } +} + +var a = document.querySelector('a') + +a.onclick = function (event) { + event.preventDefault() + + window.location.href = '../register' +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/register/index.html b/staff/lucas-orts/ponies/app/views/register/index.html new file mode 100644 index 000000000..9be3801a4 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/register/index.html @@ -0,0 +1,45 @@ + + + + + + + Register + + + + + +

Register

+ +
+ + + + + + + + + + + + + + + + + + + +
+ + Login + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/register/index.js b/staff/lucas-orts/ponies/app/views/register/index.js new file mode 100644 index 000000000..8136675da --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/register/index.js @@ -0,0 +1,37 @@ +var form = document.querySelector('form') + +form.onsubmit = function (event) { + event.preventDefault() + + var nameInput = document.getElementById('name-input') + var surnameInput = document.getElementById('surname-input') + var emailInput = document.getElementById('email-input') + var usernameInput = document.getElementById('username-input') + var passwordInput = document.getElementById('password-input') + var passwordRepeatInput = document.getElementById('password2-input') + + var name = nameInput.value + var surname = surnameInput.value + var email = emailInput.value + var username = usernameInput.value + var password = passwordInput.value + var passwordRepeat = passwordRepeatInput.value + + try { + registerUser(name, surname, email, username, password, passwordRepeat) + + alert('user successfully registered') + + location.href = '../login' + } catch (error) { + alert(error.message) + } +} + +var a = document.querySelector('a') + +a.onclick = function (event) { + event.preventDefault() + + location.href = '../login' +} \ No newline at end of file From 0aef19e033231575c35c0872774fa6b539f0f913 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 19 Jun 2024 14:48:17 +0200 Subject: [PATCH 10/21] implement update post and changes in add post #60 --- .../lucas-orts/ponies/app/logic/createPost.js | 2 +- .../ponies/app/logic/updatePostCaption.js | 15 + .../lucas-orts/ponies/app/utils/generateId.js | 7 + .../ponies/app/utils/generateRandomId.js | 3 - .../ponies/app/views/home/index.css | 113 ++++++ .../ponies/app/views/home/index.html | 10 +- .../lucas-orts/ponies/app/views/home/index.js | 323 ++++++++++++------ .../ponies/app/views/login/index.css | 0 .../ponies/app/views/login/index.html | 4 +- .../ponies/app/views/register/index.css | 0 .../ponies/app/views/register/index.html | 4 +- 11 files changed, 365 insertions(+), 116 deletions(-) create mode 100644 staff/lucas-orts/ponies/app/logic/updatePostCaption.js create mode 100644 staff/lucas-orts/ponies/app/utils/generateId.js delete mode 100644 staff/lucas-orts/ponies/app/utils/generateRandomId.js create mode 100644 staff/lucas-orts/ponies/app/views/home/index.css create mode 100644 staff/lucas-orts/ponies/app/views/login/index.css create mode 100644 staff/lucas-orts/ponies/app/views/register/index.css diff --git a/staff/lucas-orts/ponies/app/logic/createPost.js b/staff/lucas-orts/ponies/app/logic/createPost.js index 8458c7a03..e6e27da26 100644 --- a/staff/lucas-orts/ponies/app/logic/createPost.js +++ b/staff/lucas-orts/ponies/app/logic/createPost.js @@ -10,7 +10,7 @@ function createPost(image, caption) { caption: caption, author: sessionStorage.username, date: new Date().toISOString(), - id: generateRandomId() + id: generateId() } posts.push(post) diff --git a/staff/lucas-orts/ponies/app/logic/updatePostCaption.js b/staff/lucas-orts/ponies/app/logic/updatePostCaption.js new file mode 100644 index 000000000..d9c5db112 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/updatePostCaption.js @@ -0,0 +1,15 @@ +function updatePostCaption(postId, newCaption) { + if (postId.trim().length === 0) throw new Error('invalid postId') + + var posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + var post = posts.find(function (post) { + return post.id === postId + }) + + if (post === undefined) throw new Error('post not found') + + post.caption = newCaption + + localStorage.posts = JSON.stringify(posts) +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/utils/generateId.js b/staff/lucas-orts/ponies/app/utils/generateId.js new file mode 100644 index 000000000..c43cff149 --- /dev/null +++ b/staff/lucas-orts/ponies/app/utils/generateId.js @@ -0,0 +1,7 @@ +function generateId() { + var id10 = Math.random().toString().slice(2) + Date.now().toString() + + var id36 = Math.round(+id10 / 1000000000000).toString(36) + + return id36 +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/utils/generateRandomId.js b/staff/lucas-orts/ponies/app/utils/generateRandomId.js deleted file mode 100644 index 6e3866900..000000000 --- a/staff/lucas-orts/ponies/app/utils/generateRandomId.js +++ /dev/null @@ -1,3 +0,0 @@ -function generateRandomId() { - return Math.random().toString() + Date.now().toString() -} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.css b/staff/lucas-orts/ponies/app/views/home/index.css new file mode 100644 index 000000000..1aa948c44 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/index.css @@ -0,0 +1,113 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.section__form { + box-sizing: border-box; + position: fixed; + background-color: white; + width: 100%; + bottom: 2.3rem; + padding: 1rem +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; + margin-bottom: 20%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; + background-color: #FF0303; + border-radius: 60px; + padding-top: 3px; + padding-bottom: 3px; + padding-left: 6px; + padding-right: 6px; +} + +.add-post-button { + font-size: inherit; + background-color: #FF0303; + border-radius: 100%; + +} + +.post-list { + display: flex; + flex-direction: column; + gap: 1rem; +} + +.post { + /* border: 1px solid black; */ + box-shadow: 1px 1px 10px 1px lightgray; +} + +.post__author { + margin: .5rem; +} + +.post__image { + width: 100%; +} + +.post__caption { + margin: .5rem; +} + +.post__actions { + margin: .5rem; +} + +.post__time { + display: block; + margin: .5rem; + color: silver; + font-size: .9rem; +} + +.header { + position: fixed; + left: 0; + top: 0; + width: 100%; + display: flex; + justify-content: right; + align-items: center; + gap: 1rem; + background-color: #f25252; +} + +.main { + margin-top: 3.5rem; + margin-bottom: 3rem; +} + +.footer { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + display: flex; + justify-content: center; + background-color: white; + padding: .5rem 0; +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.html b/staff/lucas-orts/ponies/app/views/home/index.html index 3345b80cb..f5510046f 100644 --- a/staff/lucas-orts/ponies/app/views/home/index.html +++ b/staff/lucas-orts/ponies/app/views/home/index.html @@ -6,18 +6,13 @@ Home - + -

Home

- - - + @@ -25,6 +20,7 @@

Home

+ diff --git a/staff/lucas-orts/ponies/app/views/home/index.js b/staff/lucas-orts/ponies/app/views/home/index.js index 89bc69b6d..c877b0e7f 100644 --- a/staff/lucas-orts/ponies/app/views/home/index.js +++ b/staff/lucas-orts/ponies/app/views/home/index.js @@ -1,135 +1,260 @@ -try { - var name = getUserName() +(function () { + var header = document.createElement('header') + header.className = 'header' + document.body.appendChild(header) - var title = document.querySelector('h1') + var userName = document.createElement('p') + header.appendChild(userName) - title.innerText = 'Hello, ' + name + '!' -} catch (error) { - alert(error.message) -} - -var logoutButton = document.getElementById('logout-button') - -logoutButton.onclick = function () { try { - logoutUser() + var name = getUserName() - location.href = '../login' + userName.innerText = 'Hello, ' + name + '!' } catch (error) { alert(error.message) } -} - -var addPostButton = document.getElementById('add-post-button') - -addPostButton.onclick = function () { - var createPostSection = document.createElement('section') - document.body.appendChild(createPostSection) - - var createPostTitle = document.createElement('h2') - createPostTitle.innerText = 'Create Post' - createPostSection.appendChild(createPostTitle) - - var createPostForm = document.createElement('form') - createPostSection.appendChild(createPostForm) - createPostForm.onsubmit = function (event) { - event.preventDefault() - - // var postImageInput = document.getElementById('post-image-input') - var postImage = postImageInput.value - var postCaption = postCaptionInput.value + var logoutButton = document.createElement('button') + logoutButton.className = 'logout-button' + logoutButton.innerText = 'Logout' + header.appendChild(logoutButton) + logoutButton.onclick = function () { try { - createPost(postImage, postCaption) - - document.body.removeChild(createPostSection) - - for (var i = postListSection.children.length - 1; i > -1; i--) { - var child = postListSection.children[i] - - postListSection.removeChild(child) - } + logoutUser() - listPosts() + location.href = '../login' } catch (error) { alert(error.message) } } - var postImageLabel = document.createElement('label') - postImageLabel.htmlFor = 'post-image-input' - postImageLabel.innerText = 'Image' - createPostForm.appendChild(postImageLabel) - - var postImageInput = document.createElement('input') - postImageInput.id = postImageLabel.htmlFor - createPostForm.appendChild(postImageInput) - var postCaptionLabel = document.createElement('label') - postCaptionLabel.htmlFor = 'post-caption-input' - postCaptionLabel.innerText = 'Caption' - createPostForm.appendChild(postCaptionLabel) + var main = document.createElement('main') + main.className = 'view main' + document.body.appendChild(main) - var postCaptionInput = document.createElement('input') - postCaptionInput.id = postCaptionLabel.htmlFor - createPostForm.appendChild(postCaptionInput) + var postListSection = document.createElement('section') + postListSection.className = 'post-list' + main.appendChild(postListSection) - var postButtonSubmit = document.createElement('button') - postButtonSubmit.type = 'submit' - postButtonSubmit.innerText = 'Submit' - createPostForm.appendChild(postButtonSubmit) + function clearPosts() { + for (var i = postListSection.children.length - 1; i > -1; i--) { + var child = postListSection.children[i] - var postCancelButton = document.createElement('button') - postCancelButton.innerText = 'Cancel' - postCancelButton.type = 'reset' - createPostForm.appendChild(postCancelButton) + postListSection.removeChild(child) + } + } - postCancelButton.onclick = function () { - document.body.removeChild(createPostSection) + function listPosts() { + try { + var posts = getAllPosts() + + posts.forEach(function (post) { + var postArticle = document.createElement('article') + postArticle.className = 'post' + postListSection.appendChild(postArticle) + + var postAuthorTitle = document.createElement('h3') + postAuthorTitle.className = 'post__author' + postAuthorTitle.innerText = post.author + postArticle.appendChild(postAuthorTitle) + + var postImage = document.createElement('img') + postImage.className = 'post__image' + postImage.src = post.image + postArticle.appendChild(postImage) + + var postCaptionText = document.createElement('p') + postCaptionText.className = 'post__caption' + postCaptionText.innerText = post.caption + postArticle.appendChild(postCaptionText) + + if (post.author === getUserUsername()) { + + var postActionButtonsDiv = document.createElement('div') + postActionButtonsDiv.className = 'post__actions' + postArticle.appendChild(postActionButtonsDiv) + + var postDeleteButton = document.createElement('button') + postDeleteButton.className = 'form__button' + postDeleteButton.innerText = 'Delete' + postActionButtonsDiv.appendChild(postDeleteButton) + + postDeleteButton.onclick = function () { + if (confirm('Delete post?')) + try { + deletePost(post.id) + + clearPosts() + listPosts() + } catch (error) { + alert(error.message) + + if (error.message === 'post not found') { + clearPosts() + listPosts() + } + } + } + + var editButton = document.createElement('button') + editButton.className = 'form__button' + editButton.innerText = 'Edit' + postActionButtonsDiv.appendChild(editButton) + + editButton.onclick = function () { + + var editCaptionForm = document.createElement('form') + postArticle.appendChild(editCaptionForm) + + var editCaptionLabel = document.createElement('label') + editCaptionLabel.htmlFor = 'edit-caption-input' + editCaptionForm.appendChild(editCaptionLabel) + + var editCaptionInput = document.createElement('input') + editCaptionInput.id = editCaptionLabel.htmlFor + editCaptionInput.value = post.caption + editCaptionForm.appendChild(editCaptionInput) + + var editCaptionSubmitButton = document.createElement('button') + editCaptionSubmitButton.className = 'form__button' + editCaptionSubmitButton.type = 'submit' + editCaptionSubmitButton.innerText = 'Save' + editCaptionForm.appendChild(editCaptionSubmitButton) + + var editCaptionCancelButton = document.createElement('button') + editCaptionCancelButton.className = 'form__button' + editCaptionCancelButton.innerText = 'Cancel' + editCaptionCancelButton.type = 'button' + editCaptionForm.appendChild(editCaptionCancelButton) + + editCaptionCancelButton.onclick = function () { + postArticle.removeChild(editCaptionForm) + } + + editCaptionForm.onsubmit = function (event) { + event.preventDefault() + + try { + var newCaption = editCaptionInput.value + + updatePostCaption(post.id, newCaption) + + postArticle.removeChild(editCaptionForm) + + clearPosts() + listPosts() + } catch (error) { + alert(error.message) + + if (error.message === 'post not found') { + clearPosts() + listPosts() + } + } + } + } + } + + var postDateTime = document.createElement('time') + postDateTime.className = 'post__time' + postDateTime.innerText = formatTime(new Date(post.date)) + postArticle.appendChild(postDateTime) + }) + } catch (error) { + alert(error.message) + } } -} -var postListSection = document.createElement('section') -document.body.appendChild(postListSection) + listPosts() -function listPosts() { - var posts = getAllPosts() + var footer = document.createElement('footer') + footer.className = 'footer' + document.body.appendChild(footer) - posts.forEach(function (post) { - var postArticle = document.createElement('article') - postListSection.appendChild(postArticle) + var addPostButton = document.createElement('button') + addPostButton.className = 'add-post-button' + addPostButton.innerText = '+' + footer.appendChild(addPostButton) - var postAuthorTitle = document.createElement('h3') - postAuthorTitle.innerText = post.author - postArticle.appendChild(postAuthorTitle) + addPostButton.onclick = function () { + addPostButton.disabled = true + var createPostSection = document.createElement('section') + createPostSection.className = 'section__form' + document.body.appendChild(createPostSection) - var postImage = document.createElement('img') - postImage.src = post.image - postArticle.appendChild(postImage) + var createPostTitle = document.createElement('h2') + createPostTitle.innerText = 'Create Post' + createPostSection.appendChild(createPostTitle) - var postCaptionText = document.createElement('p') - postCaptionText.innerText = post.caption - postArticle.appendChild(postCaptionText) + var createPostForm = document.createElement('form') + createPostForm.className = 'form' + createPostSection.appendChild(createPostForm) - var postDateTime = document.createElement('time') - postDateTime.innerText = formatTime(new Date(post.date)) - postArticle.appendChild(postDateTime) + createPostForm.onsubmit = function (event) { + event.preventDefault() - if (post.author === getUserUsername()) { - var postDeleteButton = document.createElement('button') - postDeleteButton.innerText = 'Delete' - postArticle.appendChild(postDeleteButton) + addPostButton.disabled = false + //var postImageInput = document.getElementById('post-image-input') + var postImage = postImageInput.value + var postCaption = postCaptionInput.value - postDeleteButton.onclick = function () { + try { + createPost(postImage, postCaption) - var id = post.id + document.body.removeChild(createPostSection) - deletePost(id) - postListSection.removeChild(postArticle) + clearPosts() + listPosts() + } catch (error) { + alert(error.message) } } - }) -} -listPosts() \ No newline at end of file + var postImageFieldDiv = document.createElement('div') + postImageFieldDiv.className = 'form__field' + createPostForm.appendChild(postImageFieldDiv) + + var postImageLabel = document.createElement('label') + postImageLabel.htmlFor = 'post-image-input' + postImageLabel.innerText = 'Image' + postImageFieldDiv.appendChild(postImageLabel) + + var postImageInput = document.createElement('input') + postImageInput.className = 'form__input' + postImageInput.id = postImageLabel.htmlFor + postImageFieldDiv.appendChild(postImageInput) + + var postCaptionFieldDiv = document.createElement('div') + postCaptionFieldDiv.className = 'form__field' + createPostForm.appendChild(postCaptionFieldDiv) + + var postCaptionLabel = document.createElement('label') + postCaptionLabel.htmlFor = 'post-caption-input' + postCaptionLabel.innerText = 'Caption' + postCaptionFieldDiv.appendChild(postCaptionLabel) + + var postCaptionInput = document.createElement('input') + postCaptionInput.className = 'form__input' + postCaptionInput.id = postCaptionLabel.htmlFor + postCaptionFieldDiv.appendChild(postCaptionInput) + + var postSubmitButton = document.createElement('button') + postSubmitButton.className = 'form__button' + postSubmitButton.type = 'submit' + postSubmitButton.innerText = 'Create' + createPostForm.appendChild(postSubmitButton) + + var postCancelButton = document.createElement('button') + postCancelButton.className = 'form__button' + postCancelButton.type = 'reset' + postCancelButton.innerText = 'Cancel' + createPostForm.appendChild(postCancelButton) + + postCancelButton.onclick = function () { + addPostButton.disabled = false + document.body.removeChild(createPostSection) + } + } +})() \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.css b/staff/lucas-orts/ponies/app/views/login/index.css new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/ponies/app/views/login/index.html b/staff/lucas-orts/ponies/app/views/login/index.html index 1e853f2e0..f1e149486 100644 --- a/staff/lucas-orts/ponies/app/views/login/index.html +++ b/staff/lucas-orts/ponies/app/views/login/index.html @@ -6,9 +6,7 @@ Login - + diff --git a/staff/lucas-orts/ponies/app/views/register/index.css b/staff/lucas-orts/ponies/app/views/register/index.css new file mode 100644 index 000000000..e69de29bb diff --git a/staff/lucas-orts/ponies/app/views/register/index.html b/staff/lucas-orts/ponies/app/views/register/index.html index 9be3801a4..aa6fafca4 100644 --- a/staff/lucas-orts/ponies/app/views/register/index.html +++ b/staff/lucas-orts/ponies/app/views/register/index.html @@ -6,9 +6,7 @@ Register - + From e7ebadc676391b120be74163affcee36b49208b2 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Jul 2024 10:54:28 +0200 Subject: [PATCH 11/21] implement login in React #60 --- .../Array/Array.prototype.at.test.js | 39 ---- .../Array/Array.prototype.concat.test.js | 42 ---- .../Array/Array.prototype.copyWithin.test.js | 42 ---- .../Array/Array.prototype.every.test.js | 29 --- .../Array/Array.prototype.filter.test.js | 12 - .../Array/Array.prototype.find.test.js | 9 - .../Array/Array.prototype.forEach.test.js | 67 ------ .../Array/Array.prototype.includes.test.js | 28 --- .../Array/Array.prototype.indexOf.test.js | 19 -- .../Array/Array.prototype.join.test.js | 38 ---- .../Array/Array.prototype.lastIndexOf.test.js | 17 -- .../Array/Array.prototype.map.test.js | 13 -- .../Array/Array.prototype.pop.test.js | 32 --- .../Array/Array.prototype.push.test.js | 27 --- .../lucas-orts/playground/Array/Array.test.js | 46 ---- staff/lucas-orts/playground/Curray/Curray.js | 15 -- .../playground/Curray/Curray.prototype.at.js | 10 - .../Curray/Curray.prototype.at.test.js | 43 ---- .../Curray/Curray.prototype.concat.js | 29 --- .../Curray/Curray.prototype.concat.test.js | 44 ---- .../Curray/Curray.prototype.copyWithin.js | 45 ---- .../Curray.prototype.copyWithin.test.js | 59 ----- .../Curray/Curray.prototype.every.js | 16 -- .../Curray/Curray.prototype.every.test.js | 33 --- .../Curray/Curray.prototype.filter.js | 18 -- .../Curray/Curray.prototype.filter.test.js | 16 -- .../Curray/Curray.prototype.find.js | 15 -- .../Curray/Curray.prototype.find.test.js | 18 -- .../Curray/Curray.prototype.forEach.js | 11 - .../Curray/Curray.prototype.forEach.test.js | 19 -- .../Curray/Curray.prototype.includes.js | 0 .../Curray/Curray.prototype.includes.test.js | 59 ----- .../Curray/Curray.prototype.indexOf.js | 24 -- .../Curray/Curray.prototype.indexOf.test.js | 30 --- .../Curray/Curray.prototype.join.js | 20 -- .../Curray/Curray.prototype.join.test.js | 48 ---- .../Curray/Curray.prototype.lastIndexOf.js | 17 -- .../Curray.prototype.lastIndexOf.test.js | 21 -- .../playground/Curray/Curray.prototype.map.js | 14 -- .../Curray/Curray.prototype.map.test.js | 17 -- .../playground/Curray/Curray.prototype.pop.js | 9 - .../Curray/Curray.prototype.pop.test.js | 36 --- .../Curray/Curray.prototype.push.js | 11 - .../Curray/Curray.prototype.push.test.js | 32 --- .../playground/Curray/Curray.test.js | 40 ---- staff/lucas-orts/playground/arrays/index.js | 55 ----- .../lucas-orts/playground/building/index.html | 0 .../lucas-orts/playground/building/style.css | 0 staff/lucas-orts/playground/car/index.html | 0 staff/lucas-orts/playground/car/style.css | 0 staff/lucas-orts/playground/cv/index.html | 0 staff/lucas-orts/playground/face/index.html | 0 staff/lucas-orts/playground/face/style.css | 0 staff/lucas-orts/playground/objects/index.js | 91 -------- staff/lucas-orts/playground/objects/map.js | 15 -- .../lucas-orts/ponies/app/data/deletePost.mjs | 13 ++ staff/lucas-orts/ponies/app/data/findPost.mjs | 9 + .../lucas-orts/ponies/app/data/findPosts.mjs | 9 + staff/lucas-orts/ponies/app/data/findUser.mjs | 9 + staff/lucas-orts/ponies/app/data/index.mjs | 21 ++ .../lucas-orts/ponies/app/data/insertPost.mjs | 9 + .../lucas-orts/ponies/app/data/insertUser.mjs | 9 + .../lucas-orts/ponies/app/data/updatePost.mjs | 13 ++ .../lucas-orts/ponies/app/data/updateUser.mjs | 13 ++ .../ponies/app/logic/createPost.mjs | 21 ++ .../ponies/app/logic/deletePost.mjs | 13 ++ .../ponies/app/logic/getAllFavPosts.mjs | 23 ++ .../app/logic/getAllFollowingUserPosts.mjs | 23 ++ .../ponies/app/logic/getAllPosts.mjs | 23 ++ .../ponies/app/logic/getUserName.mjs | 12 + .../ponies/app/logic/getUserUsername.mjs | 3 + staff/lucas-orts/ponies/app/logic/index.mjs | 33 +++ .../lucas-orts/ponies/app/logic/loginUser.mjs | 21 ++ .../ponies/app/logic/logoutUser.mjs | 3 + .../ponies/app/logic/registerUser.mjs | 47 ++++ .../ponies/app/logic/toggleFavPost.mjs | 26 +++ .../ponies/app/logic/toggleFollowUser.mjs | 24 ++ .../ponies/app/logic/toggleLikePost.mjs | 21 ++ .../ponies/app/logic/updatePostCaption.mjs | 15 ++ .../lucas-orts/ponies/app/util/formatTime.mjs | 37 +++ .../lucas-orts/ponies/app/util/generateId.mjs | 9 + .../ponies/app/views/home/index.html | 16 +- .../ponies/app/views/login/index.css | 28 +++ .../ponies/app/views/login/index.html | 54 +++-- .../ponies/app/views/login/index.js | 27 --- .../ponies/app/views/login/index.jsx | 62 ++++++ .../ponies/app/views/register/index.css | 0 .../ponies/app/views/register/index.html | 72 +++--- .../ponies/app/views/register/index.js | 37 --- .../blog => stuff/react/demo.0}/index.html | 33 ++- staff/lucas-orts/stuff/react/demo.0/main.js | 30 +++ .../lucas-orts/stuff/react/demo.1/index.html | 19 ++ staff/lucas-orts/stuff/react/demo.1/main.js | 17 ++ staff/lucas-orts/stuff/react/demo/index.html | 19 ++ staff/lucas-orts/stuff/react/demo/main.js | 79 +++++++ .../zzz/app copy}/logic/createPost.js | 0 .../zzz/app copy}/logic/deletePost.js | 0 .../zzz/app copy}/logic/getAllPosts.js | 0 .../zzz/app copy}/logic/getUserName.js | 0 .../zzz/app copy}/logic/getUserUsername.js | 0 .../zzz/app copy}/logic/loginUser.js | 0 .../zzz/app copy}/logic/logoutUser.js | 0 .../zzz/app copy}/logic/registerUser.js | 0 .../zzz/app copy}/logic/updatePostCaption.js | 0 .../zzz/app copy}/utils/formatTime.js | 0 .../zzz/app copy}/utils/generateId.js | 0 .../stuff/zzz/app copy/views/Component.js | 40 ++++ .../zzz/app copy/views/components/Button.js | 9 + .../zzz/app copy/views/components/Form.js | 9 + .../zzz/app copy/views/components/Link.js | 9 + .../app copy/views/components/Paragraph.js | 5 + .../app copy/views/home/components/Header.js | 34 +++ .../zzz/app copy}/views/home/index.css | 34 +++ .../stuff/zzz/app copy/views/home/index.html | 33 +++ .../zzz/app copy}/views/home/index.js | 124 +++++------ .../stuff/zzz/app copy/views/login/index.css | 28 +++ .../stuff/zzz/app copy/views/login/index.html | 42 ++++ .../stuff/zzz/app copy/views/login/index.js | 29 +++ .../zzz/app copy/views/register/index.css | 28 +++ .../zzz/app copy/views/register/index.html | 65 ++++++ .../zzz/app copy/views/register/index.js | 39 ++++ .../stuff/zzz/app copy2/data/deletePost.mjs | 13 ++ .../stuff/zzz/app copy2/data/findPost.mjs | 9 + .../stuff/zzz/app copy2/data/findPosts.mjs | 9 + .../stuff/zzz/app copy2/data/findUser.mjs | 9 + .../stuff/zzz/app copy2/data/index.mjs | 21 ++ .../stuff/zzz/app copy2/data/insertPost.mjs | 9 + .../stuff/zzz/app copy2/data/insertUser.mjs | 9 + .../stuff/zzz/app copy2/data/updatePost.mjs | 13 ++ .../stuff/zzz/app copy2/data/updateUser.mjs | 13 ++ .../stuff/zzz/app copy2/logic/createPost.mjs | 21 ++ .../stuff/zzz/app copy2/logic/deletePost.mjs | 13 ++ .../zzz/app copy2/logic/getAllFavPosts.mjs | 19 ++ .../logic/getAllFollowingUserPosts.mjs | 23 ++ .../stuff/zzz/app copy2/logic/getAllPosts.mjs | 19 ++ .../stuff/zzz/app copy2/logic/getUserName.mjs | 12 + .../zzz/app copy2/logic/getUserUsername.mjs | 3 + .../stuff/zzz/app copy2/logic/index.mjs | 33 +++ .../stuff/zzz/app copy2/logic/loginUser.mjs | 21 ++ .../stuff/zzz/app copy2/logic/logoutUser.mjs | 3 + .../zzz/app copy2/logic/registerUser.mjs | 47 ++++ .../zzz/app copy2/logic/toggleFavPost.mjs | 26 +++ .../zzz/app copy2/logic/toggleFollowUser.mjs | 27 +++ .../zzz/app copy2/logic/toggleLikePost.mjs | 21 ++ .../zzz/app copy2/logic/updatePostCaption.mjs | 15 ++ .../stuff/zzz/app copy2/util/formatTime.mjs | 37 +++ .../stuff/zzz/app copy2/util/generateId.mjs | 9 + .../stuff/zzz/app copy2/views/Component.mjs | 64 ++++++ .../zzz/app copy2/views/components/Button.css | 16 ++ .../zzz/app copy2/views/components/Button.mjs | 19 ++ .../zzz/app copy2/views/components/Form.mjs | 13 ++ .../app copy2/views/components/Heading.mjs | 9 + .../zzz/app copy2/views/components/Image.mjs | 13 ++ .../zzz/app copy2/views/components/Input.mjs | 21 ++ .../zzz/app copy2/views/components/Label.mjs | 17 ++ .../zzz/app copy2/views/components/Link.mjs | 13 ++ .../app copy2/views/components/Paragraph.mjs | 9 + .../views/home/components/FavPostList.mjs | 65 ++++++ .../home/components/FollowingUserPostList.mjs | 65 ++++++ .../views/home/components/Footer.mjs | 106 +++++++++ .../views/home/components/Header.mjs | 101 +++++++++ .../app copy2/views/home/components/Post.mjs | 210 ++++++++++++++++++ .../views/home/components/PostList.mjs | 65 ++++++ .../stuff/zzz/app copy2/views/home/index.css | 147 ++++++++++++ .../stuff/zzz/app copy2/views/home/index.html | 18 ++ .../stuff/zzz/app copy2/views/home/index.mjs | 72 ++++++ .../stuff/zzz/app copy2/views/login/index.css | 28 +++ .../zzz/app copy2/views/login/index.html | 38 ++++ .../stuff/zzz/app copy2/views/login/index.mjs | 34 +++ .../zzz/app copy2/views/register/index.css | 28 +++ .../zzz/app copy2/views/register/index.html | 59 +++++ .../zzz/app copy2/views/register/index.mjs | 44 ++++ staff/lucas-orts/stuff/zzz/app1/home.html | 20 ++ staff/lucas-orts/stuff/zzz/app1/login.html | 66 ++++++ staff/lucas-orts/stuff/zzz/app1/register.html | 22 ++ staff/lucas-orts/stuff/zzz/app2/home.html | 23 ++ staff/lucas-orts/stuff/zzz/app2/login.html | 53 +++++ staff/lucas-orts/stuff/zzz/app2/register.html | 133 +++++++++++ staff/lucas-orts/stuff/zzz/app3/home.html | 34 +++ staff/lucas-orts/stuff/zzz/app3/login.html | 43 ++++ 180 files changed, 3391 insertions(+), 1601 deletions(-) delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.at.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.concat.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.every.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.filter.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.find.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.includes.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.join.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.map.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.pop.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.prototype.push.test.js delete mode 100644 staff/lucas-orts/playground/Array/Array.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.at.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.concat.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.every.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.filter.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.find.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.includes.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.join.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.map.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.pop.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.push.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js delete mode 100644 staff/lucas-orts/playground/Curray/Curray.test.js delete mode 100644 staff/lucas-orts/playground/arrays/index.js delete mode 100644 staff/lucas-orts/playground/building/index.html delete mode 100644 staff/lucas-orts/playground/building/style.css delete mode 100644 staff/lucas-orts/playground/car/index.html delete mode 100644 staff/lucas-orts/playground/car/style.css delete mode 100644 staff/lucas-orts/playground/cv/index.html delete mode 100644 staff/lucas-orts/playground/face/index.html delete mode 100644 staff/lucas-orts/playground/face/style.css delete mode 100644 staff/lucas-orts/playground/objects/index.js delete mode 100644 staff/lucas-orts/playground/objects/map.js create mode 100644 staff/lucas-orts/ponies/app/data/deletePost.mjs create mode 100644 staff/lucas-orts/ponies/app/data/findPost.mjs create mode 100644 staff/lucas-orts/ponies/app/data/findPosts.mjs create mode 100644 staff/lucas-orts/ponies/app/data/findUser.mjs create mode 100644 staff/lucas-orts/ponies/app/data/index.mjs create mode 100644 staff/lucas-orts/ponies/app/data/insertPost.mjs create mode 100644 staff/lucas-orts/ponies/app/data/insertUser.mjs create mode 100644 staff/lucas-orts/ponies/app/data/updatePost.mjs create mode 100644 staff/lucas-orts/ponies/app/data/updateUser.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/createPost.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/deletePost.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/getAllFavPosts.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/getAllFollowingUserPosts.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/getAllPosts.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/getUserName.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/getUserUsername.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/index.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/loginUser.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/logoutUser.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/registerUser.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/toggleFavPost.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/toggleFollowUser.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/toggleLikePost.mjs create mode 100644 staff/lucas-orts/ponies/app/logic/updatePostCaption.mjs create mode 100644 staff/lucas-orts/ponies/app/util/formatTime.mjs create mode 100644 staff/lucas-orts/ponies/app/util/generateId.mjs delete mode 100644 staff/lucas-orts/ponies/app/views/login/index.js create mode 100644 staff/lucas-orts/ponies/app/views/login/index.jsx delete mode 100644 staff/lucas-orts/ponies/app/views/register/index.css delete mode 100644 staff/lucas-orts/ponies/app/views/register/index.js rename staff/lucas-orts/{playground/blog => stuff/react/demo.0}/index.html (50%) create mode 100644 staff/lucas-orts/stuff/react/demo.0/main.js create mode 100644 staff/lucas-orts/stuff/react/demo.1/index.html create mode 100644 staff/lucas-orts/stuff/react/demo.1/main.js create mode 100644 staff/lucas-orts/stuff/react/demo/index.html create mode 100644 staff/lucas-orts/stuff/react/demo/main.js rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/createPost.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/deletePost.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/getAllPosts.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/getUserName.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/getUserUsername.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/loginUser.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/logoutUser.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/registerUser.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/logic/updatePostCaption.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/utils/formatTime.js (100%) rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/utils/generateId.js (100%) create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/Component.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/components/Button.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/components/Form.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/components/Link.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/components/Paragraph.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/home/components/Header.js rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/views/home/index.css (67%) create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/home/index.html rename staff/lucas-orts/{ponies/app => stuff/zzz/app copy}/views/home/index.js (64%) create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/login/index.css create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/login/index.html create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/login/index.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/register/index.css create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/register/index.html create mode 100644 staff/lucas-orts/stuff/zzz/app copy/views/register/index.js create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/deletePost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/findPost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/findPosts.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/findUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/index.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/insertPost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/insertUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/updatePost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/data/updateUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/createPost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/deletePost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFavPosts.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFollowingUserPosts.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/getAllPosts.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/getUserName.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/getUserUsername.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/index.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/loginUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/logoutUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/registerUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFavPost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFollowUser.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/toggleLikePost.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/logic/updatePostCaption.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/util/formatTime.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/util/generateId.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/Component.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.css create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Form.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Heading.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Image.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Input.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Label.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Link.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/components/Paragraph.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FavPostList.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FollowingUserPostList.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Footer.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Header.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Post.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/components/PostList.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/index.css create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/index.html create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/home/index.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/login/index.css create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/login/index.html create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/login/index.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/register/index.css create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/register/index.html create mode 100644 staff/lucas-orts/stuff/zzz/app copy2/views/register/index.mjs create mode 100644 staff/lucas-orts/stuff/zzz/app1/home.html create mode 100644 staff/lucas-orts/stuff/zzz/app1/login.html create mode 100644 staff/lucas-orts/stuff/zzz/app1/register.html create mode 100644 staff/lucas-orts/stuff/zzz/app2/home.html create mode 100644 staff/lucas-orts/stuff/zzz/app2/login.html create mode 100644 staff/lucas-orts/stuff/zzz/app2/register.html create mode 100644 staff/lucas-orts/stuff/zzz/app3/home.html create mode 100644 staff/lucas-orts/stuff/zzz/app3/login.html diff --git a/staff/lucas-orts/playground/Array/Array.prototype.at.test.js b/staff/lucas-orts/playground/Array/Array.prototype.at.test.js deleted file mode 100644 index 52dabdd45..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.at.test.js +++ /dev/null @@ -1,39 +0,0 @@ -console.info('TEST Array.prototye.at') - -console.info('CASE element a positive index') - -var nums = [5, 12, 8, 130, 44] -var num = nums.at(3) - -console.assert(num === 130, 'num is 130') - - -console.info('CASE element at index 0') - -var nums = [5, 12, 8, 130, 44] -var num = nums.at(0) - -console.assert(num === 5, 'num is 5') - - -console.info('CASE element a negative index') - -var nums = [5, 12, 8, 130, 44] -var num = nums.at(-3) - -console.assert(num === 8, 'num i 8') - - -console.info('CASE element a positive index greater than length') - -var nums = [5, 12, 8, 130, 44] -var num = nums.at(100) - -console.assert(num === undefined, 'num is undefined') - -console.info('CASE element a negative index greater than -length') - -var nums = [5, 12, 8, 130, 44] -var num = nums.at(-100) - -console.assert(num === undefined, 'num is undefined') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.concat.test.js b/staff/lucas-orts/playground/Array/Array.prototype.concat.test.js deleted file mode 100644 index 6582a2465..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.concat.test.js +++ /dev/null @@ -1,42 +0,0 @@ -console.info('TEST Array.prototype.concat') - -console.info('CASE concat elements from two arrays') - -var chars1 = ['a', 'b', 'c'] -var chars2 = ['d', 'e', 'f'] - -var chars3 = chars1.concat(chars2) - -console.assert(chars3.length === 6, 'chars3 length is 6') - -console.assert(chars3[0] === 'a', 'chars3 at 0 is a') -console.assert(chars3[1] === 'b', 'chars3 at 1 is b') -console.assert(chars3[2] === 'c', 'chars3 at 2 is c') -console.assert(chars3[3] === 'd', 'chars3 at 3 is d') -console.assert(chars3[4] === 'e', 'chars3 at 4 is e') -console.assert(chars3[5] === 'f', 'chars3 at 3 is f') - - -console.info('CASE concat elements from 5 arrays') - - -var nums1 = [10, 20, 30] -var nums2 = [400, 500] -var nums3 = [-60, -70] -var nums4 = [800, 900] -var nums5 = [-1000] - -var nums6 = nums1.concat(nums2, nums3, nums4, nums5) - -console.assert(nums6.length === 10, 'nums6 length is 10') - -console.assert(nums6[0] === 10, 'nums6 at 0 is 10') -console.assert(nums6[1] === 20, 'nums6 at 1 is 20') -console.assert(nums6[2] === 30, 'nums6 at 2 is 30') -console.assert(nums6[3] === 400, 'nums6 at 3 is 400') -console.assert(nums6[4] === 500, 'nums6 at 4 is 500') -console.assert(nums6[5] === -60, 'nums6 at 5 is -60') -console.assert(nums6[6] === -70, 'nums6 at 6 is -70') -console.assert(nums6[7] === 800, 'nums6 at 7 is 800') -console.assert(nums6[8] === 900, 'nums6 at 8 is 900') -console.assert(nums6[9] === -1000, 'nums6 at 9 is -1000') diff --git a/staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js b/staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js deleted file mode 100644 index f6ba98c59..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.copyWithin.test.js +++ /dev/null @@ -1,42 +0,0 @@ -console.info('TEST Array.prototype.copyWithin') - -console.info('CASE copyWithin 3 parametres and target> start in array') - -var animals = ['Dodo', 'Tiger', 'Pengui', 'Leo', 'Elephant'] - -var animals2 = animals.copyWithin(3, 1, 2) - -console.assert(animals2[0] === 'Dodo', 'animals2 at 0 is Dodo') -console.assert(animals2[1] === 'Tiger', 'animals2 at 1 is Tiger') -console.assert(animals2[2] === 'Pengui', 'animals2 at 2 is Pengui') -console.assert(animals2[3] === 'Tiger', 'animals2 at 3 is Tiger') -console.assert(animals2[4] === 'Elephant', 'animals2 at 4 is Elephant') -console.assert(animals2.length === 5, 'animals2 length is 5') - -console.info('CASE copyWithin 2 parametres and target> start in array') - -var animals = ['Dodo', 'Tiger', 'Pengui', 'Leo', 'Elephant'] - -var animals2 = animals.copyWithin(3, 1) - -console.assert(animals2[0] === 'Dodo', 'animals2 at 0 is Dodo') -console.assert(animals2[1] === 'Tiger', 'animals2 at 1 is Tiger') -console.assert(animals2[2] === 'Pengui', 'animals2 at 2 is Pengui') -console.assert(animals2[3] === 'Tiger', 'animals2 at 3 is Tiger') -console.assert(animals2[4] === 'Pengui', 'animals2 at 4 is Elephant') -console.assert(animals2.length === 5, 'animals2 length is 5') - - -var animals3 = ['Dodo', 'Tiger', 'Pengui', 'Leo', 'Elephant'] - - -console.info('CASE copyWithin 3 parameters and target = 0 in Array') - -var animals4 = animals3.copyWithin(0, 1, 4) - -console.assert(animals4[0] === 'Tiger', 'animals4 at 0 is Tiger') -console.assert(animals4[1] === 'Pengui', 'animals4 at 1 is Pengui') -console.assert(animals4[2] === 'Leo', 'animals4 at 2 is Dodo') -console.assert(animals4[3] === 'Leo', 'animals4 at 3 is Dodo') -console.assert(animals4[4] === 'Elephant', 'animals4 at 4 is Elephant') -console.assert(animals4.length === 5, 'animals4 length is 5') diff --git a/staff/lucas-orts/playground/Array/Array.prototype.every.test.js b/staff/lucas-orts/playground/Array/Array.prototype.every.test.js deleted file mode 100644 index 72fc1434f..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.every.test.js +++ /dev/null @@ -1,29 +0,0 @@ -console.info('TEST Array.prototype.every') - -console.info('CASE every true in Array') - -var numeros = [1, 30, 39, 29, 10, 13] - -var isBelowThreshold = function (currentValue) { - - return currentValue < 40 - -} - -var numeros1 = numeros.every(isBelowThreshold) - -console.assert(numeros1 === true, 'isBelowThreshold is true') - - -console.info('CASE every false in Array') - -var isBelowThreshold1 = function (currentValue) { - - return currentValue < 30 - -} - -var numeros2 = numeros.every(isBelowThreshold1) - - -console.assert(numeros2 === false, 'isBelowThreshold1 is false') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.filter.test.js b/staff/lucas-orts/playground/Array/Array.prototype.filter.test.js deleted file mode 100644 index 52531196d..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.filter.test.js +++ /dev/null @@ -1,12 +0,0 @@ -console.info('TEST Array.prototype.filter') - -console.info('CASE filter word.length > 6 in Array') - -var words = new Curray['spray', 'elite', 'exuberant', 'destruction', 'present'] - -var result = words.filter((word) => word.length > 6) - -console.assert(result[0] === 'exuberant', 'rsult at 0 is exuberant') -console.assert(result[1] === 'destruction', 'rsult at 1 is destruction') -console.assert(result[2] === 'present', 'rsult at 2 is present') -console.assert(result.length === 3, 'result length is 3') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.find.test.js b/staff/lucas-orts/playground/Array/Array.prototype.find.test.js deleted file mode 100644 index cb3d45bf2..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.find.test.js +++ /dev/null @@ -1,9 +0,0 @@ -console.info('TEST Array.prototype.find') - -console.info('CASE find in array') - -var numbers = [5, 12, 8, 130, 44] - -var found = numbers.find((element) => element > 10) - -console.assert(found === 12, 'found is 12') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js b/staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js deleted file mode 100644 index cf6bf0374..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.forEach.test.js +++ /dev/null @@ -1,67 +0,0 @@ -console.info('TEST Array.prototype.forEach') - -console.info('CASE copy chars into new array') - -var chars = ['a', 'b', 'c'] -var copy = [] - -chars.forEach(function (element) { - copy[copy.length] = element -}) - -console.assert(copy.length === chars.length, 'copy length equals chars length') -console.assert(copy[0] === chars[0], 'copy at 0 equals chars at 0') -console.assert(copy[1] === chars[1], 'copy at 1 equals chars at 1') -console.assert(copy[2] === chars[2], 'copy at 2 equals chars at 2') - -console.info('CASE copy chars with index and self-reference into new array') - -var chars = ['a', 'b', 'c'] -var copy = [] - -var indexes = [] -var arrays = [] - -chars.forEach(function (element, index, array) { - copy[copy.length] = element - indexes[indexes.length] = index - arrays[arrays.length] = array -}) - -console.assert(copy.length === chars.length, 'copy length equals chars length') - -console.assert(copy[0] === chars[0], 'copy at 0 equals chars at 0') -console.assert(indexes[0] === 0, 'indexes at 0 equals 0') -console.assert(arrays[0] === chars, 'arrays at 0 equals chars') - -console.assert(copy[1] === chars[1], 'copy at 1 equals chars at 1') -console.assert(indexes[1] === 1, 'indexes at 1 equals 1') -console.assert(arrays[1] === chars, 'arrays at 1 equals chars') - -console.assert(copy[2] === chars[2], 'copy at 2 equals chars at 2') -console.assert(indexes[2] === 2, 'indexes at 2 equals 2') -console.assert(arrays[2] === chars, 'arrays at 2 equals chars') - -console.info('CASE calculate percentages') - -var amounts = [100, 50, 4, 450, 100, 2000] -var results = [] - -amounts.forEach(function (amount, index, amounts) { - var total = 0 - - amounts.forEach(function (amount) { - total += amount - }) - - results[index] = amount / total * 100 -}) - -console.assert(results.length === amounts.length, 'results length equals amounts length') - -console.assert(results[0] === 3.698224852071006, 'results at 0 is 3.698224852071006') -console.assert(results[1] === 1.849112426035503, 'results at 1 is 1.849112426035503') -console.assert(results[2] === 0.14792899408284024, 'results at 2 is 0.14792899408284024') -console.assert(results[3] === 16.642011834319526, 'results at 3 is 16.642011834319526') -console.assert(results[4] === 3.698224852071006, 'results at 4 is 3.698224852071006') -console.assert(results[5] === 73.96449704142012, 'results at 5 is 73.96449704142012') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.includes.test.js b/staff/lucas-orts/playground/Array/Array.prototype.includes.test.js deleted file mode 100644 index a050f3666..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.includes.test.js +++ /dev/null @@ -1,28 +0,0 @@ -console.info('TEST Array.prototype.includes') - -console.info('CASE includes in array') - -var numeros = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] - -var numeros1 = numeros.includes(6) - -var numeros2 = numeros.includes(50) - -console.assert(numeros1 === true, 'numeros1 includes 6') -console.assert(numeros2 === false, 'numeros2 do not includes 50') - -console.info('TEST array includes color from index') - -var colors = ['red', 'green', 'blue', 'yellow', 'orange', 'pink', 'skyblue', 'red', 'white', 'black', 'grey'] - -var included = colors.includes('pink', 2) - -console.assert(included === true, 'included includes pink') - -var included = colors.includes('red', 4) - -console.assert(included === true, 'included includes red') - -var included = colors.includes('red', 8) - -console.assert(included === false, 'included does not include red') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js b/staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js deleted file mode 100644 index 61b05ca6f..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.indexOf.test.js +++ /dev/null @@ -1,19 +0,0 @@ -console.info('TEST Array.prototype.indexOf') - -console.info('CASE indexOf in array') - -var animals = ['ant', 'bison', 'camel', 'duck', 'bison'] - -var animals1 = animals.indexOf('ant') -var animals2 = animals.indexOf('bison') -var animals3 = animals.indexOf('camel', 1) -var animals4 = animals.indexOf('giraffa') -var animals5 = animals.indexOf('ant', -5) -var animals6 = animals.indexOf('bison', 2) - -console.assert(animals1 === 0, 'animals1 is 0') -console.assert(animals2 === 1, 'animals2 is 1') -console.assert(animals3 === 2, 'animals3 is 2') -console.assert(animals4 === -1, 'animals4 is -1') -console.assert(animals5 === 0, 'animals5 is 0') -console.assert(animals6 === 4, 'animals6 is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.join.test.js b/staff/lucas-orts/playground/Array/Array.prototype.join.test.js deleted file mode 100644 index 279c34121..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.join.test.js +++ /dev/null @@ -1,38 +0,0 @@ -console.info('TEST Array.prototype.join') - -console.info('CASE join in array') - -var animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo', 'Elephant'] - -console.assert(animals[0] === 'Dodo', 'animal at 0 is Dodo') -console.assert(animals[1] === 'Tiger', 'animal at 1 is Tiger') -console.assert(animals[2] === 'Penguin', 'animal at 2 is Penguin') -console.assert(animals[3] === 'Dodo', 'animal at 3 is Dodo') -console.assert(animals[4] === 'Elephant', 'animal at 4 is Elephant') -console.assert(animals.length === 5, 'animals length is 5') - -var animals2 = animals.join() -var animals22 = 'Dodo,Tiger,Penguin,Dodo,Elephant' - -console.assert(animals2 === animals22, 'animals2 is equal to animals22') - - -var animals3 = animals.join(" + ") -var animals33 = 'Dodo + Tiger + Penguin + Dodo + Elephant' - -console.assert(animals3 === animals33, 'animals3 ie equal to animals33') - -var animals4 = animals.join("/") -var animals44 = 'Dodo/Tiger/Penguin/Dodo/Elephant' - -console.assert(animals4 === animals44, 'animals4 is equal to animals44') - - -console.info('CASE join elements with separator $') - -var things = [true, 'hello world', 100, { name: 'Oswald' }, [10, 20, 30], function () { }] - -var joined = things.join(' $ ') -var joined1 = 'true $ hello world $ 100 $ [object Object] $ 10,20,30 $ function () { }' - -console.assert(joined === joined1, 'joined is equal to joined1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js b/staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js deleted file mode 100644 index 4010d8440..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.lastIndexOf.test.js +++ /dev/null @@ -1,17 +0,0 @@ -console.info('TEST Array.prototype.lastIndexOf') - -console.info('CASE lastIndexOf in array') - -var animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo', 'Elephant'] - -var animals1 = animals.lastIndexOf('Penguin') -var animals2 = animals.lastIndexOf('Dodo') -var animals3 = animals.lastIndexOf('Dodo', 1) -var animals4 = animals.lastIndexOf('Giraffa') -var animals5 = animals.lastIndexOf('Tiger', -4) - -console.assert(animals1 === 2, 'animals1 is 2') -console.assert(animals2 === 3, 'animals2 is 3') -console.assert(animals3 === 0, 'animals3 is 0') -console.assert(animals4 === -1, 'animals4 is -1') -console.assert(animals5 === 1, 'animals5 is 1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.map.test.js b/staff/lucas-orts/playground/Array/Array.prototype.map.test.js deleted file mode 100644 index 0ec658aa4..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.map.test.js +++ /dev/null @@ -1,13 +0,0 @@ -console.info('TEST Array.prototype.map') - -console.info('CASE map in array') - -var numeros = [1, 4, 9, 16] - -var map1 = numeros.map((x) => x * 2) - -console.assert(map1[0] === 2, 'map1 at 0 is 2') -console.assert(map1[1] === 8, 'map1 at 1 is 8') -console.assert(map1[2] === 18, 'map1 at 2 is 18') -console.assert(map1[3] === 32, 'map1 at 3 is 32') -console.assert(map1.length === 4, 'map1 length is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.prototype.pop.test.js b/staff/lucas-orts/playground/Array/Array.prototype.pop.test.js deleted file mode 100644 index 090484a95..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.pop.test.js +++ /dev/null @@ -1,32 +0,0 @@ -console.info('TEST pop') - -console.info('CASE pop the last element from array') - -var cars = new Array - -cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } -cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } -cars[2] = { brand: 'fiat', model: '500', year: 2017 } - -var car0 = cars[0] -var car1 = cars[1] -var car2 = cars[2] - -var last = cars.pop() - -console.assert(cars.length === 2, 'cars length is 2') - -console.assert(cars[0] === car0, 'cars at 0 is car0') -console.assert(cars[0].brand === 'ferrari', 'cars at 0 brand is ferrari') -console.assert(cars[0].model === 'gto', 'cars at 0 model is gto') -console.assert(cars[0].year === 1990, 'cars at 0 year is 1990') - -console.assert(cars[1] === car1, 'cars at 1 is car1') -console.assert(cars[1].brand === 'lamborghini', 'cars at 1 brand is lamborghini') -console.assert(cars[1].model === 'murcielago', 'cars at 1 model is murcielago') -console.assert(cars[1].year === 2010, 'cars at 1 year is 2010') - -console.assert(last === car2, 'last is car2') -console.assert(last.brand === 'fiat', 'last brand is fiat') -console.assert(last.model === '500', 'last model is 500') -console.assert(last.year === 2017, 'last year is 2017') diff --git a/staff/lucas-orts/playground/Array/Array.prototype.push.test.js b/staff/lucas-orts/playground/Array/Array.prototype.push.test.js deleted file mode 100644 index 6015b18dd..000000000 --- a/staff/lucas-orts/playground/Array/Array.prototype.push.test.js +++ /dev/null @@ -1,27 +0,0 @@ -console.info('TEST push') - -console.info('CASE push an element to array') - -var cars = new Array - -cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } -cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } -cars[2] = { brand: 'fiat', model: '500', year: 2017 } - -var newCar = { brand: 'ford', model: 'fiesta', year: 2005 } -var count = cars.push(newCar) - -console.assert(cars[3] === newCar, 'cars at 4 is newCar') -console.assert(cars.length === 4, 'cars length is 4') -console.assert(count === 4, 'count is 4') - -console.info('CASE push multiple elements to array') - -var animals = ['pigs', 'goats', 'sheep', 'cows'] -var count = animals.push('chickens', 'cats', 'dogs') - -console.assert(animals[4] === 'chickens', 'animals at 4 is chickens') -console.assert(animals[5] === 'cats', 'animals at 5 is cats') -console.assert(animals[6] === 'dogs', 'animals at 6 is dogs') -console.assert(animals.length === 7, 'animals length is 7') -console.assert(count === 7, 'count is 7') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Array/Array.test.js b/staff/lucas-orts/playground/Array/Array.test.js deleted file mode 100644 index 711437a51..000000000 --- a/staff/lucas-orts/playground/Array/Array.test.js +++ /dev/null @@ -1,46 +0,0 @@ -console.info('TEST constructor') - -console.info('CASE builds a new instance of Array') - -var a = new Array // new Array() // [] - -console.assert(a instanceof Array, 'a is an Array') -console.assert(a instanceof Object, 'a is an Object') - - -console.info('CASE builds a new Array with values') - -var a = new Array(10, 20, 30) // [10, 20, 30] - -console.assert(a instanceof Array, 'a is an Array') -console.assert(a[0] === 10, 'a at 0 is 10') -console.assert(a[1] === 20, 'a at 1 is 20') -console.assert(a[2] === 30, 'a at 2 is 30') -console.assert(a.length === 3, 'a length is 3') - - -console.info('CASE builds a new Array with only one numeric argument') - -var a = new Array(10) - -console.assert(a instanceof Array, 'a is an Array') -console.assert(a.length === 10, 'a length is 10') - - -console.info('CASE builds a new Array with only one non-numeric argument') - -var a = new Array('hola mundo') - -console.assert(a instanceof Array, 'a is an Array') -console.assert(a[0] === 'hola mundo', 'a at 0 is hola mundo') -console.assert(a.length === 1, 'a length is 1') - - -console.info('CASE builds a new Array with two values') - -var a = new Array(10, 20) - -console.assert(a instanceof Array, 'a is an Array') -console.assert(a[0] === 10, 'a at 0 is 10') -console.assert(a[1] === 20, 'a at 1 is 20') -console.assert(a.length === 2, 'a length is 2') diff --git a/staff/lucas-orts/playground/Curray/Curray.js b/staff/lucas-orts/playground/Curray/Curray.js deleted file mode 100644 index e4c822f6c..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.js +++ /dev/null @@ -1,15 +0,0 @@ -function Curray() { - if (arguments.length === 1 && typeof arguments[0] === 'number') { - this.length = arguments[0] - } - else { - for (var i = 0; i < arguments.length; i++) { - var argument = arguments[i] - this[i] = argument - } - - this.length = arguments.length - } - -} -module.exports = Curray \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.at.js b/staff/lucas-orts/playground/Curray/Curray.prototype.at.js deleted file mode 100644 index 828586098..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.at.js +++ /dev/null @@ -1,10 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.at = function (index) { - if (index > -1) { - return this[index] - } - else { - return this[this.length + index] - } -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js deleted file mode 100644 index 8ada1b0bb..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.at.test.js +++ /dev/null @@ -1,43 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.at') - -console.info('Test Curray.prototype.at') - -console.info('CASE element a positive index') - -var nums = new Curray(5, 12, 8, 130, 44) -var num = nums.at(3) - -console.assert(num === 130, 'num is 130') - - -console.info('CASE element at index 0') - -var nums = new Curray(5, 12, 8, 130, 44) -var num = nums.at(0) - -console.assert(num === 5, 'num is 5') - - -console.info('CASE element a negative index') - -var nums = new Curray(5, 12, 8, 130, 44) -var num = nums.at(-3) - -console.assert(num === 8, 'num is 8') - - -console.info('CASE element a positive index greater than length') - -var num = new Curray(5, 12, 8, 130, 44) -var num = nums.at(100) - -console.assert(num === undefined, 'num is undefined') - - -console.info('CASE element a negative index greater than -length') - -var num = new Curray(5, 12, 8, 130, 44) -var num = nums.at(-100) - -console.assert(num === undefined, 'num is undefined') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.concat.js b/staff/lucas-orts/playground/Curray/Curray.prototype.concat.js deleted file mode 100644 index 74b8e4d03..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.concat.js +++ /dev/null @@ -1,29 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.concat = function () { - - var newObject = { length: 0 } - - for (var i = 0; i < this.length; i++) { - var elem = this[i] - - newObject[newObject.length++] = elem - } - - for (var i = 0; i < arguments.length; i++) { - - var argument = arguments[i] - - for (var j = 0; j < argument.length; j++) { - - var elem = argument[j] - - newObject[newObject.length++] = elem - - } - - } - - return newObject - -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js deleted file mode 100644 index 722199346..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.concat.test.js +++ /dev/null @@ -1,44 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.concat') - -console.info('TEST Curray.prototype.concat') - -console.info('CASE concat elements from two Currays') - -var chars1 = new Curray('a', 'b', 'c') -var chars2 = new Curray('d', 'e', 'f') - -var chars3 = chars1.concat(chars2) - -console.assert(chars3.length === 6, 'chars3 length is 6') - -console.assert(chars3[0] === 'a', 'chars3 at 0 is a') -console.assert(chars3[1] === 'b', 'chars3 at 1 is b') -console.assert(chars3[2] === 'c', 'chars3 at 2 is c') -console.assert(chars3[3] === 'd', 'chars3 at 3 is d') -console.assert(chars3[4] === 'e', 'chars3 at 4 is e') -console.assert(chars3[5] === 'f', 'chars3 at 3 is f') - - -console.info('CASE concat elements from 5 Currays') - -var nums1 = new Curray(10, 20, 30) -var nums2 = new Curray(400, 500) -var nums3 = new Curray(-60, -70) -var nums4 = new Curray(800, 900) -var nums5 = new Curray("-1000") - -var nums6 = nums1.concat(nums2, nums3, nums4, nums5) - -console.assert(nums6.length === 10, 'nums6 length is 10') - -console.assert(nums6[0] === 10, 'nums6 at 0 is 10') -console.assert(nums6[1] === 20, 'nums6 at 1 is 20') -console.assert(nums6[2] === 30, 'nums6 at 2 is 30') -console.assert(nums6[3] === 400, 'nums6 at 3 is 400') -console.assert(nums6[4] === 500, 'nums6 at 4 is 500') -console.assert(nums6[5] === -60, 'nums6 at 5 is -60') -console.assert(nums6[6] === -70, 'nums6 at 6 is -70') -console.assert(nums6[7] === 800, 'nums6 at 7 is 800') -console.assert(nums6[8] === 900, 'nums6 at 8 is 900') -console.assert(nums6[9] === "-1000", 'nums6 at 9 is -1000') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js b/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js deleted file mode 100644 index 7cdbc9ab6..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.js +++ /dev/null @@ -1,45 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.copyWithin = function (target, start, end) { - if (end === undefined || end > this.length) { - end = this.length - } - - else if (end < 0) { - end = this.length + end - } - - else if (end < -this.length) { - end = 0 - } - - if (start < 0) { - start = this.length + start - } - else if (start < -this.length) { - start = 0 - } - - if (end <= start) { - return this - } - - if (target < 0) { - target = this.length + target - } - - else if (target < -this.length) { - target = 0 - } - - else if (target > this.length) { - return this - } - - var temporal = target; - for (var i = start; i < end; i++) { - this[temporal] = this[i] - temporal++ - } - return this -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js deleted file mode 100644 index d410267de..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.copyWithin.test.js +++ /dev/null @@ -1,59 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.copyWithin') - -console.info('TEST Curray.prototype.copyWithin') - -console.info('CASE copyWithin 3 parameters and target> start in Curray') - -var animals = new Curray - -animals[0] = 'Dodo' -animals[1] = 'Tiger' -animals[2] = 'Pengui' -animals[3] = 'Leo' -animals[4] = 'Elephant' -animals.length = 5 - -var animals2 = animals.copyWithin(3, 1, 2) - - -console.info('CASE copyWithin 2 parameters and target> start in Curray') - -var animals = new Curray - -animals[0] = 'Dodo' -animals[1] = 'Tiger' -animals[2] = 'Pengui' -animals[3] = 'Leo' -animals[4] = 'Elephant' -animals.length = 5 - -var animals2 = animals.copyWithin(3, 1) - -console.assert(animals2[0] === 'Dodo', 'animals2 at 0 is Dodo') -console.assert(animals2[1] === 'Tiger', 'animals2 at 1 is Tiger') -console.assert(animals2[2] === 'Pengui', 'animals2 at 2 is Pengui') -console.assert(animals2[3] === 'Tiger', 'animals2 at 3 is Tiger') -console.assert(animals2[4] === 'Pengui', 'animals2 at 4 is Elephant') -console.assert(animals2.length === 5, 'animals2 length is 5') - -var animals3 = new Curray - -animals3[0] = 'Dodo' -animals3[1] = 'Tiger' -animals3[2] = 'Pengui' -animals3[3] = 'Leo' -animals3[4] = 'Elephant' -animals3.length = 5 - - -console.info('CASE copyWithin 3 parameters and target = 0 in Curray') - -var animals4 = animals3.copyWithin(0, 1, 4) - -console.assert(animals4[0] === 'Tiger', 'animals4 at 0 is Tiger') -console.assert(animals4[1] === 'Pengui', 'animals4 at 1 is Pengui') -console.assert(animals4[2] === 'Leo', 'animals4 at 2 is Dodo') -console.assert(animals4[3] === 'Leo', 'animals4 at 3 is Dodo') -console.assert(animals4[4] === 'Elephant', 'animals4 at 4 is Elephant') -console.assert(animals4.length === 5, 'animals4 length is 5') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.every.js b/staff/lucas-orts/playground/Curray/Curray.prototype.every.js deleted file mode 100644 index 6236db6f7..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.every.js +++ /dev/null @@ -1,16 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.every = function (callback) { - - for (var i = 0; i < this.length; i++) { - - // if (callback(this[i]) === false) - if (!callback(this[i])) { - return false - } - - } - - return true - -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js deleted file mode 100644 index 4207fed01..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.every.test.js +++ /dev/null @@ -1,33 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.every') - - -console.info('TEST Curray.prototype.every') - -console.info('CASE every true in Curray') - -var numeros = new Curray(1, 30, 39, 29, 10, 13) - -var isBelowThreshold = function (currentValue) { - - return currentValue < 40 - -} - -var numeros1 = numeros.every(isBelowThreshold) - -console.assert(numeros1 === true, 'isBelowThreshold is true') - - -console.info('CASE every false in Curray') - -var isBelowThreshold1 = function (currentValue) { - - return currentValue < 30 - -} - -var numeros2 = numeros.every(isBelowThreshold1) - - -console.assert(numeros2 === false, 'isBelowThreshold1 is false') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.filter.js b/staff/lucas-orts/playground/Curray/Curray.prototype.filter.js deleted file mode 100644 index 324fd5754..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.filter.js +++ /dev/null @@ -1,18 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.filter = function (callbackFunction) { - var newObject = new Curray - - for (var i = 0; i < this.length; i++) { - - if (callbackFunction(this[i], i, this)) { - - newObject[newObject.length++] = this[i] - - } - - } - - return newObject - -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js deleted file mode 100644 index 1218408be..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.filter.test.js +++ /dev/null @@ -1,16 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.filter') - - -console.info('TEST Curray.prototype.filter') - -console.info('CASE filter word.length > 6 in Curray') - -var words = new Curray('spray', 'elite', 'exuberant', 'destruction', 'present') - -var result = words.filter((word) => word.length > 6) - -console.assert(result[0] === 'exuberant', 'rsult at 0 is exuberant') -console.assert(result[1] === 'destruction', 'rsult at 1 is destruction') -console.assert(result[2] === 'present', 'rsult at 2 is present') -console.assert(result.length === 3, 'result length is 3') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.find.js b/staff/lucas-orts/playground/Curray/Curray.prototype.find.js deleted file mode 100644 index 723f8ca0a..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.find.js +++ /dev/null @@ -1,15 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.find = function (callbackFunction) { - - for (var i = 0; i < this.length; i++) { - - if (callbackFunction(this[i], i, this)) - - return this[i] - - } - - return undefined - -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js deleted file mode 100644 index b2549c56a..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.find.test.js +++ /dev/null @@ -1,18 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.find') - - -console.info('TEST Curray.prototype.find') - -console.info('CASE find in curray') - -var numbers = new Curray(5, 12, 8, 130, 44) - -var found = numbers.find((element) => element > 10) -console.assert(found === 12, 'found is 12') - -var found = numbers.find((element) => element > 100) -console.assert(found === 130, 'found is 130') - -var found = numbers.find((element) => element > 130) -console.assert(found === undefined, 'found is undefined') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js b/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js deleted file mode 100644 index 06753ed36..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.js +++ /dev/null @@ -1,11 +0,0 @@ -var Curray = ('./Curray') - -Curray.prototype.forEach = function (callback) { - for (var i = 0; i < this.length; i++) { - var elem = this[i] - - callback(elem) - - // callback(this[i]) - } -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js deleted file mode 100644 index 0af04c1eb..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.forEach.test.js +++ /dev/null @@ -1,19 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.forEach') - -onsole.info('TEST Array.prototype.forEach') - -console.info('CASE forEach in array') - -var chars = new Curray('a', 'b', 'c') -var copy = new Curray - -var chars1 = chars.forEach(function (element) { - copy[copy.length] = element - -}) - -console.assert(copy.length === chars1.length, 'copy length equals chars length') -console.assert(copy[0] === chars1[0], 'copy at 0 equals at 0') -console.assert(copy[1] === chars1[1], 'copy at 1 equals at 1') -console.assert(copy[2] === chars1[2], 'copy at 2 equals at 2') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.includes.js b/staff/lucas-orts/playground/Curray/Curray.prototype.includes.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js deleted file mode 100644 index 9cd83c555..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.includes.test.js +++ /dev/null @@ -1,59 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.includes') - -console.info('TEST Curray.prototype.includes') - -console.info('CASE includes in Curray') - -var numeros = new Curray - -numeros[0] = 1 -numeros[1] = 2 -numeros[2] = 3 -numeros[3] = 4 -numeros[4] = 5 -numeros[5] = 6 -numeros[6] = 7 -numeros[7] = 8 -numeros[8] = 9 -numeros[9] = 10 -numeros.length = 10 - -var numeros1 = numeros.includes(6) - -var numeros2 = numeros.includes(50) - -console.assert(numeros1 === true, 'numeros1 includes 6') -console.assert(numeros2 === false, 'numeros2 do not includes 50') - - -console.info('TEST Curray includes color from index') - -var colors = new Curray - -colors[0] = 'red' -colors[1] = 'green' -colors[2] = 'blue' -colors[3] = 'yellow' -colors[4] = 'orange' -colors[5] = 'pink' -colors[6] = 'skyblue' -colors[7] = 'red' -colors[8] = 'white' -colors[9] = 'black' -colors[10] = 'grey' -colors.length = 11 - -var colors = ['red', 'green', 'blue', 'yellow', 'orange', 'pink', 'skyblue', 'red', 'white', 'black', 'grey'] - -var included = colors.includes('pink', 2) - -console.assert(included === true, 'included includes pink') - -var included = colors.includes('red', 4) - -console.assert(included === true, 'included includes red') - -var included = colors.includes('red', 8) - -console.assert(included === false, 'included does not include red') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js b/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js deleted file mode 100644 index 983a3862b..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.js +++ /dev/null @@ -1,24 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.indexOf = function (searchElement, fromIndex) { - - if (fromIndex === undefined) - fromIndex = 0 - - else if (fromIndex < 0) { - fromIndex = this.length + fromIndex - - if (fromIndex < 0) - fromIndex = 0 - } - - for (var i = fromIndex; i < this.length; i++) { - var element = this[i] - - if (searchElement === element) - return i - } - - return -1 - -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js deleted file mode 100644 index 8dbb8ced0..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.indexOf.test.js +++ /dev/null @@ -1,30 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.indexOf') - - -console.info('TEST Curray.prototype.indexOf') - -console.info('CASE indexOf in Curray') - -var animals = new Curray - -animals[0] = 'ant' -animals[1] = 'bison' -animals[2] = 'camel' -animals[3] = 'duck' -animals[4] = 'bison' -animals.length = 5 - -var animals1 = animals.indexOf('ant') -var animals2 = animals.indexOf('bison') -var animals3 = animals.indexOf('camel', 1) -var animals4 = animals.indexOf('giraffa') -var animals5 = animals.indexOf('ant', -5) -var animals6 = animals.indexOf('bison', 2) - -console.assert(animals1 === 0, 'animals1 is 0') -console.assert(animals2 === 1, 'animals2 is 1') -console.assert(animals3 === 2, 'animals3 is 2') -console.assert(animals4 === -1, 'animals4 is -1') -console.assert(animals5 === 0, 'animals5 is 0') -console.assert(animals6 === 4, 'animals6 is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.join.js b/staff/lucas-orts/playground/Curray/Curray.prototype.join.js deleted file mode 100644 index 16a6b4597..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.join.js +++ /dev/null @@ -1,20 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.join = function (separator) { - if (separator === undefined) - separator = ',' - - var res = "" - - for (var i = 0; i < this.length; i++) { - var elem = this[i] - - res += elem - - if (i < this.length - 1) - res += separator - - } - - return res -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js deleted file mode 100644 index a68e79d7a..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.join.test.js +++ /dev/null @@ -1,48 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.join') - -console.info('TEST Curray.prototype.join') - -console.info('CASE join in Curray') - -var animals = new Curray - -animals[0] = 'Dodo' -animals[1] = 'Tiger' -animals[2] = 'Penguin' -animals[3] = 'Dodo' -animals[4] = 'Elephant' -animals.length = 5 - -var animals2 = animals.join() -var animals22 = 'Dodo,Tiger,Penguin,Dodo,Elephant' - -console.assert(animals2 === animals22, 'animals2 is equal to animals22') - -var animals3 = animals.join(" + ") -var animals33 = 'Dodo + Tiger + Penguin + Dodo + Elephant' - -console.assert(animals3 === animals33, 'animals3 ie equal to animals33') - -var animals4 = animals.join("/") -var animals44 = 'Dodo/Tiger/Penguin/Dodo/Elephant' - -console.assert(animals4 === animals44, 'animals4 is equal to animals44') - - -console.info('CASE join elements with separator $') - -var things = new Curray - -things[0] = true -things[1] = 'hello world' -things[2] = 100 -things[3] = { name: 'Oswald' } -things[4] = [10, 20, 30] -things[5] = function () { } -things.length = 6 - -var joined = things.join(' $ ') -var joined1 = 'true $ hello world $ 100 $ [object Object] $ 10,20,30 $ function () { }' - -console.assert(joined === joined1, 'joined is equal to joined1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js b/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js deleted file mode 100644 index b3d49f22f..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.js +++ /dev/null @@ -1,17 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.lastIndexOf = function (searchElement, fromIndex) { - - if (fromIndex === undefined) - fromIndex = this.length - 1 - - else if (fromIndex < 0) - fromIndex = this.length + fromIndex - - for (var i = fromIndex; i > -1; i--) { - var element = this[i] - if (searchElement === element) - return i - } - return -1 -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js deleted file mode 100644 index dc21e5c9f..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.lastIndexOf.test.js +++ /dev/null @@ -1,21 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.lastIndexOf') - - -console.info('TEST Curray.prototype.lastIndexOf') - -console.info('CASE lastIndexOf in array') - -var animals = ['Dodo', 'Tiger', 'Penguin', 'Dodo', 'Elephant'] - -var animals1 = animals.lastIndexOf('Penguin') -var animals2 = animals.lastIndexOf('Dodo') -var animals3 = animals.lastIndexOf('Dodo', 1) -var animals4 = animals.lastIndexOf('Giraffa') -var animals5 = animals.lastIndexOf('Tiger', -4) - -console.assert(animals1 === 2, 'animals1 is 2') -console.assert(animals2 === 3, 'animals2 is 3') -console.assert(animals3 === 0, 'animals3 is 0') -console.assert(animals4 === -1, 'animals4 is -1') -console.assert(animals5 === 1, 'animals5 is 1') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.map.js b/staff/lucas-orts/playground/Curray/Curray.prototype.map.js deleted file mode 100644 index b0d0456d8..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.map.js +++ /dev/null @@ -1,14 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.map = function (callbackFunction) { - var newObject = { length: 0 } - - for (var i = 0; i < this.length; i++) { - - newObject[newObject.length++] = callbackFunction(this[i], i, this) - - } - - return newObject - -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js deleted file mode 100644 index 0278efb5b..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.map.test.js +++ /dev/null @@ -1,17 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.map') - - -console.info('TEST Curray.prototype.map') - -console.info('CASE map in curray') - -var numeros = new Curray(1, 4, 9, 16) - -var map1 = numeros.map((x) => x * 2) - -console.assert(map1[0] === 2, 'map1 at 0 is 2') -console.assert(map1[1] === 8, 'map1 at 1 is 8') -console.assert(map1[2] === 18, 'map1 at 2 is 18') -console.assert(map1[3] === 32, 'map1 at 3 is 32') -console.assert(map1.length === 4, 'map1 length is 4') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.pop.js b/staff/lucas-orts/playground/Curray/Curray.prototype.pop.js deleted file mode 100644 index dff594266..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.pop.js +++ /dev/null @@ -1,9 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.pop = function () { - var element = this[this.length - 1] - - delete this[--this.length] - - return element -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js deleted file mode 100644 index 206205ebd..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.pop.test.js +++ /dev/null @@ -1,36 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.pop') - -console.info('TEST pop') - -console.info('CASE pop the last element from Curray') - -var cars = new Curray - -cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } -cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } -cars[2] = { brand: 'fiat', model: '500', year: 2017 } -cars.length = 3 - -var car0 = cars[0] -var car1 = cars[1] -var car2 = cars[2] - -var last = cars.pop() - -console.assert(cars.length === 2, 'cars length is 2') - -console.assert(cars[0] === car0, 'cars at 0 is car0') -console.assert(cars[0].brand === 'ferrari', 'cars at 0 brand is ferrari') -console.assert(cars[0].model === 'gto', 'cars at 0 model is gto') -console.assert(cars[0].year === 1990, 'cars at 0 year is 1990') - -console.assert(cars[1] === car1, 'cars at 1 is car1') -console.assert(cars[1].brand === 'lamborghini', 'cars at 1 brand is lamborghini') -console.assert(cars[1].model === 'murcielago', 'cars at 1 model is murcielago') -console.assert(cars[1].year === 2010, 'cars at 1 year is 2010') - -console.assert(last === car2, 'last is car2') -console.assert(last.brand === 'fiat', 'last brand is fiat') -console.assert(last.model === '500', 'last model is 500') -console.assert(last.year === 2017, 'last year is 2017') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.push.js b/staff/lucas-orts/playground/Curray/Curray.prototype.push.js deleted file mode 100644 index a02671a50..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.push.js +++ /dev/null @@ -1,11 +0,0 @@ -var Curray = require('./Curray') - -Curray.prototype.push = function () { - for (var index = 0; index < arguments.length; index++) { - var argument = arguments[index] - - this[this.length++] = argument - } - - return this.length -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js b/staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js deleted file mode 100644 index d1c37ad89..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.prototype.push.test.js +++ /dev/null @@ -1,32 +0,0 @@ -var Curray = require('./Curray') -require('./Curray.prototype.push') - -console.info('TEST push') - -console.info('CASE push an element to Curray') - -var cars = new Curray - -cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } -cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } -cars[2] = { brand: 'fiat', model: '500', year: 2017 } -cars.length = 3 - -var newCar = { brand: 'ford', model: 'fiesta', year: 2005 } -var count = cars.push(newCar) - -console.assert(cars[3] === newCar, 'cars at 4 is newCar') -console.assert(cars.length === 4, 'cars length is 4') -console.assert(count === 4, 'count is 4') - - -console.info('CASE push multiple elements to Curray') - -var animals = new Curray('pigs', 'goats', 'sheep', 'cows') -var count = animals.push('chickens', 'cats', 'dogs') - -console.assert(animals[4] === 'chickens', 'animals at 4 is chickens') -console.assert(animals[5] === 'cats', 'animals at 5 is cats') -console.assert(animals[6] === 'dogs', 'animals at 6 is dogs') -console.assert(animals.length === 7, 'animals length is 7') -console.assert(count === 7, 'count is 7') \ No newline at end of file diff --git a/staff/lucas-orts/playground/Curray/Curray.test.js b/staff/lucas-orts/playground/Curray/Curray.test.js deleted file mode 100644 index 5dabb7962..000000000 --- a/staff/lucas-orts/playground/Curray/Curray.test.js +++ /dev/null @@ -1,40 +0,0 @@ -var Curray = require('./Curray') - -console.info('Test constructor') - -console.info('CASE builds a new instance of Curray') - -var c = new Curray // new Curray() - -console.assert(c instanceof Curray, 'c is a Curray') -console.assert(c instanceof Object, 'c is an Object') - - -console.info('CASE builds a new Curray with values') - -var c = new Curray(10, 20, 30) - -console.assert(c instanceof Curray, 'c is a Curray') -console.assert(c[0] === 10, 'c at 0 is 10') -console.assert(c[1] === 20, 'c at 1 is 20') -console.assert(c[2] === 30, 'c at 2 is 30') -console.assert(c.length === 3, 'c length is 3') - - -console.info('CASE builds a new Curray with only one numeric argument') - -var c = new Curray(10) - -console.assert(c instanceof Curray, 'c is a Curray') -console.assert(c.length == 10, 'c length is 10 ') - - -console.info('CASE builds a new Curray with only one non numeric argument') - -var c = new Curray('hola mundo') - -console.assert(c instanceof Curray, 'c is a Curray') -console.assert(c[0] === 'hola mundo', 'c at 0 is hola mundo') -console.assert(c.length === 1, 'c length is 1') - - diff --git a/staff/lucas-orts/playground/arrays/index.js b/staff/lucas-orts/playground/arrays/index.js deleted file mode 100644 index c5dfd88fb..000000000 --- a/staff/lucas-orts/playground/arrays/index.js +++ /dev/null @@ -1,55 +0,0 @@ -console.log('Test arrays') - -console.log('CASE add elements to array') - -var a = new Array - -a[0] = 10 -a[1] = 20 -a[2] = 30 - -console.log(a) -//[10, 20, 30] - -var a = new Array - -a[0] = 10 -a[1] = 20 -a[2] = 30 - -console.log(a) -//[10, 20, 30] - -//a.length= a.length - 1 -//a.length -=1 -a.length-- - -console.log(a) -//[10, 20] - -console.log('CASE remove last 2 elements from array') - -var colors = new Array -colors[0] = 'red' -colors[1] = 'green' -colors[2] = 'blue' -colors[3] = 'yellow' - - - - - -console.log('CASE push an element to array') -var cars = new Array -cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } -cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } -cars[2] = { brand: 'fiat', model: '500', year: 2017 } - -console.log(cars) - -console.log(cars.length) - -cars.push({ brand: 'ford', model: 'fiesta', year: 2005 }) - -console.log(cars) -console.log(cars.length) \ No newline at end of file diff --git a/staff/lucas-orts/playground/building/index.html b/staff/lucas-orts/playground/building/index.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/building/style.css b/staff/lucas-orts/playground/building/style.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/car/index.html b/staff/lucas-orts/playground/car/index.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/car/style.css b/staff/lucas-orts/playground/car/style.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/cv/index.html b/staff/lucas-orts/playground/cv/index.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/face/index.html b/staff/lucas-orts/playground/face/index.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/face/style.css b/staff/lucas-orts/playground/face/style.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/playground/objects/index.js b/staff/lucas-orts/playground/objects/index.js deleted file mode 100644 index 6ab2e5292..000000000 --- a/staff/lucas-orts/playground/objects/index.js +++ /dev/null @@ -1,91 +0,0 @@ -console.log('Test objects') -console.log('CASE add elements to object') - -var o = new Object // {} -o[0] = 10 -o[1] = 20 -o[2] = 30 -o.length = 3 - -console.log(o) -// { 0: 10, 1: 20, 2:30, length: 3 } - -console.log('CASE remove las element from object') - -var o = new Object - -o[0] = 10 -o[1] = 20 -o[2] = 30 -o.length = 3 - -console.log(o) -// { 0: 10, 1: 20, 2:30, length: 3 } - -delete o[2] -//o.length = o.length - 1 -// o.length -= 1 -o.length-- - -console.log(o) -// { 0: 10, 1: 20, length: 2} - -console.log('CASE remove last 2 elements from object') - -var colors = new Object - -colors[0] = 'red' -colors[1] = "green" -colors[2] = 'blue' -colors[3] = 'yellow' -colors.length = 4 - -console.log(colors) -// { 0: red, 1: green, 2: blue, 3: yellow, length: 4} - -delete colors[3] -delete colors[2] -// colors.length = colors.length - 2 -colors.length -= 2 -console.log(colors) - -// { 0: red, 1: green, length: 2} - - -console.log('CASE push an element to object') -var cars = new Object -cars[0] = { brand: 'ferrari', model: 'gto', year: 1990 } -cars[1] = { brand: 'lamborghini', model: 'murcielago', year: 2010 } -cars[2] = { brand: 'fiat', model: '500', year: 2017 } -cars.length = 3 - -console.log(cars) - -console.log(cars.length) - -cars.push = function (element) { - this[this.length] = element - return this.length++ -} - -cars.push({ brand: 'ford', model: 'fiesta', year: 2005 }) - -console.log(cars) -// { 0: {...}, 1: {...}, 2: {...}, 3: {...}, length: 4 } -console.log(cars.length) - -//cars.pop = function () { -// delete this[this.length - 1] -// return this.length-- -//} -cars.pop = function () { - var lastElement = this[this.length - 1] - delete this[this.length - 1] - this.length-- - - return lastElement -} -console.log(cars.pop()) -console.log(cars) -// { 0: {...}, 1: {...}, 2: {...}, 3: {...}, length: 4 } -console.log(cars.length) \ No newline at end of file diff --git a/staff/lucas-orts/playground/objects/map.js b/staff/lucas-orts/playground/objects/map.js deleted file mode 100644 index f350f1521..000000000 --- a/staff/lucas-orts/playground/objects/map.js +++ /dev/null @@ -1,15 +0,0 @@ -var numbers = { 0: 1, 1: 4, 2: 9, 3: 16, length: 4 } -numbers.map = function (callbackFn) { - var newObject = { length: 0 } - for (var i = 0; i < this.length; i++) { - - newObject[newObject.length++] = callbackFn(this[i], i, this) - - } - return newObject -} - -const map1 = numbers.map((x) => x + 3); - -console.log(map1); -// Expected output: Array [4, 7, 12, 19] \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/deletePost.mjs b/staff/lucas-orts/ponies/app/data/deletePost.mjs new file mode 100644 index 000000000..8905a9d05 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/deletePost.mjs @@ -0,0 +1,13 @@ +function deletePost(condition) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const postIndex = posts.findIndex(condition) + + if (postIndex > -1) { + posts.splice(postIndex, 1) + + localStorage.posts = JSON.stringify(posts) + } +} + +export default deletePost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/findPost.mjs b/staff/lucas-orts/ponies/app/data/findPost.mjs new file mode 100644 index 000000000..1849d8bcd --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/findPost.mjs @@ -0,0 +1,9 @@ +function findPost(condition) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const post = posts.find(condition) + + return post || null +} + +export default findPost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/findPosts.mjs b/staff/lucas-orts/ponies/app/data/findPosts.mjs new file mode 100644 index 000000000..1620c18a6 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/findPosts.mjs @@ -0,0 +1,9 @@ +function findPosts(condition) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const foundPosts = posts.filter(condition) + + return foundPosts +} + +export default findPosts \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/findUser.mjs b/staff/lucas-orts/ponies/app/data/findUser.mjs new file mode 100644 index 000000000..008bc7083 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/findUser.mjs @@ -0,0 +1,9 @@ +function findUser(condition) { + const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + const user = users.find(condition) + + return user || null +} + +export default findUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/index.mjs b/staff/lucas-orts/ponies/app/data/index.mjs new file mode 100644 index 000000000..830e27f38 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/index.mjs @@ -0,0 +1,21 @@ +import deletePost from './deletePost.mjs' +import findPost from './findPost.mjs' +import findPosts from './findPosts.mjs' +import findUser from './findUser.mjs' +import insertPost from './insertPost.mjs' +import insertUser from './insertUser.mjs' +import updatePost from './updatePost.mjs' +import updateUser from './updateUser.mjs' + +const data = { + deletePost, + findPost, + findPosts, + findUser, + insertPost, + insertUser, + updatePost, + updateUser +} + +export default data \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/insertPost.mjs b/staff/lucas-orts/ponies/app/data/insertPost.mjs new file mode 100644 index 000000000..46c648c84 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/insertPost.mjs @@ -0,0 +1,9 @@ +function insertPost(post) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + posts.push(post) + + localStorage.posts = JSON.stringify(posts) +} + +export default insertPost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/insertUser.mjs b/staff/lucas-orts/ponies/app/data/insertUser.mjs new file mode 100644 index 000000000..74a40bc06 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/insertUser.mjs @@ -0,0 +1,9 @@ +function insertUser(user) { + const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + users.push(user) + + localStorage.users = JSON.stringify(users) +} + +export default insertUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/updatePost.mjs b/staff/lucas-orts/ponies/app/data/updatePost.mjs new file mode 100644 index 000000000..9ac553124 --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/updatePost.mjs @@ -0,0 +1,13 @@ +function updatePost(condition, post) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const index = posts.findIndex(condition) + + if (index > -1) { + posts.splice(index, 1, post) + + localStorage.posts = JSON.stringify(posts) + } +} + +export default updatePost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/data/updateUser.mjs b/staff/lucas-orts/ponies/app/data/updateUser.mjs new file mode 100644 index 000000000..5e3e5817a --- /dev/null +++ b/staff/lucas-orts/ponies/app/data/updateUser.mjs @@ -0,0 +1,13 @@ +function updateUser(condition, user) { + const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + const index = users.findIndex(condition) + + if (index > -1) { + users.splice(index, 1, user) + + localStorage.users = JSON.stringify(users) + } +} + +export default updateUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/createPost.mjs b/staff/lucas-orts/ponies/app/logic/createPost.mjs new file mode 100644 index 000000000..d528a0dbf --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/createPost.mjs @@ -0,0 +1,21 @@ +import data from '../data/index.mjs' + +import generateId from '../util/generateId.mjs' + +const createPost = (image, caption) => { + if (!image.startsWith('http')) + throw new Error('invalid image') + + const post = { + id: generateId(), + image: image, + caption: caption, + author: sessionStorage.username, + date: new Date().toISOString(), + likes: [] + } + + data.insertPost(post) +} + +export default createPost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/deletePost.mjs b/staff/lucas-orts/ponies/app/logic/deletePost.mjs new file mode 100644 index 000000000..f597d3ae9 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/deletePost.mjs @@ -0,0 +1,13 @@ +import data from '../data/index.mjs' + +const deletePost = postId => { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const post = data.findPost(post => post.id === postId) + + if (post === null) throw new Error('post not found') + + data.deletePost(post => post.id === postId) +} + +export default deletePost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getAllFavPosts.mjs b/staff/lucas-orts/ponies/app/logic/getAllFavPosts.mjs new file mode 100644 index 000000000..90e52d208 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getAllFavPosts.mjs @@ -0,0 +1,23 @@ +import data from '../data/index.mjs' + +const getAllFavPosts = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const posts = data.findPosts(post => user.favs.includes(post.id)) + + posts.forEach(post => { + post.fav = user.favs.includes(post.id) + post.like = post.likes.includes(sessionStorage.username) + post.author = { + username: post.author, + following: user.following.includes(post.author) + } + }) + + return posts.reverse() +} + +export default getAllFavPosts \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getAllFollowingUserPosts.mjs b/staff/lucas-orts/ponies/app/logic/getAllFollowingUserPosts.mjs new file mode 100644 index 000000000..4ab5384e6 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getAllFollowingUserPosts.mjs @@ -0,0 +1,23 @@ +import data from '../data/index.mjs' + +const getAllFollowingUserPosts = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const posts = data.findPosts(post => user.following.includes(post.author)) + + posts.forEach(post => { + post.fav = user.favs.includes(post.id) + post.like = post.likes.includes(sessionStorage.username) + post.author = { + username: post.author, + following: user.following.includes(post.author) + } + }) + + return posts.reverse() +} + +export default getAllFollowingUserPosts \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getAllPosts.mjs b/staff/lucas-orts/ponies/app/logic/getAllPosts.mjs new file mode 100644 index 000000000..e8409edf1 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getAllPosts.mjs @@ -0,0 +1,23 @@ +import data from '../data/index.mjs' + +const getAllPosts = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const posts = data.findPosts(() => true) + + posts.forEach(post => { + post.fav = user.favs.includes(post.id) + post.like = post.likes.includes(sessionStorage.username) + post.author = { + username: post.author, + following: user.following.includes(post.author) + } + }) + + return posts.reverse() +} + +export default getAllPosts \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getUserName.mjs b/staff/lucas-orts/ponies/app/logic/getUserName.mjs new file mode 100644 index 000000000..f92bd7b0d --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getUserName.mjs @@ -0,0 +1,12 @@ +import data from '../data/index.mjs' + +const getUserName = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + return user.name +} + +export default getUserName \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/getUserUsername.mjs b/staff/lucas-orts/ponies/app/logic/getUserUsername.mjs new file mode 100644 index 000000000..69e37f836 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/getUserUsername.mjs @@ -0,0 +1,3 @@ +const getUserUsername = () => sessionStorage.username + +export default getUserUsername \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/index.mjs b/staff/lucas-orts/ponies/app/logic/index.mjs new file mode 100644 index 000000000..5c0236217 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/index.mjs @@ -0,0 +1,33 @@ +import getAllPosts from './getAllPosts.mjs' +import getUserName from './getUserName.mjs' +import getUserUsername from './getUserUsername.mjs' +import loginUser from './loginUser.mjs' +import logoutUser from './logoutUser.mjs' +import registerUser from './registerUser.mjs' +import toggleLikePost from './toggleLikePost.mjs' +import updatePostCaption from './updatePostCaption.mjs' +import createPost from './createPost.mjs' +import deletePost from './deletePost.mjs' +import toggleFavPost from './toggleFavPost.mjs' +import getAllFavPosts from './getAllFavPosts.mjs' +import toggleFollowUser from './toggleFollowUser.mjs' +import getAllFollowingUserPosts from './getAllFollowingUserPosts.mjs' + +const logic = { + getAllPosts, + getUserName, + getUserUsername, + loginUser, + logoutUser, + registerUser, + toggleLikePost, + updatePostCaption, + createPost, + deletePost, + toggleFavPost, + getAllFavPosts, + toggleFollowUser, + getAllFollowingUserPosts +} + +export default logic \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/loginUser.mjs b/staff/lucas-orts/ponies/app/logic/loginUser.mjs new file mode 100644 index 000000000..3d271bb92 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/loginUser.mjs @@ -0,0 +1,21 @@ +import data from '../data/index.mjs' + +const loginUser = (username, password) => { + if (username.trim().length < 4) + throw new Error('invalid username') + + if (password.trim().length < 8) + throw new Error('invalid password') + + const user = data.findUser(user => user.username === username) + + if (user === null) + throw new Error('username does not exist') + + if (user.password !== password) + throw new Error('wrong password') + + sessionStorage.username = username +} + +export default loginUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/logoutUser.mjs b/staff/lucas-orts/ponies/app/logic/logoutUser.mjs new file mode 100644 index 000000000..cce13cc28 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/logoutUser.mjs @@ -0,0 +1,3 @@ +const logoutUser = () => delete sessionStorage.username + +export default logoutUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/registerUser.mjs b/staff/lucas-orts/ponies/app/logic/registerUser.mjs new file mode 100644 index 000000000..caf65d464 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/registerUser.mjs @@ -0,0 +1,47 @@ +import data from '../data/index.mjs' + +const EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/ + +const registerUser = (name, surname, email, username, password, passwordRepeat) => { + if (name.trim() === '') + throw new Error('invalid name') + + if (surname.trim().length < 2) + throw new Error('invalid surname') + + if (!EMAIL_REGEX.test(email)) + throw new Error('invalid email') + + if (username.trim().length < 4) + throw new Error('invalid username') + + if (password.trim().length < 8) + throw new Error('invalid password') + + if (password !== passwordRepeat) + throw new Error('passwords do not match') + + let user = data.findUser(user => user.email === email) + + if (user !== null) + throw new Error('email already exists') + + user = data.findUser(user => user.username === username) + + if (user !== null) + throw new Error('username already exists') + + user = { + name: name, + surname: surname, + email: email, + username: username, + password: password, + favs: [], + following: [] + } + + data.insertUser(user) +} + +export default registerUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/toggleFavPost.mjs b/staff/lucas-orts/ponies/app/logic/toggleFavPost.mjs new file mode 100644 index 000000000..a2ee408cb --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/toggleFavPost.mjs @@ -0,0 +1,26 @@ +import data from '../data/index.mjs' + +function toggleFavPost(postId) { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const post = data.findPost(post => post.id === postId) + + if (post === null) + throw new Error('post not found') + + const index = user.favs.indexOf(postId) + + if (index < 0) + user.favs.push(postId) + else + user.favs.splice(index, 1) + + data.updateUser(user => user.username === sessionStorage.username, user) +} + +export default toggleFavPost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/toggleFollowUser.mjs b/staff/lucas-orts/ponies/app/logic/toggleFollowUser.mjs new file mode 100644 index 000000000..2a6a77d68 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/toggleFollowUser.mjs @@ -0,0 +1,24 @@ +import data from '../data/index.mjs' + +function toggleFollowUser(username) { + if (!username.trim().length) throw new Error('invalid username') + + const user = data.findUser(user => user.username === sessionStorage.username) + + if (!user) throw new Error('user not found') + + const following = data.findUser(user => user.username === username) + + if (!following) throw new Error('following user not found') + + const index = user.following.indexOf(username) + + if (index < 0) + user.following.push(username) + else + user.following.splice(index, 1) + + data.updateUser(user => user.username === sessionStorage.username, user) +} + +export default toggleFollowUser \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/toggleLikePost.mjs b/staff/lucas-orts/ponies/app/logic/toggleLikePost.mjs new file mode 100644 index 000000000..4a4faf4a3 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/toggleLikePost.mjs @@ -0,0 +1,21 @@ +import data from '../data/index.mjs' + +function toggleLikePost(postId) { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const post = data.findPost(post => post.id === postId) + + if (post === null) + throw new Error('post not found') + + const index = post.likes.indexOf(sessionStorage.username) + + if (index < 0) + post.likes.push(sessionStorage.username) + else + post.likes.splice(index, 1) + + data.updatePost(post => post.id === postId, post) +} + +export default toggleLikePost \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/updatePostCaption.mjs b/staff/lucas-orts/ponies/app/logic/updatePostCaption.mjs new file mode 100644 index 000000000..55312dc22 --- /dev/null +++ b/staff/lucas-orts/ponies/app/logic/updatePostCaption.mjs @@ -0,0 +1,15 @@ +import data from '../data/index.mjs' + +const updatePostCaption = (postId, newCaption) => { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const post = data.findPost(post => post.id === postId) + + if (post === null) throw new Error('post not found') + + post.caption = newCaption + + data.updatePost(post => post.id === postId, post) +} + +export default updatePostCaption \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/util/formatTime.mjs b/staff/lucas-orts/ponies/app/util/formatTime.mjs new file mode 100644 index 000000000..823431980 --- /dev/null +++ b/staff/lucas-orts/ponies/app/util/formatTime.mjs @@ -0,0 +1,37 @@ +function formatTime(date) { + const seconds = Math.round((Date.now() - date.getTime()) / 1000) + + if (seconds < 60) + return seconds + ' second' + (seconds === 1 ? '' : 's') + + const minutes = Math.round(seconds / 60) + + if (minutes < 60) + return minutes + ' minute' + (minutes === 1 ? '' : 's') + + const hours = Math.round(minutes / 60) + + if (hours < 24) + return hours + ' hour' + (hours === 1 ? '' : 's') + + const days = Math.round(hours / 24) + + if (days < 7) + return days + ' day' + (days === 1 ? '' : 's') + + const weeks = Math.round(days / 7) + + if (weeks < 4) + return weeks + ' week' + (weeks === 1 ? '' : 's') + + const months = Math.round(weeks / 4) + + if (months < 12) + return months + ' month' + (months === 1 ? '' : 's') + + const years = Math.round(months / 12) + + return years + ' year' + (years === 1 ? '' : 's') +} + +export default formatTime \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/util/generateId.mjs b/staff/lucas-orts/ponies/app/util/generateId.mjs new file mode 100644 index 000000000..23e31265b --- /dev/null +++ b/staff/lucas-orts/ponies/app/util/generateId.mjs @@ -0,0 +1,9 @@ +function generateId() { + const id10 = Math.random().toString().slice(2) + Date.now().toString() + + const id36 = Math.round(+id10 / 1000000000000).toString(36) + + return id36 +} + +export default generateId \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.html b/staff/lucas-orts/ponies/app/views/home/index.html index f5510046f..b21ad3b68 100644 --- a/staff/lucas-orts/ponies/app/views/home/index.html +++ b/staff/lucas-orts/ponies/app/views/home/index.html @@ -6,23 +6,13 @@ Home + + - - - - - - - - - - - - - + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.css b/staff/lucas-orts/ponies/app/views/login/index.css index e69de29bb..f0a1836cf 100644 --- a/staff/lucas-orts/ponies/app/views/login/index.css +++ b/staff/lucas-orts/ponies/app/views/login/index.css @@ -0,0 +1,28 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.html b/staff/lucas-orts/ponies/app/views/login/index.html index f1e149486..c1b03395b 100644 --- a/staff/lucas-orts/ponies/app/views/login/index.html +++ b/staff/lucas-orts/ponies/app/views/login/index.html @@ -10,22 +10,44 @@ -

Login

- -
- - - - - - - -
- - Register - - - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.js b/staff/lucas-orts/ponies/app/views/login/index.js deleted file mode 100644 index 0a9f6879f..000000000 --- a/staff/lucas-orts/ponies/app/views/login/index.js +++ /dev/null @@ -1,27 +0,0 @@ -var form = document.querySelector('form') - -form.onsubmit = function (event) { - event.preventDefault() - - var usernameInput = document.getElementById('username-input') - var passwordInput = document.getElementById('password-input') - - var username = usernameInput.value - var password = passwordInput.value - - try { - loginUser(username, password) - - location.href = '../home' - } catch (error) { - alert(error.message) - } -} - -var a = document.querySelector('a') - -a.onclick = function (event) { - event.preventDefault() - - window.location.href = '../register' -} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/login/index.jsx b/staff/lucas-orts/ponies/app/views/login/index.jsx new file mode 100644 index 000000000..8f07626f0 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/login/index.jsx @@ -0,0 +1,62 @@ +import logic from '../../logic/index.mjs' + +const Component = React.Component + +class Login extends Component { + constructor() { + super() + } + + handleRegisterClick(event) { + event.preventDefault() + + location.href = '../register' + } + + handleLoginSubmit(event) { + event.preventDefault() + + const form = event.target + + const usernameInput = form['username-input'] + const passwordInput = form['password-input'] + + const username = usernameInput.value + const password = passwordInput.value + + try { + logic.loginUser(username, password) + + location.href = '../home' + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + render() { + return
+

Login

+ +
+
+ + +
+ +
+ + +
+ + +
+ + Register +
+ } +} + +const root = ReactDOM.createRoot(document.getElementById('root')) +root.render() \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/register/index.css b/staff/lucas-orts/ponies/app/views/register/index.css deleted file mode 100644 index e69de29bb..000000000 diff --git a/staff/lucas-orts/ponies/app/views/register/index.html b/staff/lucas-orts/ponies/app/views/register/index.html index aa6fafca4..3889092bc 100644 --- a/staff/lucas-orts/ponies/app/views/register/index.html +++ b/staff/lucas-orts/ponies/app/views/register/index.html @@ -6,38 +6,54 @@ Register + + -

Register

- -
- - - - - - - - - - - - - - - - - - - -
- - Login - - - +
+

Register

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + Login +
+ + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/register/index.js b/staff/lucas-orts/ponies/app/views/register/index.js deleted file mode 100644 index 8136675da..000000000 --- a/staff/lucas-orts/ponies/app/views/register/index.js +++ /dev/null @@ -1,37 +0,0 @@ -var form = document.querySelector('form') - -form.onsubmit = function (event) { - event.preventDefault() - - var nameInput = document.getElementById('name-input') - var surnameInput = document.getElementById('surname-input') - var emailInput = document.getElementById('email-input') - var usernameInput = document.getElementById('username-input') - var passwordInput = document.getElementById('password-input') - var passwordRepeatInput = document.getElementById('password2-input') - - var name = nameInput.value - var surname = surnameInput.value - var email = emailInput.value - var username = usernameInput.value - var password = passwordInput.value - var passwordRepeat = passwordRepeatInput.value - - try { - registerUser(name, surname, email, username, password, passwordRepeat) - - alert('user successfully registered') - - location.href = '../login' - } catch (error) { - alert(error.message) - } -} - -var a = document.querySelector('a') - -a.onclick = function (event) { - event.preventDefault() - - location.href = '../login' -} \ No newline at end of file diff --git a/staff/lucas-orts/playground/blog/index.html b/staff/lucas-orts/stuff/react/demo.0/index.html similarity index 50% rename from staff/lucas-orts/playground/blog/index.html rename to staff/lucas-orts/stuff/react/demo.0/index.html index 33183a3f8..1a6caac41 100644 --- a/staff/lucas-orts/playground/blog/index.html +++ b/staff/lucas-orts/stuff/react/demo.0/index.html @@ -1,18 +1,17 @@ - - - - - - Mi blog - - -
-

Mi Blog

-

Bienvenidos a mi blog

-
- - -
- + + + + + + + Hello, React! + + + +
+ + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/react/demo.0/main.js b/staff/lucas-orts/stuff/react/demo.0/main.js new file mode 100644 index 000000000..e9364089b --- /dev/null +++ b/staff/lucas-orts/stuff/react/demo.0/main.js @@ -0,0 +1,30 @@ +const title = document.createElement('h1') +title.innerText = " Hello, World!" + +const query = document.createElement('input') +query.type = 'text' +query.name = 'q' + +const form = document.createElement('form') +form.action = 'https://www.google.com/search' +form.appendChild(query) + +const samu = document.createElement('li') +samu.innerText = 'Samu' + +const edu = document.createElement('li') +edu.innerText = 'Edu' + +const marti = document.createElement('li') +marti.innerText = 'Marti' + +const people = document.createElement('ul') +people.appendChild(samu) +people.appendChild(edu) +people.appendChild(marti) + +const root = document.getElementById('root') +root.appendChild(title) +root.appendChild(form) +root.appendChild(people) + diff --git a/staff/lucas-orts/stuff/react/demo.1/index.html b/staff/lucas-orts/stuff/react/demo.1/index.html new file mode 100644 index 000000000..6eaa6352c --- /dev/null +++ b/staff/lucas-orts/stuff/react/demo.1/index.html @@ -0,0 +1,19 @@ + + + + + + + Hello, React! + + + +
+ + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/react/demo.1/main.js b/staff/lucas-orts/stuff/react/demo.1/main.js new file mode 100644 index 000000000..22dbb1f43 --- /dev/null +++ b/staff/lucas-orts/stuff/react/demo.1/main.js @@ -0,0 +1,17 @@ +const title = React.createElement('h1', { children: 'Hello, World!' }) + +const query = React.createElement('input', { type: 'text', name: 'q', placeholder: 'Search' }) + +const form = React.createElement('form', { + children: query, + atcion: 'https://www.google.com/search' +}) + +const samu = React.createElement('li', { children: 'Samu' }) +const edu = React.createElement('li', { children: 'Edu' }) +const marti = React.createElement('li', { children: 'Marti' }) + +const people = React.createElement('ul', { children: [samu, edu, marti] }) + +const root = ReactDom.createRoot(document.getElementById('root')) +root.render([title, form, people]) \ No newline at end of file diff --git a/staff/lucas-orts/stuff/react/demo/index.html b/staff/lucas-orts/stuff/react/demo/index.html new file mode 100644 index 000000000..6eaa6352c --- /dev/null +++ b/staff/lucas-orts/stuff/react/demo/index.html @@ -0,0 +1,19 @@ + + + + + + + Hello, React! + + + +
+ + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/react/demo/main.js b/staff/lucas-orts/stuff/react/demo/main.js new file mode 100644 index 000000000..86e549038 --- /dev/null +++ b/staff/lucas-orts/stuff/react/demo/main.js @@ -0,0 +1,79 @@ +const title = React.createElement('h1', { children: 'Hello, World! ' }) + +const query = React.createElement('input', { type: 'text', name: 'q', placeholder: 'search' }) + +const form = React.createElement('form', { + children: query, + action: 'https://www.google.com/search' +}) + +const samu = React.createElement('li', { children: 'Samu' }) +const edu = React.createElement('li', { children: 'Edu' }) +const marti = React.createElement('li', { children: 'Marti' }) + +const people = React.createElement('ul', { children: [samu, edu, marti] }) + +const Component = React.Component + +class Hello extends Component { + constructor() { + super() + + } + + render() { + return React.createElement('h1', { children: 'Hello!' }) + } +} + +function Goodbye() { + return React.createElement('h1', { children: 'Goodbye!' }) +} + +class Counter extends Component { + constructor() { + super() + + this.state = { count: 0 } + + } + + handleClick() { + this.setState({ count: this.state.count + 1 }) + } + + render() { + //const self = this + + return React.createElement('button', { + children: this.state.count, + + //FAILS! + //onClick: function(){ + //this.setState({count: this.state.count + 1}) + //} + + //WORKS! + //onCLick: function(){ + // self.setState({count: self.state.count + 1}) + //} + + //WORKS! + //onClick: () =>{ + // this.seState({ count: this.state.count + 1}) + //} + + //WORKS! + //onClick: function(){ + // self.handleClick() + //} + + //WORKS! + onClick: () => this.handleClick() + }) + } +} + +const root = ReactDOM.createRoot(document.getElelementById('root')) +// root.render([title, form, people, new Hello().render(), Goodbye(), new Counter.render()]) +root.render([title, form, people, React.createElement(Hello, {}), React.createElement(Goodbye, {}), React.createElement(Counter, {})]) \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/logic/createPost.js b/staff/lucas-orts/stuff/zzz/app copy/logic/createPost.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/createPost.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/createPost.js diff --git a/staff/lucas-orts/ponies/app/logic/deletePost.js b/staff/lucas-orts/stuff/zzz/app copy/logic/deletePost.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/deletePost.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/deletePost.js diff --git a/staff/lucas-orts/ponies/app/logic/getAllPosts.js b/staff/lucas-orts/stuff/zzz/app copy/logic/getAllPosts.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/getAllPosts.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/getAllPosts.js diff --git a/staff/lucas-orts/ponies/app/logic/getUserName.js b/staff/lucas-orts/stuff/zzz/app copy/logic/getUserName.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/getUserName.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/getUserName.js diff --git a/staff/lucas-orts/ponies/app/logic/getUserUsername.js b/staff/lucas-orts/stuff/zzz/app copy/logic/getUserUsername.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/getUserUsername.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/getUserUsername.js diff --git a/staff/lucas-orts/ponies/app/logic/loginUser.js b/staff/lucas-orts/stuff/zzz/app copy/logic/loginUser.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/loginUser.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/loginUser.js diff --git a/staff/lucas-orts/ponies/app/logic/logoutUser.js b/staff/lucas-orts/stuff/zzz/app copy/logic/logoutUser.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/logoutUser.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/logoutUser.js diff --git a/staff/lucas-orts/ponies/app/logic/registerUser.js b/staff/lucas-orts/stuff/zzz/app copy/logic/registerUser.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/registerUser.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/registerUser.js diff --git a/staff/lucas-orts/ponies/app/logic/updatePostCaption.js b/staff/lucas-orts/stuff/zzz/app copy/logic/updatePostCaption.js similarity index 100% rename from staff/lucas-orts/ponies/app/logic/updatePostCaption.js rename to staff/lucas-orts/stuff/zzz/app copy/logic/updatePostCaption.js diff --git a/staff/lucas-orts/ponies/app/utils/formatTime.js b/staff/lucas-orts/stuff/zzz/app copy/utils/formatTime.js similarity index 100% rename from staff/lucas-orts/ponies/app/utils/formatTime.js rename to staff/lucas-orts/stuff/zzz/app copy/utils/formatTime.js diff --git a/staff/lucas-orts/ponies/app/utils/generateId.js b/staff/lucas-orts/stuff/zzz/app copy/utils/generateId.js similarity index 100% rename from staff/lucas-orts/ponies/app/utils/generateId.js rename to staff/lucas-orts/stuff/zzz/app copy/utils/generateId.js diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/Component.js b/staff/lucas-orts/stuff/zzz/app copy/views/Component.js new file mode 100644 index 000000000..096abca67 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/Component.js @@ -0,0 +1,40 @@ +class Component { + constructor(container) { + this.container = container + } + + add(child) { + if (!(child instanceof Component)) + throw new TypeError('child is not a Component') + + this.container.appendChild(child.container) + } + + setText(text) { + if (typeof text !== 'string') + throw new TypeError('text is not a string') + + this.container.innerText = text + } + + setBackgroundColor(color) { + if (typeof color !== 'string') + throw new TypeError('color is not a string') + + this.container.style.backgroundColor = color + } + + setColor(color) { + if (typeof color !== 'string') + throw new TypeError('color is not a string') + + this.container.style.color = color + } + + setClassName(className) { + if (typeof className !== 'string') + throw new TypeError('className is not a string') + + this.container.className = className + } +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/components/Button.js b/staff/lucas-orts/stuff/zzz/app copy/views/components/Button.js new file mode 100644 index 000000000..1b2df081c --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/components/Button.js @@ -0,0 +1,9 @@ +class Button extends Component { + constructor() { + super(document.createElement('button')); + + } + onClick(callback) { + this.container.onclick = callback + } +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/components/Form.js b/staff/lucas-orts/stuff/zzz/app copy/views/components/Form.js new file mode 100644 index 000000000..dd3f1295f --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/components/Form.js @@ -0,0 +1,9 @@ +class Form extends Component { + constructor(selector) { + super(document.querySelector(selector)) + } + + onSubmit(callback) { + this.container.onsubmit = callback + } +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/components/Link.js b/staff/lucas-orts/stuff/zzz/app copy/views/components/Link.js new file mode 100644 index 000000000..f378c6a7c --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/components/Link.js @@ -0,0 +1,9 @@ +class Link extends Component { + constructor(selector) { + super(document.querySelector(selector)) + } + + onClick(callback) { + this.container.onclick = callback + } +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/components/Paragraph.js b/staff/lucas-orts/stuff/zzz/app copy/views/components/Paragraph.js new file mode 100644 index 000000000..03cbf7583 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/components/Paragraph.js @@ -0,0 +1,5 @@ +class Paragraph extends Component { + constructor() { + super(document.createElement('p')) + } +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/home/components/Header.js b/staff/lucas-orts/stuff/zzz/app copy/views/home/components/Header.js new file mode 100644 index 000000000..3c35039ce --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/home/components/Header.js @@ -0,0 +1,34 @@ +class Header extends Component { + constructor() { + super(document.createElement('header')) + + this.container.className = 'header' + + const userName = new Paragraph + userName.setClassName('header__user-name') + this.add(userName) + + try { + const name = getUserName() + + userName.setText('Hello, ' + name + '!') + } catch (error) { + alert(error.message) + } + + const logoutButton = new Button + logoutButton.setClassName('logout-button') + logoutButton.setInnerText('Logout') + this.add(logoutButton) + + logoutButton.onClick = function () { + try { + logoutUser() + + location.href = '../login' + } catch (error) { + alert(error.message) + } + } + } +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.css b/staff/lucas-orts/stuff/zzz/app copy/views/home/index.css similarity index 67% rename from staff/lucas-orts/ponies/app/views/home/index.css rename to staff/lucas-orts/stuff/zzz/app copy/views/home/index.css index 1aa948c44..7409db2e6 100644 --- a/staff/lucas-orts/ponies/app/views/home/index.css +++ b/staff/lucas-orts/stuff/zzz/app copy/views/home/index.css @@ -94,6 +94,12 @@ align-items: center; gap: 1rem; background-color: #f25252; + box-sizing: border-box; + box-shadow: 0px 1px 1px lightgray; +} + +.header__user-name { + margin: 0; } .main { @@ -110,4 +116,32 @@ justify-content: center; background-color: white; padding: .5rem 0; + box-shadow: 0px -1px 1px lightgray; +} + +.create-post-section { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + background-color: white; + padding: .5rem; + box-sizing: border-box; +} + +.create-post-section__title { + margin: .5rem 0; +} + +.create-post-section__buttons { + display: flex; + justify-content: center; + gap: 1rem; + font-size: inherit; + background-color: #FF0303; + border-radius: 60px; + padding-top: 3px; + padding-bottom: 3px; + padding-left: 6px; + padding-right: 6px; } \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/home/index.html b/staff/lucas-orts/stuff/zzz/app copy/views/home/index.html new file mode 100644 index 000000000..27972eb76 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/home/index.html @@ -0,0 +1,33 @@ + + + + + + + Home + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.js b/staff/lucas-orts/stuff/zzz/app copy/views/home/index.js similarity index 64% rename from staff/lucas-orts/ponies/app/views/home/index.js rename to staff/lucas-orts/stuff/zzz/app copy/views/home/index.js index c877b0e7f..b9242ffc3 100644 --- a/staff/lucas-orts/ponies/app/views/home/index.js +++ b/staff/lucas-orts/stuff/zzz/app copy/views/home/index.js @@ -1,46 +1,19 @@ -(function () { - var header = document.createElement('header') - header.className = 'header' - document.body.appendChild(header) +{ + const home = new Component(document.body) + const header = new Header + home.add(header) - var userName = document.createElement('p') - header.appendChild(userName) + const body = new Component(document.createElement('main')) + body.setClassName('view main') + home.add(body) - try { - var name = getUserName() - - userName.innerText = 'Hello, ' + name + '!' - } catch (error) { - alert(error.message) - } - - var logoutButton = document.createElement('button') - logoutButton.className = 'logout-button' - logoutButton.innerText = 'Logout' - header.appendChild(logoutButton) - - logoutButton.onclick = function () { - try { - logoutUser() - - location.href = '../login' - } catch (error) { - alert(error.message) - } - } - - - var main = document.createElement('main') - main.className = 'view main' - document.body.appendChild(main) - - var postListSection = document.createElement('section') + const postListSection = document.createElement('section') postListSection.className = 'post-list' main.appendChild(postListSection) function clearPosts() { - for (var i = postListSection.children.length - 1; i > -1; i--) { - var child = postListSection.children[i] + for (let i = postListSection.children.length - 1; i > -1; i--) { + const child = postListSection.children[i] postListSection.removeChild(child) } @@ -48,35 +21,35 @@ function listPosts() { try { - var posts = getAllPosts() + const posts = getAllPosts() posts.forEach(function (post) { - var postArticle = document.createElement('article') + const postArticle = document.createElement('article') postArticle.className = 'post' postListSection.appendChild(postArticle) - var postAuthorTitle = document.createElement('h3') + const postAuthorTitle = document.createElement('h3') postAuthorTitle.className = 'post__author' postAuthorTitle.innerText = post.author postArticle.appendChild(postAuthorTitle) - var postImage = document.createElement('img') + const postImage = document.createElement('img') postImage.className = 'post__image' postImage.src = post.image postArticle.appendChild(postImage) - var postCaptionText = document.createElement('p') + const postCaptionText = document.createElement('p') postCaptionText.className = 'post__caption' postCaptionText.innerText = post.caption postArticle.appendChild(postCaptionText) if (post.author === getUserUsername()) { - var postActionButtonsDiv = document.createElement('div') + const postActionButtonsDiv = document.createElement('div') postActionButtonsDiv.className = 'post__actions' postArticle.appendChild(postActionButtonsDiv) - var postDeleteButton = document.createElement('button') + const postDeleteButton = document.createElement('button') postDeleteButton.className = 'form__button' postDeleteButton.innerText = 'Delete' postActionButtonsDiv.appendChild(postDeleteButton) @@ -98,32 +71,32 @@ } } - var editButton = document.createElement('button') + const editButton = document.createElement('button') editButton.className = 'form__button' editButton.innerText = 'Edit' postActionButtonsDiv.appendChild(editButton) editButton.onclick = function () { - var editCaptionForm = document.createElement('form') + const editCaptionForm = document.createElement('form') postArticle.appendChild(editCaptionForm) - var editCaptionLabel = document.createElement('label') + const editCaptionLabel = document.createElement('label') editCaptionLabel.htmlFor = 'edit-caption-input' editCaptionForm.appendChild(editCaptionLabel) - var editCaptionInput = document.createElement('input') + const editCaptionInput = document.createElement('input') editCaptionInput.id = editCaptionLabel.htmlFor editCaptionInput.value = post.caption editCaptionForm.appendChild(editCaptionInput) - var editCaptionSubmitButton = document.createElement('button') + const editCaptionSubmitButton = document.createElement('button') editCaptionSubmitButton.className = 'form__button' editCaptionSubmitButton.type = 'submit' editCaptionSubmitButton.innerText = 'Save' editCaptionForm.appendChild(editCaptionSubmitButton) - var editCaptionCancelButton = document.createElement('button') + const editCaptionCancelButton = document.createElement('button') editCaptionCancelButton.className = 'form__button' editCaptionCancelButton.innerText = 'Cancel' editCaptionCancelButton.type = 'button' @@ -137,7 +110,7 @@ event.preventDefault() try { - var newCaption = editCaptionInput.value + const newCaption = editCaptionInput.value updatePostCaption(post.id, newCaption) @@ -157,7 +130,7 @@ } } - var postDateTime = document.createElement('time') + const postDateTime = document.createElement('time') postDateTime.className = 'post__time' postDateTime.innerText = formatTime(new Date(post.date)) postArticle.appendChild(postDateTime) @@ -169,26 +142,27 @@ listPosts() - var footer = document.createElement('footer') + const footer = document.createElement('footer') footer.className = 'footer' document.body.appendChild(footer) - var addPostButton = document.createElement('button') + const addPostButton = document.createElement('button') addPostButton.className = 'add-post-button' addPostButton.innerText = '+' footer.appendChild(addPostButton) addPostButton.onclick = function () { addPostButton.disabled = true - var createPostSection = document.createElement('section') - createPostSection.className = 'section__form' + const createPostSection = document.createElement('section') + createPostSection.className = 'create-post-section' document.body.appendChild(createPostSection) - var createPostTitle = document.createElement('h2') + const createPostTitle = document.createElement('h2') + createPostTitle.className = 'create-post-section__title' createPostTitle.innerText = 'Create Post' createPostSection.appendChild(createPostTitle) - var createPostForm = document.createElement('form') + const createPostForm = document.createElement('form') createPostForm.className = 'form' createPostSection.appendChild(createPostForm) @@ -196,9 +170,9 @@ event.preventDefault() addPostButton.disabled = false - //var postImageInput = document.getElementById('post-image-input') - var postImage = postImageInput.value - var postCaption = postCaptionInput.value + //const postImageInput = document.getElementById('post-image-input') + const postImage = postImageInput.value + const postCaption = postCaptionInput.value try { createPost(postImage, postCaption) @@ -212,49 +186,53 @@ } } - var postImageFieldDiv = document.createElement('div') + const postImageFieldDiv = document.createElement('div') postImageFieldDiv.className = 'form__field' createPostForm.appendChild(postImageFieldDiv) - var postImageLabel = document.createElement('label') + const postImageLabel = document.createElement('label') postImageLabel.htmlFor = 'post-image-input' postImageLabel.innerText = 'Image' postImageFieldDiv.appendChild(postImageLabel) - var postImageInput = document.createElement('input') + const postImageInput = document.createElement('input') postImageInput.className = 'form__input' postImageInput.id = postImageLabel.htmlFor postImageFieldDiv.appendChild(postImageInput) - var postCaptionFieldDiv = document.createElement('div') + const postCaptionFieldDiv = document.createElement('div') postCaptionFieldDiv.className = 'form__field' createPostForm.appendChild(postCaptionFieldDiv) - var postCaptionLabel = document.createElement('label') + const postCaptionLabel = document.createElement('label') postCaptionLabel.htmlFor = 'post-caption-input' postCaptionLabel.innerText = 'Caption' postCaptionFieldDiv.appendChild(postCaptionLabel) - var postCaptionInput = document.createElement('input') + const postCaptionInput = document.createElement('input') postCaptionInput.className = 'form__input' postCaptionInput.id = postCaptionLabel.htmlFor postCaptionFieldDiv.appendChild(postCaptionInput) - var postSubmitButton = document.createElement('button') + const postButtonsDiv = document.createElement('div') + postButtonsDiv.className = 'create-post-section__buttons' + createPostForm.appendChild(postButtonsDiv) + + const postSubmitButton = document.createElement('button') postSubmitButton.className = 'form__button' postSubmitButton.type = 'submit' postSubmitButton.innerText = 'Create' - createPostForm.appendChild(postSubmitButton) + postButtonsDiv.appendChild(postSubmitButton) - var postCancelButton = document.createElement('button') + const postCancelButton = document.createElement('button') postCancelButton.className = 'form__button' postCancelButton.type = 'reset' postCancelButton.innerText = 'Cancel' - createPostForm.appendChild(postCancelButton) + postButtonsDiv.appendChild(postCancelButton) postCancelButton.onclick = function () { addPostButton.disabled = false - document.body.removeChild(createPostSection) + footer.removeChild(createPostSection) } } -})() \ No newline at end of file +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/login/index.css b/staff/lucas-orts/stuff/zzz/app copy/views/login/index.css new file mode 100644 index 000000000..f0a1836cf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/login/index.css @@ -0,0 +1,28 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/login/index.html b/staff/lucas-orts/stuff/zzz/app copy/views/login/index.html new file mode 100644 index 000000000..3a59f2bb8 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/login/index.html @@ -0,0 +1,42 @@ + + + + + + + Login + + + + + +
+

Login

+ +
+
+ + +
+ +
+ + +
+ + +
+ + Register +
+ + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/login/index.js b/staff/lucas-orts/stuff/zzz/app copy/views/login/index.js new file mode 100644 index 000000000..77b88a7b9 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/login/index.js @@ -0,0 +1,29 @@ +(function () { + var loginForm = new Form('form') + + loginForm.onSubmit(function (event) { + event.preventDefault() + + var usernameInput = document.getElementById('username-input') + var passwordInput = document.getElementById('password-input') + + var username = usernameInput.value + var password = passwordInput.value + + try { + loginUser(username, password) + + location.href = '../home' + } catch (error) { + alert(error.message) + } + }) + + var registerLink = new Link('a') + + registerLink.onClick(function (event) { + event.preventDefault() + + location.href = '../register' + }) +})() \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/register/index.css b/staff/lucas-orts/stuff/zzz/app copy/views/register/index.css new file mode 100644 index 000000000..f0a1836cf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/register/index.css @@ -0,0 +1,28 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/register/index.html b/staff/lucas-orts/stuff/zzz/app copy/views/register/index.html new file mode 100644 index 000000000..818cede63 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/register/index.html @@ -0,0 +1,65 @@ + + + + + + + Register + + + + + +
+

Register

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + Login +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy/views/register/index.js b/staff/lucas-orts/stuff/zzz/app copy/views/register/index.js new file mode 100644 index 000000000..0fe42494e --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy/views/register/index.js @@ -0,0 +1,39 @@ +(function () { + var registerForm = new Form('form') + + registerForm.onSubmit(function (event) { + event.preventDefault() + + var nameInput = document.getElementById('name-input') + var surnameInput = document.getElementById('surname-input') + var emailInput = document.getElementById('email-input') + var usernameInput = document.getElementById('username-input') + var passwordInput = document.getElementById('password-input') + var passwordRepeatInput = document.getElementById('password2-input') + + var name = nameInput.value + var surname = surnameInput.value + var email = emailInput.value + var username = usernameInput.value + var password = passwordInput.value + var passwordRepeat = passwordRepeatInput.value + + try { + registerUser(name, surname, email, username, password, passwordRepeat) + + alert('user successfully registered') + + location.href = '../login' + } catch (error) { + alert(error.message) + } + }) + + var loginLink = new Link('a') + + loginLink.onClick(function (event) { + event.preventDefault() + + location.href = '../login' + }) +})() \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/deletePost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/deletePost.mjs new file mode 100644 index 000000000..8905a9d05 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/deletePost.mjs @@ -0,0 +1,13 @@ +function deletePost(condition) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const postIndex = posts.findIndex(condition) + + if (postIndex > -1) { + posts.splice(postIndex, 1) + + localStorage.posts = JSON.stringify(posts) + } +} + +export default deletePost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/findPost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/findPost.mjs new file mode 100644 index 000000000..1849d8bcd --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/findPost.mjs @@ -0,0 +1,9 @@ +function findPost(condition) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const post = posts.find(condition) + + return post || null +} + +export default findPost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/findPosts.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/findPosts.mjs new file mode 100644 index 000000000..1620c18a6 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/findPosts.mjs @@ -0,0 +1,9 @@ +function findPosts(condition) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const foundPosts = posts.filter(condition) + + return foundPosts +} + +export default findPosts \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/findUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/findUser.mjs new file mode 100644 index 000000000..008bc7083 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/findUser.mjs @@ -0,0 +1,9 @@ +function findUser(condition) { + const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + const user = users.find(condition) + + return user || null +} + +export default findUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/index.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/index.mjs new file mode 100644 index 000000000..830e27f38 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/index.mjs @@ -0,0 +1,21 @@ +import deletePost from './deletePost.mjs' +import findPost from './findPost.mjs' +import findPosts from './findPosts.mjs' +import findUser from './findUser.mjs' +import insertPost from './insertPost.mjs' +import insertUser from './insertUser.mjs' +import updatePost from './updatePost.mjs' +import updateUser from './updateUser.mjs' + +const data = { + deletePost, + findPost, + findPosts, + findUser, + insertPost, + insertUser, + updatePost, + updateUser +} + +export default data \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/insertPost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/insertPost.mjs new file mode 100644 index 000000000..46c648c84 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/insertPost.mjs @@ -0,0 +1,9 @@ +function insertPost(post) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + posts.push(post) + + localStorage.posts = JSON.stringify(posts) +} + +export default insertPost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/insertUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/insertUser.mjs new file mode 100644 index 000000000..74a40bc06 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/insertUser.mjs @@ -0,0 +1,9 @@ +function insertUser(user) { + const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + users.push(user) + + localStorage.users = JSON.stringify(users) +} + +export default insertUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/updatePost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/updatePost.mjs new file mode 100644 index 000000000..dca455f9e --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/updatePost.mjs @@ -0,0 +1,13 @@ +function updatePost(condition, post) { + const posts = localStorage.posts !== undefined ? JSON.parse(localStorage.posts) : [] + + const postIndex = posts.findIndex(condition) + + if (postIndex > -1) { + posts.splice(postIndex, 1, post) + + localStorage.posts = JSON.stringify(posts) + } +} + +export default updatePost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/data/updateUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/data/updateUser.mjs new file mode 100644 index 000000000..5e3e5817a --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/data/updateUser.mjs @@ -0,0 +1,13 @@ +function updateUser(condition, user) { + const users = localStorage.users !== undefined ? JSON.parse(localStorage.users) : [] + + const index = users.findIndex(condition) + + if (index > -1) { + users.splice(index, 1, user) + + localStorage.users = JSON.stringify(users) + } +} + +export default updateUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/createPost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/createPost.mjs new file mode 100644 index 000000000..d528a0dbf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/createPost.mjs @@ -0,0 +1,21 @@ +import data from '../data/index.mjs' + +import generateId from '../util/generateId.mjs' + +const createPost = (image, caption) => { + if (!image.startsWith('http')) + throw new Error('invalid image') + + const post = { + id: generateId(), + image: image, + caption: caption, + author: sessionStorage.username, + date: new Date().toISOString(), + likes: [] + } + + data.insertPost(post) +} + +export default createPost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/deletePost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/deletePost.mjs new file mode 100644 index 000000000..f597d3ae9 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/deletePost.mjs @@ -0,0 +1,13 @@ +import data from '../data/index.mjs' + +const deletePost = postId => { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const post = data.findPost(post => post.id === postId) + + if (post === null) throw new Error('post not found') + + data.deletePost(post => post.id === postId) +} + +export default deletePost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFavPosts.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFavPosts.mjs new file mode 100644 index 000000000..957ad00ab --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFavPosts.mjs @@ -0,0 +1,19 @@ +import data from '../data/index.mjs' + +const getAllFavPosts = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const posts = data.findPosts(post => user.favs.includes(post.id)) + + posts.forEach(post => { + post.fav = user.favs.includes(post.id) + post.like = post.likes.includes(sessionStorage.username) + }) + + return posts.reverse() +} + +export default getAllFavPosts \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFollowingUserPosts.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFollowingUserPosts.mjs new file mode 100644 index 000000000..3ebc8fe15 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllFollowingUserPosts.mjs @@ -0,0 +1,23 @@ +import data from '../data/index.mjs' + +const getAllFollowingUserPosts = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('User not found') + + const posts = data.findPosts(post => user.follows.includes(post.author)) + + posts.forEach(post => { + post.fav = user.favs.includes(post.id) + post.like = post.likes.includes(sessionStorage.username) + post.author = { + username: post.author, + following: user.following.includes(post.author) + } + }) + + return posts.reverse() +} + +export default getAllFollowingUserPosts \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllPosts.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllPosts.mjs new file mode 100644 index 000000000..53a978452 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/getAllPosts.mjs @@ -0,0 +1,19 @@ +import data from '../data/index.mjs' + +const getAllPosts = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const posts = data.findPosts(() => true) + + posts.forEach(post => { + post.fav = user.favs.includes(post.id) + post.like = post.likes.includes(sessionStorage.username) + }) + + return posts.reverse() +} + +export default getAllPosts \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/getUserName.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/getUserName.mjs new file mode 100644 index 000000000..f92bd7b0d --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/getUserName.mjs @@ -0,0 +1,12 @@ +import data from '../data/index.mjs' + +const getUserName = () => { + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + return user.name +} + +export default getUserName \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/getUserUsername.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/getUserUsername.mjs new file mode 100644 index 000000000..69e37f836 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/getUserUsername.mjs @@ -0,0 +1,3 @@ +const getUserUsername = () => sessionStorage.username + +export default getUserUsername \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/index.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/index.mjs new file mode 100644 index 000000000..36a7cf383 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/index.mjs @@ -0,0 +1,33 @@ +import getAllPosts from './getAllPosts.mjs' +import getUserName from './getUserName.mjs' +import getUserUsername from './getUserUsername.mjs' +import loginUser from './loginUser.mjs' +import logoutUser from './logoutUser.mjs' +import registerUser from './registerUser.mjs' +import toggleLikePost from './toggleLikePost.mjs' +import updatePostCaption from './updatePostCaption.mjs' +import createPost from './createPost.mjs' +import deletePost from './deletePost.mjs' +import toggleFavPost from './toggleFavPost.mjs' +import toggleFollowUser from './toggleFollowUser.mjs' +import getAllFavPosts from './getAllFavPosts.mjs' +import getAllFollowingUserPosts from './getAllFollowingUserPosts.mjs' + +const logic = { + getAllPosts, + getUserName, + getUserUsername, + loginUser, + logoutUser, + registerUser, + toggleLikePost, + updatePostCaption, + createPost, + deletePost, + toggleFavPost, + toggleFollowUser, + getAllFavPosts, + getAllFollowingUserPosts +} + +export default logic \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/loginUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/loginUser.mjs new file mode 100644 index 000000000..3d271bb92 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/loginUser.mjs @@ -0,0 +1,21 @@ +import data from '../data/index.mjs' + +const loginUser = (username, password) => { + if (username.trim().length < 4) + throw new Error('invalid username') + + if (password.trim().length < 8) + throw new Error('invalid password') + + const user = data.findUser(user => user.username === username) + + if (user === null) + throw new Error('username does not exist') + + if (user.password !== password) + throw new Error('wrong password') + + sessionStorage.username = username +} + +export default loginUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/logoutUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/logoutUser.mjs new file mode 100644 index 000000000..cce13cc28 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/logoutUser.mjs @@ -0,0 +1,3 @@ +const logoutUser = () => delete sessionStorage.username + +export default logoutUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/registerUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/registerUser.mjs new file mode 100644 index 000000000..caf65d464 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/registerUser.mjs @@ -0,0 +1,47 @@ +import data from '../data/index.mjs' + +const EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/ + +const registerUser = (name, surname, email, username, password, passwordRepeat) => { + if (name.trim() === '') + throw new Error('invalid name') + + if (surname.trim().length < 2) + throw new Error('invalid surname') + + if (!EMAIL_REGEX.test(email)) + throw new Error('invalid email') + + if (username.trim().length < 4) + throw new Error('invalid username') + + if (password.trim().length < 8) + throw new Error('invalid password') + + if (password !== passwordRepeat) + throw new Error('passwords do not match') + + let user = data.findUser(user => user.email === email) + + if (user !== null) + throw new Error('email already exists') + + user = data.findUser(user => user.username === username) + + if (user !== null) + throw new Error('username already exists') + + user = { + name: name, + surname: surname, + email: email, + username: username, + password: password, + favs: [], + following: [] + } + + data.insertUser(user) +} + +export default registerUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFavPost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFavPost.mjs new file mode 100644 index 000000000..a2ee408cb --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFavPost.mjs @@ -0,0 +1,26 @@ +import data from '../data/index.mjs' + +function toggleFavPost(postId) { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('user not found') + + const post = data.findPost(post => post.id === postId) + + if (post === null) + throw new Error('post not found') + + const index = user.favs.indexOf(postId) + + if (index < 0) + user.favs.push(postId) + else + user.favs.splice(index, 1) + + data.updateUser(user => user.username === sessionStorage.username, user) +} + +export default toggleFavPost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFollowUser.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFollowUser.mjs new file mode 100644 index 000000000..0f620276d --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleFollowUser.mjs @@ -0,0 +1,27 @@ +import data from "../data/index.mjs" + +function toggleFollowUser(username) { + + if (username.trim().length === 0) throw new Error('Invalid username') + + const user = data.findUser(user => user.username === sessionStorage.username) + + if (user === null) + throw new Error('User not found') + + const following = data.findUser(user => user.username) + + if (!following) + throw new Error('following user not found') + + const index = user.following.indexOf(username) + + if (index !== -1) + user.following.splice(index, 1) + else + user.following.push(post.author) + + data.updateUser(user => user.username === sessionStorage.username, user) +} + +export default toggleFollowUser \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleLikePost.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleLikePost.mjs new file mode 100644 index 000000000..4a4faf4a3 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/toggleLikePost.mjs @@ -0,0 +1,21 @@ +import data from '../data/index.mjs' + +function toggleLikePost(postId) { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const post = data.findPost(post => post.id === postId) + + if (post === null) + throw new Error('post not found') + + const index = post.likes.indexOf(sessionStorage.username) + + if (index < 0) + post.likes.push(sessionStorage.username) + else + post.likes.splice(index, 1) + + data.updatePost(post => post.id === postId, post) +} + +export default toggleLikePost \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/logic/updatePostCaption.mjs b/staff/lucas-orts/stuff/zzz/app copy2/logic/updatePostCaption.mjs new file mode 100644 index 000000000..55312dc22 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/logic/updatePostCaption.mjs @@ -0,0 +1,15 @@ +import data from '../data/index.mjs' + +const updatePostCaption = (postId, newCaption) => { + if (postId.trim().length === 0) throw new Error('invalid postId') + + const post = data.findPost(post => post.id === postId) + + if (post === null) throw new Error('post not found') + + post.caption = newCaption + + data.updatePost(post => post.id === postId, post) +} + +export default updatePostCaption \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/util/formatTime.mjs b/staff/lucas-orts/stuff/zzz/app copy2/util/formatTime.mjs new file mode 100644 index 000000000..823431980 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/util/formatTime.mjs @@ -0,0 +1,37 @@ +function formatTime(date) { + const seconds = Math.round((Date.now() - date.getTime()) / 1000) + + if (seconds < 60) + return seconds + ' second' + (seconds === 1 ? '' : 's') + + const minutes = Math.round(seconds / 60) + + if (minutes < 60) + return minutes + ' minute' + (minutes === 1 ? '' : 's') + + const hours = Math.round(minutes / 60) + + if (hours < 24) + return hours + ' hour' + (hours === 1 ? '' : 's') + + const days = Math.round(hours / 24) + + if (days < 7) + return days + ' day' + (days === 1 ? '' : 's') + + const weeks = Math.round(days / 7) + + if (weeks < 4) + return weeks + ' week' + (weeks === 1 ? '' : 's') + + const months = Math.round(weeks / 4) + + if (months < 12) + return months + ' month' + (months === 1 ? '' : 's') + + const years = Math.round(months / 12) + + return years + ' year' + (years === 1 ? '' : 's') +} + +export default formatTime \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/util/generateId.mjs b/staff/lucas-orts/stuff/zzz/app copy2/util/generateId.mjs new file mode 100644 index 000000000..23e31265b --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/util/generateId.mjs @@ -0,0 +1,9 @@ +function generateId() { + const id10 = Math.random().toString().slice(2) + Date.now().toString() + + const id36 = Math.round(+id10 / 1000000000000).toString(36) + + return id36 +} + +export default generateId \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/Component.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/Component.mjs new file mode 100644 index 000000000..b81514504 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/Component.mjs @@ -0,0 +1,64 @@ +class Component { + constructor(container) { + this.container = container + } + + add(child) { + if (!(child instanceof Component)) + throw new TypeError('child is not a Component') + + this.container.appendChild(child.container) + } + + remove(child) { + if (!(child instanceof Component)) + throw new TypeError('child is not a Component') + + this.container.removeChild(child.container) + } + + has(child) { + if (!(child instanceof Component)) + throw new TypeError('child is not a Component') + + const children = this.container.children + + for (let i = 0; i < children.length; i++) { + const childContainer = children[i] + + if (childContainer === child.container) return true + } + + return false + } + + setText(text) { + if (typeof text !== 'string') + throw new TypeError('text is not a string') + + this.container.innerText = text + } + + setBackgroundColor(color) { + if (typeof color !== 'string') + throw new TypeError('color is not a string') + + this.container.style.backgroundColor = color + } + + setColor(color) { + if (typeof color !== 'string') + throw new TypeError('color is not a string') + + this.container.style.color = color + } + + setClassName(className) { + if (typeof className !== 'string') + throw new TypeError('className is not a string') + + this.container.className = className + } +} + +export default Component \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.css b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.css new file mode 100644 index 000000000..975d7fb77 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.css @@ -0,0 +1,16 @@ +.Button { + background-color: transparent; + border-color: black; + border-radius: .5rem; + border-width: 1px; + border-style: solid; + padding: .25rem .5rem; +} + +.Button:hover { + background-color: aquamarine; +} + +.Button--active { + border-color: aquamarine; +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.mjs new file mode 100644 index 000000000..ab6d58c1a --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Button.mjs @@ -0,0 +1,19 @@ +import Component from '../Component.mjs' + +class Button extends Component { + constructor() { + super(document.createElement('button')) + + this.setClassName('Button') + } + + onClick(callback) { + this.container.onclick = callback + } + + setType(type) { + this.container.type = type + } +} + +export default Button \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Form.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Form.mjs new file mode 100644 index 000000000..32a95955d --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Form.mjs @@ -0,0 +1,13 @@ +import Component from '../Component.mjs' + +class Form extends Component { + constructor(selector) { + super(selector ? document.querySelector(selector) : document.createElement('form')) + } + + onSubmit(callback) { + this.container.onsubmit = callback + } +} + +export default Form \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Heading.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Heading.mjs new file mode 100644 index 000000000..0d8cf8b33 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Heading.mjs @@ -0,0 +1,9 @@ +import Component from '../Component.mjs' + +class Heading extends Component { + constructor(level) { + super(document.createElement(`h${level}`)) + } +} + +export default Heading \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Image.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Image.mjs new file mode 100644 index 000000000..1b0d956b2 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Image.mjs @@ -0,0 +1,13 @@ +import Component from '../Component.mjs' + +class Image extends Component { + constructor() { + super(document.createElement('img')) + } + + setUrl(url) { + this.container.src = url + } +} + +export default Image \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Input.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Input.mjs new file mode 100644 index 000000000..301d88ace --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Input.mjs @@ -0,0 +1,21 @@ +import Component from '../Component.mjs' + +class Input extends Component { + constructor() { + super(document.createElement('input')) + } + + setId(id) { + this.container.id = id + } + + setValue(value) { + this.container.value = value + } + + getValue() { + return this.container.value + } +} + +export default Input \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Label.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Label.mjs new file mode 100644 index 000000000..c468597ec --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Label.mjs @@ -0,0 +1,17 @@ +import Component from '../Component.mjs' + +class Label extends Component { + constructor() { + super(document.createElement('label')) + } + + setFor(id) { + this.container.htmlFor = id + } + + getFor() { + return this.container.htmlFor + } +} + +export default Label \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Link.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Link.mjs new file mode 100644 index 000000000..d3e0b8909 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Link.mjs @@ -0,0 +1,13 @@ +import Component from '../Component.mjs' + +class Link extends Component { + constructor(selector) { + super(document.querySelector(selector)) + } + + onClick(callback) { + this.container.onclick = callback + } +} + +export default Link \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/components/Paragraph.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Paragraph.mjs new file mode 100644 index 000000000..074401877 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/components/Paragraph.mjs @@ -0,0 +1,9 @@ +import Component from '../Component.mjs' + +class Paragraph extends Component { + constructor() { + super(document.createElement('p')) + } +} + +export default Paragraph \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FavPostList.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FavPostList.mjs new file mode 100644 index 000000000..a096c6abf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FavPostList.mjs @@ -0,0 +1,65 @@ +import Component from '../../Component.mjs' +import Post from './Post.mjs' + +import logic from '../../../logic/index.mjs' + +class FavPostList extends Component { + constructor() { + super(document.createElement('section')) + + this.setClassName('post-list') + } + + clearPosts() { + for (let i = this.container.children.length - 1; i > -1; i--) { + const child = this.container.children[i] + + this.container.removeChild(child) + } + } + + listPosts() { + try { + const posts = logic.getAllFavPosts() + + const self = this + + posts.forEach(_post => { + const post = new Post(_post) + + post.onPostDeleted(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostCaptionEdited(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostLikeToggled(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostFavToggled(() => { + self.clearPosts() + self.listPosts() + }) + + post.onUserFollowToggled(() => { + self.clearPosts() + self.listPosts() + }) + + self.add(post) + }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } +} + +export default FavPostList \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FollowingUserPostList.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FollowingUserPostList.mjs new file mode 100644 index 000000000..142773740 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/FollowingUserPostList.mjs @@ -0,0 +1,65 @@ +import Component from '../../Component.mjs' +import Post from './Post.mjs' + +import logic from '../../../logic/index.mjs' + +class FollowingUserPostList extends Component { + constructor() { + super(document.createElement('section')) + + this.setClassName('post-list') + } + + clearPosts() { + for (let i = this.container.children.length - 1; i > -1; i--) { + const child = this.container.children[i] + + this.container.removeChild(child) + } + } + + listPosts() { + const posts = logic.getAllFollowPosts() + try { + + const self = this + + posts.forEach(_post => { + const post = new Post(_post) + + post.onPostDeleted(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostCaptionEdited(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostLikeToggled(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostFavToggled(() => { + self.clearPosts() + self.listPosts() + }) + + post.onUserFollowToggled(() => { + self.clearPosts() + self.listPosts() + }) + + self.add(post) + }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } +} + +export default FollowingUserPostList \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Footer.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Footer.mjs new file mode 100644 index 000000000..bbd9b4fef --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Footer.mjs @@ -0,0 +1,106 @@ +import Component from '../../Component.mjs' +import Button from '../../components/Button.mjs' +import Heading from '../../components/Heading.mjs' +import Label from '../../components/Label.mjs' +import Form from '../../components/Form.mjs' +import Input from '../../components/Input.mjs' + +import logic from '../../../logic/index.mjs' + +class Footer extends Component { + constructor() { + super(document.createElement('footer')) + this.setClassName('footer') + + const addPostButton = new Button + addPostButton.setText('+') + this.add(addPostButton) + + const self = this + + addPostButton.onClick(() => { + const createPost = new Component(document.createElement('section')) + createPost.setClassName('create-post-section') + self.add(createPost) + + const createPostTitle = new Heading(2) + createPostTitle.setClassName('create-post-section__title') + createPostTitle.setText('Create Post') + createPost.add(createPostTitle) + + const createPostForm = new Form + createPostForm.setClassName('form') + createPost.add(createPostForm) + + createPostForm.onSubmit(event => { + event.preventDefault() + + //const postImageInput = document.getElementById('post-image-input') + const postImage = postImageInput.getValue() + const postCaption = postCaptionInput.getValue() + + try { + logic.createPost(postImage, postCaption) + + self.remove(createPost) + + self.onPostCreatedCallback() + } catch (error) { + console.error(error) + + alert(error.message) + } + }) + + const postImageField = new Component(document.createElement('div')) + postImageField.setClassName('form__field') + createPostForm.add(postImageField) + + const postImageLabel = new Label + postImageLabel.setFor('post-image-input') + postImageLabel.setText('Image') + postImageField.add(postImageLabel) + + const postImageInput = new Input + postImageInput.setClassName('form__input') + postImageInput.setId(postImageLabel.getFor()) + postImageField.add(postImageInput) + + const postCaptionField = new Component(document.createElement('div')) + postCaptionField.setClassName('form__field') + createPostForm.add(postCaptionField) + + const postCaptionLabel = new Label + postCaptionLabel.setFor('post-caption-input') + postCaptionLabel.setText('Caption') + postCaptionField.add(postCaptionLabel) + + const postCaptionInput = new Input + postCaptionInput.setClassName('form__input') + postCaptionInput.setId(postCaptionLabel.getFor()) + postCaptionField.add(postCaptionInput) + + const postButtons = new Component(document.createElement('div')) + postButtons.setClassName('create-post-section__buttons') + createPostForm.add(postButtons) + + const postSubmitButton = new Button + postSubmitButton.setType('submit') + postSubmitButton.setText('Create') + postButtons.add(postSubmitButton) + + const postCancelButton = new Button + postCancelButton.setType('reset') + postCancelButton.setText('Cancel') + postButtons.add(postCancelButton) + + postCancelButton.onClick(() => self.remove(createPost)) + }) + } + + onPostCreated(callback) { + this.onPostCreatedCallback = callback + } +} + +export default Footer \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Header.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Header.mjs new file mode 100644 index 000000000..1e143eb7f --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Header.mjs @@ -0,0 +1,101 @@ +import Component from '../../Component.mjs' +import Paragraph from '../../components/Paragraph.mjs' +import Button from '../../components/Button.mjs' + +import logic from '../../../logic/index.mjs' + +class Header extends Component { + constructor() { + super(document.createElement('header')) + this.setClassName('header') + + const userName = new Paragraph + userName.setClassName('header__user-name') + this.add(userName) + + try { + const name = logic.getUserName() + + userName.setText('Hello, ' + name + '!') + } catch (error) { + console.error(error) + + alert(error.message) + } + const self = this + + const homeButton = new Button + homeButton.setText('🏚️') + this.add(homeButton) + + + homeButton.onClick(() => { + homeButton.addClassName('Button--active') + + followingButton.removeClassName('Button--active') + favsButton.removeClassName('Button--active') + + self.onHomeClickCallback() + }) + + const followingButton = new Button + followingButton.setText('🦄') + this.add(followingButton) + + followingButton.onClick(() => { + followingButton.addClassName('Button--active') + + homeButton.removeClassName('Button--active') + favsButton.removeClassName('Button--active') + + self.onFollowingClickCallback() + + }) + + const favsButton = new Button + favsButton.setText('🏴') + this.add(favsButton) + + favsButton.onClick(() => { + + favsButton.addClassName('Button--active') + + followingButton.removeClassName('Button--active') + homeButton.removeClassName('Button--active') + + self.onFavsClickCallback() + + }) + + + const logoutButton = new Button + logoutButton.setClassName('logout-button') + logoutButton.setText('Logout') + this.add(logoutButton) + + logoutButton.onClick(() => { + try { + logic.logoutUser() + + location.href = '../login' + } catch (error) { + console.error(error) + + alert(error.message) + } + }) + } + onHomeClick(callback) { + this.onHomeClickCallback = callback + } + + onFavsClick(callback) { + this.onFavsClickCallback = callback + } + + onFollowingClick(callback) { + this.onFollowingClickCallback = callback + } +} + +export default Header \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Post.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Post.mjs new file mode 100644 index 000000000..55df85f5f --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/Post.mjs @@ -0,0 +1,210 @@ +import Component from '../../Component.mjs' +import Heading from '../../components/Heading.mjs' +import Image from '../../components/Image.mjs' +import Paragraph from '../../components/Paragraph.mjs' +import Button from '../../components/Button.mjs' +import Form from '../../components/Form.mjs' +import Label from '../../components/Label.mjs' +import Input from '../../components/Input.mjs' + +import logic from '../../../logic/index.mjs' + +import formatTime from '../../../util/formatTime.mjs' + +class Post extends Component { + constructor(post) { + super(document.createElement('article')) + this.setClassName('post') + + const top = new Component(document.createElement('div')) + top.setClassName('post__top') + this.add(top) + + const postAuthorTitle = new Heading(3) + postAuthorTitle.setClassName('post__author') + postAuthorTitle.setText(post.author.username) + top.add(postAuthorTitle) + + const self = this + + if (post.author !== logic.getUserUsername()) { + const followButton = new Button + followButton.setClassName('post__button') + followButton.setText(post.author.following ? 'Unfollow' : 'Follow') + top.add(followButton) + + followButton.onClick(() => { + try { + logic.toggleFollowUser(post.author.username) + + self.onFollowUserToggledCallback() + } catch (error) { + console.error(error) + + alert(error.message) + } + }) + } + const postImage = new Image + postImage.setClassName('post__image') + postImage.setUrl(post.image) + this.add(postImage) + + const postCaptionText = new Paragraph + postCaptionText.setClassName('post__caption') + postCaptionText.setText(post.caption) + this.add(postCaptionText) + + const postActionButtons = new Component(document.createElement('div')) + postActionButtons.setClassName('post__actions') + this.add(postActionButtons) + + const postToggleLikeButton = new Button + postToggleLikeButton.setText((post.like ? '❤️' : '🤍') + ' ' + post.likes.length + ' like' + (post.likes.length === 1 ? '' : 's')) + postActionButtons.add(postToggleLikeButton) + + postToggleLikeButton.onClick(() => { + try { + logic.toggleLikePost(post.id) + + self.onPostLikeToggledCallback() + } catch (error) { + console.error(error) + + alert(error.message) + } + }) + + const postToggleFavButton = new Button + postToggleFavButton.setText(post.fav ? '🏴' : '🏳️') + postActionButtons.add(postToggleFavButton) + + postToggleFavButton.onClick(() => { + try { + logic.toggleFavPost(post.id) + + self.onPostFavToggledCallback() + } catch (error) { + console.error(error) + + alert(error.message) + } + }) + + if (post.author === logic.getUserUsername()) { + const postDeleteButton = new Button + postDeleteButton.setText('Delete') + postActionButtons.add(postDeleteButton) + + postDeleteButton.onClick(() => { + if (confirm('Delete post?')) + try { + logic.deletePost(post.id) + + // self.clearPosts() + // self.listPosts() + self.onPostDeletedCallback() + } catch (error) { + console.error(error) + + alert(error.message) + + if (error.message === 'post not found') { + // self.clearPosts() + // self.listPosts() + self.onPostDeletedCallback() + } + } + }) + + const editButton = new Button + editButton.setText('Edit') + postActionButtons.add(editButton) + + let editCaptionForm + + editButton.onClick(() => { + //if (editCaptionForm && self.has(editCaptionForm)) return + if (editCaptionForm) return + + editCaptionForm = new Form + self.add(editCaptionForm) + + const editCaptionLabel = new Label + editCaptionLabel.setFor('edit-caption-input') + editCaptionForm.add(editCaptionLabel) + + const editCaptionInput = new Input + editCaptionInput.setId(editCaptionLabel.getFor()) + editCaptionInput.setValue(post.caption) + editCaptionForm.add(editCaptionInput) + + const editCaptionSubmitButton = new Button + editCaptionSubmitButton.setType('submit') + editCaptionSubmitButton.setText('Save') + editCaptionForm.add(editCaptionSubmitButton) + + const editCaptionCancelButton = new Button + editCaptionCancelButton.setText('Cancel') + editCaptionCancelButton.setType('button') + editCaptionForm.add(editCaptionCancelButton) + + // editCaptionCancelButton.onClick(() => self.remove(editCaptionForm)) + editCaptionCancelButton.onClick(() => { + self.remove(editCaptionForm) + + editCaptionForm = undefined + }) + + editCaptionForm.onSubmit(event => { + event.preventDefault() + + try { + const newCaption = editCaptionInput.getValue() + + logic.updatePostCaption(post.id, newCaption) + + self.remove(editCaptionForm) + + editCaptionForm = undefined + + self.onPostCaptionEditedCallback() + } catch (error) { + console.error(error) + + alert(error.message) + + if (error.message === 'post not found') + self.onPostCaptionEditedCallback() + } + }) + }) + } + + const postDateTime = new Component(document.createElement('time')) + postDateTime.setClassName('post__time') + postDateTime.setText(formatTime(new Date(post.date))) + this.add(postDateTime) + } + + onPostDeleted(callback) { + this.onPostDeletedCallback = callback + } + + onPostCaptionEdited(callback) { + this.onPostCaptionEditedCallback = callback + } + + onPostLikeToggled(callback) { + this.onPostLikeToggledCallback = callback + } + + onPostFavToggled(callback) { + this.onPostFavToggledCallback = callback + } + onFollowUserToggled(callback) { + this.onFollowUserToggledCallback = callback + } +} + +export default Post \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/PostList.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/PostList.mjs new file mode 100644 index 000000000..0c7632d8c --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/components/PostList.mjs @@ -0,0 +1,65 @@ +import Component from '../../Component.mjs' +import Post from './Post.mjs' + +import logic from '../../../logic/index.mjs' + +class PostList extends Component { + constructor() { + super(document.createElement('section')) + + this.setClassName('post-list') + } + + clearPosts() { + for (let i = this.container.children.length - 1; i > -1; i--) { + const child = this.container.children[i] + + this.container.removeChild(child) + } + } + + listPosts() { + try { + const posts = logic.getAllPosts() + + const self = this + + posts.forEach(_post => { + const post = new Post(_post) + + post.onPostDeleted(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostCaptionEdited(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostLikeToggled(() => { + self.clearPosts() + self.listPosts() + }) + + post.onPostFavToggled(() => { + self.clearPosts() + self.listPosts() + }) + + post.onUserFollowToggled(() => { + self.clearPosts() + self.listPosts() + }) + + self.add(post) + }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } +} + +export default PostList \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.css b/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.css new file mode 100644 index 000000000..7409db2e6 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.css @@ -0,0 +1,147 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.section__form { + box-sizing: border-box; + position: fixed; + background-color: white; + width: 100%; + bottom: 2.3rem; + padding: 1rem +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; + margin-bottom: 20%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; + background-color: #FF0303; + border-radius: 60px; + padding-top: 3px; + padding-bottom: 3px; + padding-left: 6px; + padding-right: 6px; +} + +.add-post-button { + font-size: inherit; + background-color: #FF0303; + border-radius: 100%; + +} + +.post-list { + display: flex; + flex-direction: column; + gap: 1rem; +} + +.post { + /* border: 1px solid black; */ + box-shadow: 1px 1px 10px 1px lightgray; +} + +.post__author { + margin: .5rem; +} + +.post__image { + width: 100%; +} + +.post__caption { + margin: .5rem; +} + +.post__actions { + margin: .5rem; +} + +.post__time { + display: block; + margin: .5rem; + color: silver; + font-size: .9rem; +} + +.header { + position: fixed; + left: 0; + top: 0; + width: 100%; + display: flex; + justify-content: right; + align-items: center; + gap: 1rem; + background-color: #f25252; + box-sizing: border-box; + box-shadow: 0px 1px 1px lightgray; +} + +.header__user-name { + margin: 0; +} + +.main { + margin-top: 3.5rem; + margin-bottom: 3rem; +} + +.footer { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + display: flex; + justify-content: center; + background-color: white; + padding: .5rem 0; + box-shadow: 0px -1px 1px lightgray; +} + +.create-post-section { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + background-color: white; + padding: .5rem; + box-sizing: border-box; +} + +.create-post-section__title { + margin: .5rem 0; +} + +.create-post-section__buttons { + display: flex; + justify-content: center; + gap: 1rem; + font-size: inherit; + background-color: #FF0303; + border-radius: 60px; + padding-top: 3px; + padding-bottom: 3px; + padding-left: 6px; + padding-right: 6px; +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.html b/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.html new file mode 100644 index 000000000..b21ad3b68 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.html @@ -0,0 +1,18 @@ + + + + + + + Home + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.mjs new file mode 100644 index 000000000..0789da324 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/home/index.mjs @@ -0,0 +1,72 @@ +import Component from '../Component.mjs' +import Header from './components/Header.mjs' +import PostList from './components/PostList.mjs' +import Footer from './components/Footer.mjs' + +const home = new Component(document.body) +const header = new Header +home.add(header) + +header.onHomeClick(() => { + if (!body.has(postList)) { + if (favPostList && body.has(favPostList)) + body.remove(favPostList) + else if (followingPostList && body.has(followingPostList)) + body.remove(followingPostList) + + body.add(postList) + + postList.clearPosts() + postList.listPosts() + } +}) + +let favPostList + +header.onFavsClick(() => { + if (!favPostList || body.has(favPostList)) { + if (body.has(postList)) + body.remove(postList) + else if (followingPostList && body.has(followingPostList)) + body.remove(followingPostList) + + favPostList = new FavPostList + body.add(favPostList) + + favPostList.listPosts() + } +}) + +let followingPostList + +header.onFollowingClick(() => { + if (!followingPostList || !body.has(followingPostList)) { + if (body.has(postList)) + body.remove(postList) + else if (favPostList && body.has(favPostList)) + favPostList && body.remove(favPostList) + + followingPostList = new FollowingUserPostList + body.add(followingPostList) + + followingPostList.listPosts() + } +}) + + +const body = new Component(document.createElement('main')) +body.setClassName('view main') +home.add(body) + +const postList = new PostList +body.add(postList) + +postList.listPosts() + +const footer = new Footer +home.add(footer) + +footer.onPostCreated(() => { + postList.clearPosts() + postList.listPosts() +}) \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.css b/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.css new file mode 100644 index 000000000..f0a1836cf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.css @@ -0,0 +1,28 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.html b/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.html new file mode 100644 index 000000000..b3eb0c122 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.html @@ -0,0 +1,38 @@ + + + + + + + Login + + + + + + + +
+

Login

+ +
+
+ + +
+ +
+ + +
+ + +
+ + Register +
+ + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.mjs new file mode 100644 index 000000000..00950e146 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/login/index.mjs @@ -0,0 +1,34 @@ +import Form from '../components/Form.mjs' +import Link from '../components/Link.mjs' + +import logic from '../../logic/index.mjs' + +const loginForm = new Form('form') + +loginForm.onSubmit(event => { + event.preventDefault() + + const usernameInput = document.getElementById('username-input') + const passwordInput = document.getElementById('password-input') + + const username = usernameInput.value + const password = passwordInput.value + + try { + logic.loginUser(username, password) + + location.href = '../home' + } catch (error) { + console.error(error) + + alert(error.message) + } +}) + +const registerLink = new Link('a') + +registerLink.onClick(event => { + event.preventDefault() + + location.href = '../register' +}) \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.css b/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.css new file mode 100644 index 000000000..f0a1836cf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.css @@ -0,0 +1,28 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.html b/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.html new file mode 100644 index 000000000..3889092bc --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.html @@ -0,0 +1,59 @@ + + + + + + + Register + + + + + + + +
+

Register

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ + Login +
+ + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.mjs b/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.mjs new file mode 100644 index 000000000..a8363efcf --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app copy2/views/register/index.mjs @@ -0,0 +1,44 @@ +import Form from '../components/Form.mjs' +import Link from '../components/Link.mjs' + +import logic from '../../logic/index.mjs' + +const registerForm = new Form('form') + +registerForm.onSubmit(event => { + event.preventDefault() + + const nameInput = document.getElementById('name-input') + const surnameInput = document.getElementById('surname-input') + const emailInput = document.getElementById('email-input') + const usernameInput = document.getElementById('username-input') + const passwordInput = document.getElementById('password-input') + const passwordRepeatInput = document.getElementById('password2-input') + + const name = nameInput.value + const surname = surnameInput.value + const email = emailInput.value + const username = usernameInput.value + const password = passwordInput.value + const passwordRepeat = passwordRepeatInput.value + + try { + logic.registerUser(name, surname, email, username, password, passwordRepeat) + + alert('user successfully registered') + + location.href = '../login' + } catch (error) { + console.error(error) + + alert(error.message) + } +}) + +const loginLink = new Link('a') + +loginLink.onClick(event => { + event.preventDefault() + + location.href = '../login' +}) \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app1/home.html b/staff/lucas-orts/stuff/zzz/app1/home.html new file mode 100644 index 000000000..547526a22 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app1/home.html @@ -0,0 +1,20 @@ + + + + + + + Home + + + + +

Home

+ + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app1/login.html b/staff/lucas-orts/stuff/zzz/app1/login.html new file mode 100644 index 000000000..1cf4a2308 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app1/login.html @@ -0,0 +1,66 @@ + + + + + + + Login + + + + + +

Login

+
+ + + + + + + +
+ + Register + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app1/register.html b/staff/lucas-orts/stuff/zzz/app1/register.html new file mode 100644 index 000000000..d2db016c9 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app1/register.html @@ -0,0 +1,22 @@ + + + + + + + Register + + + + +

Register

+ + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app2/home.html b/staff/lucas-orts/stuff/zzz/app2/home.html new file mode 100644 index 000000000..44cc4e5ee --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app2/home.html @@ -0,0 +1,23 @@ + + + + + + + Home + + + + + +

Home

+ + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app2/login.html b/staff/lucas-orts/stuff/zzz/app2/login.html new file mode 100644 index 000000000..559f3a2fe --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app2/login.html @@ -0,0 +1,53 @@ + + + + + + + Login + + + +

Login

+ +
+ + + + + + + +
+ Register + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app2/register.html b/staff/lucas-orts/stuff/zzz/app2/register.html new file mode 100644 index 000000000..96abed85d --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app2/register.html @@ -0,0 +1,133 @@ + + + + + + + Register + + + + + +

Register

+ +
+ + + + + + + + + + + + + + + + + + + +
+ + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app3/home.html b/staff/lucas-orts/stuff/zzz/app3/home.html new file mode 100644 index 000000000..e109f7966 --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app3/home.html @@ -0,0 +1,34 @@ + + + + + + + Home + + + + +

Home

+ + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/stuff/zzz/app3/login.html b/staff/lucas-orts/stuff/zzz/app3/login.html new file mode 100644 index 000000000..2b090396d --- /dev/null +++ b/staff/lucas-orts/stuff/zzz/app3/login.html @@ -0,0 +1,43 @@ + + + + + + + Login + + + + + +

Login

+ +
+ + + + + + + +
+ + + + + + \ No newline at end of file From 5cc0f35c3404c84263689e34362c49139d56aad9 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 3 Jul 2024 14:04:22 +0200 Subject: [PATCH 12/21] implement register in React #60 --- .../ponies/app/views/login/index.jsx | 1 + .../ponies/app/views/register/index.css | 28 ++++++ .../ponies/app/views/register/index.html | 82 ++++++++-------- .../ponies/app/views/register/index.jsx | 93 +++++++++++++++++++ 4 files changed, 160 insertions(+), 44 deletions(-) create mode 100644 staff/lucas-orts/ponies/app/views/register/index.css create mode 100644 staff/lucas-orts/ponies/app/views/register/index.jsx diff --git a/staff/lucas-orts/ponies/app/views/login/index.jsx b/staff/lucas-orts/ponies/app/views/login/index.jsx index 8f07626f0..0bdb7ecdb 100644 --- a/staff/lucas-orts/ponies/app/views/login/index.jsx +++ b/staff/lucas-orts/ponies/app/views/login/index.jsx @@ -43,6 +43,7 @@ class Login extends Component {
+
diff --git a/staff/lucas-orts/ponies/app/views/register/index.css b/staff/lucas-orts/ponies/app/views/register/index.css new file mode 100644 index 000000000..f0a1836cf --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/register/index.css @@ -0,0 +1,28 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/register/index.html b/staff/lucas-orts/ponies/app/views/register/index.html index 3889092bc..f6565ea13 100644 --- a/staff/lucas-orts/ponies/app/views/register/index.html +++ b/staff/lucas-orts/ponies/app/views/register/index.html @@ -6,54 +6,48 @@ Register - - -
-

Register

- -
-
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- - -
- - Login -
- - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/register/index.jsx b/staff/lucas-orts/ponies/app/views/register/index.jsx new file mode 100644 index 000000000..03a19196f --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/register/index.jsx @@ -0,0 +1,93 @@ +import logic from '../../logic/index.mjs' + +const Component = React.Component + +class Register extends Component { + constructor() { + super() + } + + handleLoginClick(event) { + event.preventDefault() + + location.href = '../login' + } + + handleRegisterSubmit(event) { + event.preventDefault() + + const form = event.target + + const nameInput = form['name-input'] + const surNameInput = form['surname-input'] + const emailInput = form['email-input'] + const usernameInput = form['username-input'] + const passwordInput = form['password-input'] + const passwordRepeatInput = form['password-repeat-input'] + + const name = nameInput.value + const surname = surNameInput.value + const email = emailInput.value + const username = usernameInput.value + const password = passwordInput.value + const passwordRepeat = passwordRepeatInput.value + + try { + logic.registerUser(name, surname, email, username, password, passwordRepeat) + + location.href = '../login' + + alert('user successfully registered') + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + render() { + return
+

Register

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + +
+ + Login +
+ } +} + +const root = ReactDOM.createRoot(document.getElementById('root')) +root.render() \ No newline at end of file From 5df307c87861d42eb2f080af6f1b09ee3afa2361 Mon Sep 17 00:00:00 2001 From: root Date: Sun, 7 Jul 2024 10:56:01 +0200 Subject: [PATCH 13/21] implement home in React #60 --- .../ponies/app/logic/getUserName.mjs | 4 +- .../views/home/components/FavsPostList.jsx | 106 ++++++++++++++ .../home/components/FollowingPostList.jsx | 106 ++++++++++++++ .../app/views/home/components/Footer.jsx | 75 ++++++++++ .../app/views/home/components/Header.jsx | 60 ++++++++ .../ponies/app/views/home/components/Post.jsx | 137 ++++++++++++++++++ .../app/views/home/components/PostList.jsx | 106 ++++++++++++++ .../ponies/app/views/home/index.css | 128 ++++++++++++++++ .../ponies/app/views/home/index.html | 49 ++++++- .../ponies/app/views/home/index.jsx | 56 +++++++ 10 files changed, 822 insertions(+), 5 deletions(-) create mode 100644 staff/lucas-orts/ponies/app/views/home/components/FavsPostList.jsx create mode 100644 staff/lucas-orts/ponies/app/views/home/components/FollowingPostList.jsx create mode 100644 staff/lucas-orts/ponies/app/views/home/components/Footer.jsx create mode 100644 staff/lucas-orts/ponies/app/views/home/components/Header.jsx create mode 100644 staff/lucas-orts/ponies/app/views/home/components/Post.jsx create mode 100644 staff/lucas-orts/ponies/app/views/home/components/PostList.jsx create mode 100644 staff/lucas-orts/ponies/app/views/home/index.css create mode 100644 staff/lucas-orts/ponies/app/views/home/index.jsx diff --git a/staff/lucas-orts/ponies/app/logic/getUserName.mjs b/staff/lucas-orts/ponies/app/logic/getUserName.mjs index f92bd7b0d..6d6de5813 100644 --- a/staff/lucas-orts/ponies/app/logic/getUserName.mjs +++ b/staff/lucas-orts/ponies/app/logic/getUserName.mjs @@ -3,9 +3,9 @@ import data from '../data/index.mjs' const getUserName = () => { const user = data.findUser(user => user.username === sessionStorage.username) - if (user === null) + if (user === null) { throw new Error('user not found') - + } return user.name } diff --git a/staff/lucas-orts/ponies/app/views/home/components/FavsPostList.jsx b/staff/lucas-orts/ponies/app/views/home/components/FavsPostList.jsx new file mode 100644 index 000000000..949ef4c55 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/components/FavsPostList.jsx @@ -0,0 +1,106 @@ +import logic from '../../logic/index.mjs' + +const { Component } = React + +import Post from './Post.jsx' + +class FavsPostList extends Component { + constructor() { + super() + + try { + const posts = logic.getAllFavPosts() + + this.state = { posts } + } + catch (error) { + console.error(error) + + alert(error.message) + } + } + + componentWillReceiveProps(newProps) { + if (newProps.refreshStamp !== this.props.refreshStamp) + try { + const posts = logic.getAllFavPosts() + + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostDeleted() { + try { + const posts = logic.getAllFavPosts() + + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostEdited() { + try { + const posts = logic.getAllFavPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostLiked() { + try { + const posts = logic.getAllFavPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostFav() { + try { + const posts = logic.getAllFavPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handleUserFollowed() { + try { + const posts = logic.getAllFavPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + render() { + return
+ {this.state.posts.map(post => )} +
+ } +} + +export default FavsPostList \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/components/FollowingPostList.jsx b/staff/lucas-orts/ponies/app/views/home/components/FollowingPostList.jsx new file mode 100644 index 000000000..6dcb1d7b5 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/components/FollowingPostList.jsx @@ -0,0 +1,106 @@ +import logic from '../../logic/index.mjs' + +const { Component } = React + +import Post from './Post.jsx' + +class FollowingPostList extends Component { + constructor() { + super() + + try { + const posts = logic.getAllFollowingUserPosts() + + this.state = { posts } + } + catch (error) { + console.error(error) + + alert(error.message) + } + } + + componentWillReceiveProps(newProps) { + if (newProps.refreshStamp !== this.props.refreshStamp) + try { + const posts = logic.getAllFollowingUserPosts() + + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostDeleted() { + try { + const posts = logic.getAllFollowingUserPosts() + + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostEdited() { + try { + const posts = logic.getAllFollowingUserPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostLiked() { + try { + const posts = logic.getAllFollowingUserPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostFav() { + try { + const posts = logic.getAllFollowingUserPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handleUserFollowed() { + try { + const posts = logic.getAllFollowingUserPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + render() { + return
+ {this.state.posts.map(post => )} +
+ } +} + +export default FollowingPostList \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/components/Footer.jsx b/staff/lucas-orts/ponies/app/views/home/components/Footer.jsx new file mode 100644 index 000000000..4cbe1c250 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/components/Footer.jsx @@ -0,0 +1,75 @@ + +import logic from '../../../logic/index.mjs' + +const { Component } = React + +class Footer extends Component { + constructor() { + super() + + this.state = { + isFormOpen: false + } + } + + handleCreatePostClick() { + this.setState({ isFormOpen: true }) + } + + handleCancelCreatePostClick() { + this.setState({ isFormOpen: false }) + } + + handleCreatePostSubmit(event) { + event.preventDefault() + const form = event.target + + const postImageInput = form['post-image-input'] + const postCaptionInput = form['post-caption-input'] + const postImage = postImageInput.value + const postCaption = postCaptionInput.value + + try { + logic.createPost(postImage, postCaption) + + this.setState({ isFormOpen: false }) + + this.props.onPostCreated() + } catch (error) { + console.error(error) + + alert(error.message) + } + + } + + render() { + return
+ + {this.state.isFormOpen && (
+

Create Post

+
+
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ )} + +
+ + } +} + +export default Footer \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/components/Header.jsx b/staff/lucas-orts/ponies/app/views/home/components/Header.jsx new file mode 100644 index 000000000..92bed53da --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/components/Header.jsx @@ -0,0 +1,60 @@ +import logic from '../../../logic/index.mjs' + +const { Component } = React + +class Header extends Component { + constructor() { + super() + + try { + const name = logic.getUserName() + + this.state = { name } + } + catch (error) { + console.error(error) + + alert(error.message) + } + } + + + + handleHomeClick() { + this.props.onHomeClick() + } + + handleFollowClick() { + this.props.onFollowClick() + } + + handleFavsClick() { + this.props.onFavsClick() + } + + handleLogout() { + try { + logic.logoutUser() + + location.href = '../Login' + } + catch (error) { + console.error(error) + + alert(error.message) + } + } + + + render() { + return
+

Hello, {this.state.name}!

+ + + + +
+ } +} + +export default Header \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/components/Post.jsx b/staff/lucas-orts/ponies/app/views/home/components/Post.jsx new file mode 100644 index 000000000..b17b93a83 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/components/Post.jsx @@ -0,0 +1,137 @@ +import logic from '../../../logic/index.mjs' + +import formatTime from '../../../util/formatTime.mjs' + +const { Component } = React + +class Post extends Component { + constructor() { + super() + + this.state = { editPostVisible: false } + } + + handleDeletePostClick() { + if (confirm('Delete post?')) + try { + logic.deletePost(this.props.post.id) + + this.props.onPostDeleted() + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + componentWillUnmount() { + //esto hace cosas antes de que se desmonte un componente + } + handleEditPostClick() { + this.setState({ editPostVisible: true }) + } + + handleCancelEditPostClick() { + this.setState({ editPostVisible: false }) + } + + handleEditPostSubmit(event) { + event.preventDefault() + + const form = event.target + + const editCaptionInput = form['edit-caption-input'] + + const newCaption = editCaptionInput.value + + try { + logic.updatePostCaption(this.props.post.id, newCaption) + + this.setState({ editPostVisible: false }) + + this.props.onPostEdited() + } + catch (error) { + console.error(error) + + alert(error.message) + } + } + + + handleLikePostClick() { + try { + logic.toggleLikePost(this.props.post.id) + + this.props.onPostLikeToggled() + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + + handleFavPostClick() { + try { + logic.toggleFavPost(this.props.post.id) + + this.props.onPostFavToggled() + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handleFollowUserClick() { + try { + logic.toggleFollowUser(this.props.post.author.username) // { username: ..., following: true | false } + + this.props.onUserFollowToggled() + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + + render() { + const post = this.props.post + + return
+
+

{post.author.username}

+ + +
+ + + +

{post.caption}

+ +
+ + + + {post.author.username === logic.getUserUsername() && <> + + + } +
+ + + + {this.state.editPostVisible &&
+ + + + + +
} +
+ } +} + +export default Post \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/components/PostList.jsx b/staff/lucas-orts/ponies/app/views/home/components/PostList.jsx new file mode 100644 index 000000000..57a7bfe6a --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/components/PostList.jsx @@ -0,0 +1,106 @@ +import logic from '../../logic/index.mjs' + +const { Component } = React + +import Post from './Post.jsx' + +class PostList extends Component { + constructor() { + super() + + try { + const posts = logic.getAllPosts() + + this.state = { posts } + } + catch (error) { + console.error(error) + + alert(error.message) + } + } + + componentWillReceiveProps(newProps) { + if (newProps.refreshStamp !== this.props.refreshStamp) + try { + const posts = logic.getAllPosts() + + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostDeleted() { + try { + const posts = logic.getAllPosts() + + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostEdited() { + try { + const posts = logic.getAllPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostLiked() { + try { + const posts = logic.getAllPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handlePostFav() { + try { + const posts = logic.getAllPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + handleUserFollowed() { + try { + const posts = logic.getAllPosts() + this.setState({ posts }) + } catch (error) { + console.error(error) + + alert(error.message) + } + } + + render() { + return
+ {this.state.posts.map(post => )} +
+ } +} + +export default PostList \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.css b/staff/lucas-orts/ponies/app/views/home/index.css new file mode 100644 index 000000000..8617a11ee --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/index.css @@ -0,0 +1,128 @@ +.view { + display: flex; + flex-direction: column; + align-items: center; + gap: 1rem; + font-size: 1.1rem; +} + +.form { + display: flex; + flex-direction: column; + gap: .5rem; + min-width: 80%; +} + +.form__field { + display: flex; + flex-direction: column; + gap: .2rem +} + +.form__input { + font-size: inherit; +} + +.form__button { + font-size: inherit; +} + +.post-list { + display: flex; + flex-direction: column; + gap: 1rem; +} + +.post { + /* border: 1px solid black; */ + box-shadow: 1px 1px 10px 1px lightgray; +} + +.post__top { + display: flex; + margin: 0 .5rem; + align-items: center; + gap: .5rem; +} + +.post__author { + /* height: .5rem; */ +} + +.post__image { + width: 100%; +} + +.post__caption { + margin: .5rem; +} + +.post__actions { + margin: .5rem; + display: flex; + gap: .5rem; +} + +.post__time { + display: block; + margin: .5rem; + color: silver; + font-size: .9rem; +} + +.header { + position: fixed; + left: 0; + top: 0; + width: 100%; + display: flex; + justify-content: right; + align-items: center; + gap: .5rem; + background-color: white; + padding: .5rem; + box-sizing: border-box; + box-shadow: 0px 1px 1px lightgray; +} + +.header__user-name { + margin: 0; +} + +.main { + margin-top: 3.5rem; + margin-bottom: 3rem; +} + +.footer { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + display: flex; + flex-direction: column; + justify-content: center; + background-color: white; + padding: .5rem 0; + box-shadow: 0px -1px 1px lightgray; +} + +.create-post-section { + position: fixed; + bottom: 0; + left: 0; + width: 100%; + background-color: white; + padding: .5rem; + box-sizing: border-box; +} + +.create-post-section__title { + margin: .5rem 0; +} + +.create-post-section__buttons { + display: flex; + justify-content: center; + gap: 1rem; +} \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.html b/staff/lucas-orts/ponies/app/views/home/index.html index b21ad3b68..b74695aa7 100644 --- a/staff/lucas-orts/ponies/app/views/home/index.html +++ b/staff/lucas-orts/ponies/app/views/home/index.html @@ -6,13 +6,56 @@ Home - - - +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/lucas-orts/ponies/app/views/home/index.jsx b/staff/lucas-orts/ponies/app/views/home/index.jsx new file mode 100644 index 000000000..afc53ebd4 --- /dev/null +++ b/staff/lucas-orts/ponies/app/views/home/index.jsx @@ -0,0 +1,56 @@ +import Header from "./components/Header" +import PostList from "./components/PostList" +import Footer from "./components/Footer" +import FollowingPostList from "./components/FollowingPostList" +import FavsPostList from "./components/FavsPostList" + +const { Component } = React + +class Home extends Component { + constructor() { + super() + + this.state = { refreshStamp: null, view: 'home' } + } + + + handlePostCreated() { + this.setState({ refreshStamp: Date.now() }) + } + + handleHomeClick() { + this.setState({ view: 'home' }) + } + + handleFollowClick() { + this.setState({ view: 'follows' }) + } + + handleFavsClick() { + this.setState({ view: 'favs' }) + } + + render() { + return <> +
+ +
+ {this.state.view === 'home' && } + + {this.state.view === 'follows' && } + + {this.state.view === 'favs' && } +
+