diff --git a/staff/fabian-romero/react/ponies/api/data/deletePost.js b/staff/fabian-romero/react/ponies/api/data/deletePost.js
new file mode 100644
index 000000000..adb6f5bea
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/deletePost.js
@@ -0,0 +1,21 @@
+import fs from 'fs' // importo esto para saber la forma en que se tienen que leer los codigos
+
+function deletePost(condition) {
+ let json = fs.readFileSync('./data/posts.json', 'utf8') // ya no uso localstorage, uso disco y esta es la manera apra poder que se lea la info que tengo almacenada en el disco
+
+ const posts = json ? JSON.parse(json) : [] //si en el json hay algo, lo parsee, y si no.. que me devuelva un array vacio
+
+ const postIndex = posts.findIndex(condition)
+
+ if (postIndex > -1) {
+ posts.splice(postIndex, 1)
+
+ json = JSON.stringify(posts) // local no más ahora json
+ fs.writeFileSync('./data/posts.json', json)
+ }
+}
+
+export default deletePost
+// esta carpeta datos de api es solo para manejar datos no sesiones
+
+// cambiar a los validation
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/deletePost.test.js b/staff/fabian-romero/react/ponies/api/data/deletePost.test.js
new file mode 100644
index 000000000..ae38b6c1f
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/deletePost.test.js
@@ -0,0 +1,12 @@
+import deletePost from "./deletePost.js"
+
+
+const post1 = {
+ author: "Valito",
+ caption: "ÑamÑam!",
+ date: "2024-07-11T09:41:57.634Z",
+ id: "gud3txmwlqo",
+ image: "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+}
+
+deletePost(post => post.id === post1) // aqui puedo poner cualquer dato.. la logica es que me lo va a eliminar
diff --git a/staff/fabian-romero/react/ponies/api/data/demo.js b/staff/fabian-romero/react/ponies/api/data/demo.js
new file mode 100644
index 000000000..4737c3135
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/demo.js
@@ -0,0 +1,65 @@
+import fs from 'fs'
+
+const users = [] // aqui es paras cargar la info en tu local
+
+const Fabian = {
+ name: 'Fabian',
+ surname: 'Romero',
+ email: 'fabian@romero.com',
+ username: 'Fabito',
+ password: 'fabi1234'
+}
+
+const Valentin = {
+ name: 'Valentin',
+ surname: 'Romero',
+ email: 'valentin@romero.com',
+ username: 'Valito',
+ password: 'vali1234'
+}
+
+users.push(Fabian) // aqui los pusheo' para añadirlos a las arrys vacias en caso de pedirlos en alguna funcion
+users.push(Valentin)
+
+
+const usersJSON = JSON.stringify(users)
+
+console.log('usersJSON', usersJSON)
+
+fs.writeFileSync('./data/users.json', usersJSON)
+
+const usersJSON2 = fs.readFileSync('./data/users.json', 'utf-8')
+
+console.log('usersJSON2', usersJSON2)
+
+const posts = []
+
+const post1 = {
+
+ author: "Fabito",
+ caption: "TOT EL DIA!!",
+ date: "2024-07-10T12:42:54.986Z",
+ id: "gho3apb3njs",
+ image: "https://media.tenor.com/LLTYGBtru5kAAAAM/mila-stauffer-whatever.gif"
+}
+
+const post2 = {
+ author: "Valito",
+ caption: "ÑamÑam!",
+ date: "2024-07-11T09:41:57.634Z",
+ id: "gud3txmwlqo",
+ image: "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+}
+
+posts.push(post1)
+posts.push(post2)
+
+const postsJSON = JSON.stringify(posts)
+
+console.log('postsJSON', postsJSON)
+
+fs.writeFileSync('./data/posts.json', postsJSON)
+
+const postsJSON2 = fs.readFileSync('./data/users.json', 'utf-8')
+
+console.log('postsJSON2', postsJSON2)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/findPost.js b/staff/fabian-romero/react/ponies/api/data/findPost.js
new file mode 100644
index 000000000..aa4cc46f3
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/findPost.js
@@ -0,0 +1,13 @@
+import fs from 'fs'
+
+function findPost(condition) {
+ let json = fs.readFileSync('./data/posts.json', 'utf8')
+
+ const posts = json ? JSON.parse(json) : []
+
+ const post = posts.find(condition)
+
+ return post || null
+}
+
+export default findPost // este se queda tal cual porque no tiene stringyfy
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/findPost.test.js b/staff/fabian-romero/react/ponies/api/data/findPost.test.js
new file mode 100644
index 000000000..b8d541cad
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/findPost.test.js
@@ -0,0 +1,3 @@
+import findPost from './findPost.js'
+
+console.log(findPost(post => post.author === "Valito"))
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/findPosts.js b/staff/fabian-romero/react/ponies/api/data/findPosts.js
new file mode 100644
index 000000000..cc0dd19db
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/findPosts.js
@@ -0,0 +1,14 @@
+import fs from 'fs'
+
+function findPosts(condition) {
+
+ let json = fs.readFileSync('./data/posts.json', 'utf8')
+
+ const posts = json ? JSON.parse(json) : []
+
+ const foundPosts = posts.filter(condition)
+
+ return foundPosts
+}
+
+export default findPosts
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/findPosts.test.js b/staff/fabian-romero/react/ponies/api/data/findPosts.test.js
new file mode 100644
index 000000000..13f6f21f9
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/findPosts.test.js
@@ -0,0 +1,3 @@
+import findPosts from './findPosts.js'
+
+console.log(findPosts(post => post.author === 'Valito'))
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/findUser.js b/staff/fabian-romero/react/ponies/api/data/findUser.js
new file mode 100644
index 000000000..394321a40
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/findUser.js
@@ -0,0 +1,13 @@
+import fs from 'fs'
+
+function findUser(condition) {
+ let json = fs.readFileSync('./data/users.json', 'utf8')
+
+ const users = json ? JSON.parse(json) : []
+
+ const user = users.find(condition)
+
+ return user || null
+}
+
+export default findUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/findUser.test.js b/staff/fabian-romero/react/ponies/api/data/findUser.test.js
new file mode 100644
index 000000000..1da17458f
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/findUser.test.js
@@ -0,0 +1,4 @@
+import findUser from './findUser.js'
+
+console.log(findUser(user => user.surname === "Romero"))
+console.log(findUser(user => user.username === "Valito"))
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/index.js b/staff/fabian-romero/react/ponies/api/data/index.js
new file mode 100644
index 000000000..d4065b125
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/index.js
@@ -0,0 +1,21 @@
+import deletePost from './deletePost'
+import findPost from './findPost'
+import findPosts from './findPosts'
+import findUser from './findUser'
+import insertPost from './insertPost'
+import insertUser from './insertUser'
+import updatePost from './updatePost'
+import updateUser from './updateUser'
+
+const data = {
+ deletePost,
+ findPost,
+ findPosts,
+ findUser,
+ insertPost,
+ insertUser,
+ updatePost,
+ updateUser
+}
+
+export default data
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/insertPost.js b/staff/fabian-romero/react/ponies/api/data/insertPost.js
new file mode 100644
index 000000000..b8473e94b
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/insertPost.js
@@ -0,0 +1,15 @@
+import fs from 'fs'
+
+function insertPost(post) {
+ let json = fs.readFileSync('./data/posts.json', 'utf8')
+
+ const posts = json ? JSON.parse(json) : []
+
+ posts.push(post)
+
+ json = JSON.stringify(posts)
+
+ fs.writeFileSync('./data/posts.json', json)
+}
+
+export default insertPost
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/insertPost.test.js b/staff/fabian-romero/react/ponies/api/data/insertPost.test.js
new file mode 100644
index 000000000..19df13333
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/insertPost.test.js
@@ -0,0 +1,29 @@
+import insertPost from './insertPost.js'
+
+const post = {
+ author: "Valito",
+ caption: "ÑamÑam!",
+ date: "2024-07-11T09:41:57.634Z",
+ id: "gud3txmwlqo",
+ image: "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+}
+
+const post2 = {
+ author: "Valito",
+ caption: "ÑamÑam!",
+ date: "2024-07-11T09:41:57.634Z",
+ id: "gud3txmwlqo",
+ image: "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+}
+
+const post3 = {
+ author: "Valito",
+ caption: "ÑamÑam!",
+ date: "2024-07-11T09:41:57.634Z",
+ id: "gud3txmwlqo",
+ image: "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+}
+
+insertPost(post)
+insertPost(post2)
+insertPost(post3)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/insertUser.Test.js b/staff/fabian-romero/react/ponies/api/data/insertUser.Test.js
new file mode 100644
index 000000000..858f7f922
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/insertUser.Test.js
@@ -0,0 +1,15 @@
+import insertUser from './insertUser.js'
+
+const user = {
+ name: 'Fabian',
+ surname: 'Romero',
+ email: 'fabian@romero.com',
+ username: 'Fabito',
+ password: 'fabi1234'
+}
+
+insertUser(user)
+
+// para probar los test tengo que abrir la consola y escribir
+
+// node data/demo.js
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/insertUser.js b/staff/fabian-romero/react/ponies/api/data/insertUser.js
new file mode 100644
index 000000000..17456e8bc
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/insertUser.js
@@ -0,0 +1,15 @@
+import fs from 'fs'
+
+function insertUser(user) {
+ let json = fs.readFileSync('./data/users.json', 'utf8')
+
+ const users = json ? JSON.parse(json) : []
+
+ users.push(user)
+
+ json = JSON.stringify(users)
+
+ fs.writeFileSync('./data/users.json', json)
+}
+
+export default insertUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/posts.json b/staff/fabian-romero/react/ponies/api/data/posts.json
new file mode 100644
index 000000000..fdb27ab7a
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/posts.json
@@ -0,0 +1,37 @@
+[
+ {
+ "author": "Valito",
+ "caption": "ÑamÑam!",
+ "date": "2024-07-11T09:41:57.634Z",
+ "id": "gud3txmwlqo",
+ "image": "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+ },
+ {
+ "author": "Valito",
+ "caption": "ÑamÑam!",
+ "date": "2024-07-11T09:41:57.634Z",
+ "id": "gud3txmwlqo",
+ "image": "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+ },
+ {
+ "author": "Valito",
+ "caption": "ÑamÑam!",
+ "date": "2024-07-11T09:41:57.634Z",
+ "id": "gud3txmwlqo",
+ "image": "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+ },
+ {
+ "author": "Valito",
+ "caption": "ÑamÑam!",
+ "date": "2024-07-11T09:41:57.634Z",
+ "id": "gud3txmwlqo",
+ "image": "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+ },
+ {
+ "author": "Valito",
+ "caption": "ÑamÑam!",
+ "date": "2024-07-11T09:41:57.634Z",
+ "id": "gud3txmwlqo",
+ "image": "https://media.tenor.com/u3QduFHVtJ8AAAAM/tacos-dog.gif"
+ }
+]
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/updatePost.js b/staff/fabian-romero/react/ponies/api/data/updatePost.js
new file mode 100644
index 000000000..bd355b70d
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/updatePost.js
@@ -0,0 +1,25 @@
+import fs from 'fs'
+
+import validate from '../validate.js'
+
+function updatePost(condition, post) {
+ validate.callback(condition, 'condition')
+ vaklidate.object(post, 'post')
+
+
+ let json = fs.readFileSync('./data/posts.json', 'utf8')
+
+ const posts = json ? JSON.parse(json) : []
+
+ const index = posts.findIndex(condition)
+
+ if (index > -1) {
+ posts.splice(index, 1, post)
+
+ json = JSON.stringify(posts)
+
+ fs.writeFileSync('./data/posts.json', json)
+
+ }
+}
+export default updatePost
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/updatePost.test.js b/staff/fabian-romero/react/ponies/api/data/updatePost.test.js
new file mode 100644
index 000000000..d3eb40bc3
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/updatePost.test.js
@@ -0,0 +1,13 @@
+import updatePost from './updatePost.js'
+
+const post = {
+
+ author: "Valito",
+ caption: "tiki tiki",
+ date: "2024-07-10T12:47:25.218Z",
+ id: "mi8drcuyseo",
+ image: "https://media.tenor.com/lhUSFl0CnpEAAAAM/frenchie-french.gif"
+
+}
+
+updatePost(post => post.id === "mi8drcuyseo", post)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/updateUser.js b/staff/fabian-romero/react/ponies/api/data/updateUser.js
new file mode 100644
index 000000000..505a76a66
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/updateUser.js
@@ -0,0 +1,24 @@
+import fs from 'fs'
+
+import validate from '../validate.js'
+
+function updateUser(condition, user) {
+ validate.callback(condition, 'condition')
+ validate.object(user, 'user')
+
+ let json = fs.readFileSync('./data/user.json', 'uft8')
+
+ const user = json ? JSON.parse(json) : []
+
+ const index = users.findIndex(condition)
+
+ if (index > -1) {
+ users.splice(index, 1, user)
+
+ json = JSON.stringify(users)
+
+ fs.writeFileSync('./data/users.json', json)
+ }
+}
+
+export default updateUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/updateUser.test.js b/staff/fabian-romero/react/ponies/api/data/updateUser.test.js
new file mode 100644
index 000000000..abf97593a
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/updateUser.test.js
@@ -0,0 +1,13 @@
+import updateUser from './updateUser.js'
+
+const Valito = {
+
+ "name": "Valentin",
+ "surname": "Romero",
+ "email": "valentin@romero.com",
+ "username": "Valito",
+ "password": "vali1234"
+
+}
+
+updateUser(user => user.username === 'Valentin', Valito)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/data/users.json b/staff/fabian-romero/react/ponies/api/data/users.json
new file mode 100644
index 000000000..d6755965e
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/data/users.json
@@ -0,0 +1,16 @@
+[
+ {
+ "name": "Fabian",
+ "surname": "Romero",
+ "email": "fabian@romero.com",
+ "username": "Fabito",
+ "password": "fabi1234"
+ },
+ {
+ "name": "Valentin",
+ "surname": "Romero",
+ "email": "valentin@romero.com",
+ "username": "Valito",
+ "password": "vali1234"
+ }
+]
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/authenticateUser.js b/staff/fabian-romero/react/ponies/api/logic/authenticateUser.js
new file mode 100644
index 000000000..5d148c68e
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/authenticateUser.js
@@ -0,0 +1,18 @@
+import data from "../data/index.js"
+
+import validate from "../validate.js"
+
+const authenticateUser = (username, password) => {
+ validate.username(username)
+ validate.password(password)
+
+ const user = data.findUser(user => user.username === username)
+
+ if (user === null)
+ throw new Error('user not found')
+
+ if (user.password !== password)
+ throw new Error('wrong password')
+}
+
+export default authenticateUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/authenticateUser.test.js b/staff/fabian-romero/react/ponies/api/logic/authenticateUser.test.js
new file mode 100644
index 000000000..d05db5fd1
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/authenticateUser.test.js
@@ -0,0 +1,3 @@
+import authenticateUser from './authenticateUser.js'
+
+authenticateUser("valito", "vali1234")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/createPost.js b/staff/fabian-romero/react/ponies/api/logic/createPost.js
new file mode 100644
index 000000000..b4df88907
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/createPost.js
@@ -0,0 +1,27 @@
+import data from '../data/index.js'
+
+import generateId from '../util/generateId'
+
+const createPost = (image, caption) => {
+
+ const user = data.findeUser(user => user.username == username)
+
+ if (user === null)
+ throw new Error('user not found')
+
+ if (!image.startsWith('http'))
+ throw new Error('invalid image')
+
+ const post = {
+ id: generateId(),
+ image,
+ caption,
+ author: username,
+ date: new Date().toISOString(),
+ likes: []
+ }
+
+ data.insertPost(post)
+}
+
+export default createPost
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/createPost.test.js b/staff/fabian-romero/react/ponies/api/logic/createPost.test.js
new file mode 100644
index 000000000..9ebcd3390
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/createPost.test.js
@@ -0,0 +1,3 @@
+import createPost from './createPost.js'
+
+createPost(//MODIFICAR EJEMPLO)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/deletePost.js b/staff/fabian-romero/react/ponies/api/logic/deletePost.js
new file mode 100644
index 000000000..37ae3bf7c
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/deletePost.js
@@ -0,0 +1,20 @@
+import data from '../data/index.js'
+
+const deletePost = (username, postId) => {
+
+ const user = data.findUser(user => user.username === username)
+
+ if (user = null)
+ throw new Error('user not found')
+
+
+ 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/fabian-romero/react/ponies/api/logic/deletePost.test.js b/staff/fabian-romero/react/ponies/api/logic/deletePost.test.js
new file mode 100644
index 000000000..2cdbcbb5f
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/deletePost.test.js
@@ -0,0 +1,3 @@
+import deletePost from './deletePost.js'
+
+deletePost("samu", "3cpx3rsbvqw0")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getAllFavPosts.js b/staff/fabian-romero/react/ponies/api/logic/getAllFavPosts.js
new file mode 100644
index 000000000..f469c0989
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getAllFavPosts.js
@@ -0,0 +1,28 @@
+import data from '../data/index.js'
+
+const getAllFavPosts = username => {
+
+ 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)
+
+ const author = data.findUser(user => user.username === post.author)
+
+ post.author = {
+ username: author.username,
+ avatar: author.avatar,
+ following: user.following.includes(author.username)
+ }
+ })
+
+ return posts.reverse()
+}
+
+export default getAllFavPosts
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getAllFavPosts.test.js b/staff/fabian-romero/react/ponies/api/logic/getAllFavPosts.test.js
new file mode 100644
index 000000000..0afe5c75e
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getAllFavPosts.test.js
@@ -0,0 +1,5 @@
+import getAllFavPosts from './getAllFavPosts.js'
+
+const posts = getAllFavPosts("samu")
+
+console.log(posts)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getAllPoniesPosts.js b/staff/fabian-romero/react/ponies/api/logic/getAllPoniesPosts.js
new file mode 100644
index 000000000..566f9146d
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getAllPoniesPosts.js
@@ -0,0 +1,30 @@
+import data from '../data/index.js'
+
+const getAllPoniesPosts = username => {
+
+
+ const user = data.findUser(user => user.username ===
+ 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(username)
+
+ const author = data.findUser(user => user.username === post.author)
+
+ post.author = {
+ username: author.username,
+ avatar: author.avatar,
+ following: user.following.includes(author.username)
+ }
+ })
+
+ return posts.reverse()
+}
+
+export default getAllPoniesPosts
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getAllPoniesPosts.test.js b/staff/fabian-romero/react/ponies/api/logic/getAllPoniesPosts.test.js
new file mode 100644
index 000000000..d95e01f5f
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getAllPoniesPosts.test.js
@@ -0,0 +1,5 @@
+import getAllPoniesPosts from './getAllPoniesPosts.js'
+
+const posts = getAllPoniesPosts("samu")
+
+console.log(posts)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getAllPosts.js b/staff/fabian-romero/react/ponies/api/logic/getAllPosts.js
new file mode 100644
index 000000000..b4ab9f5a2
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getAllPosts.js
@@ -0,0 +1,28 @@
+import data from '../data/index.js'
+
+const getAllPosts = username => {
+
+ const user = data.findUser(user => user.username === 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(username)
+
+ const author = data.findUser(user => user.username === post.author)
+
+ post.author = {
+ username: author.username,
+ avatar: author.avatar,
+ following: user.following.includes(author.username)
+ }
+ })
+
+ return posts.reverse()
+}
+
+export default getAllPosts
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getAllPosts.test.js b/staff/fabian-romero/react/ponies/api/logic/getAllPosts.test.js
new file mode 100644
index 000000000..12a1130c9
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getAllPosts.test.js
@@ -0,0 +1,5 @@
+import getAllPosts from './getAllPosts.js'
+
+const posts = getAllPosts("samu")
+
+console.log(posts)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getUser.js b/staff/fabian-romero/react/ponies/api/logic/getUser.js
new file mode 100644
index 000000000..5ab5e4eb9
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getUser.js
@@ -0,0 +1,14 @@
+import data from '../data/index.js'
+
+const getUser = username => {
+ const user = data.findUser(user => user.username === username)
+
+ if (user === null)
+ throw new Error('user not found')
+
+ delete user.password
+
+ return user
+}
+
+export default getUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getUser.test.js b/staff/fabian-romero/react/ponies/api/logic/getUser.test.js
new file mode 100644
index 000000000..89421b14b
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getUser.test.js
@@ -0,0 +1,5 @@
+import getUser from './getUser.js'
+
+const user = getUser("samu")
+
+console.log(user)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/getUserName.js b/staff/fabian-romero/react/ponies/api/logic/getUserName.js
new file mode 100644
index 000000000..8f228ba4f
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getUserName.js
@@ -0,0 +1,12 @@
+import data from "../data/index.js"
+
+const getUserName = username => {
+ const user = data.findUser(user => user.username === 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/fabian-romero/react/ponies/api/logic/getUserName.test.js b/staff/fabian-romero/react/ponies/api/logic/getUserName.test.js
new file mode 100644
index 000000000..8c75e8616
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/getUserName.test.js
@@ -0,0 +1,5 @@
+import getUserName from './getUserName.js'
+
+const user = getUserName("samu")
+
+console.log(user)
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/logic/getUserUsername.mjs b/staff/fabian-romero/react/ponies/api/logic/getUserUsername.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/logic/getUserUsername.mjs
rename to staff/fabian-romero/react/ponies/api/logic/getUserUsername.js
diff --git a/staff/fabian-romero/react/ponies/api/logic/index.js b/staff/fabian-romero/react/ponies/api/logic/index.js
new file mode 100644
index 000000000..876cc7ee2
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/index.js
@@ -0,0 +1,35 @@
+import getAllPosts from './getAllPosts.js'
+import getUserName from './getUserName.js'
+import getUserUsername from './getUserUsername.js'
+import loginUser from './loginUser.js'
+import logoutUser from './logoutUser.js'
+import registerUser from './registerUser.js'
+import toggleLikePost from './toggleLikePost.js'
+import updatePostCaption from './updatePostCaption.js'
+import createPost from './createPost.js'
+import deletePost from './deletePost.js'
+import toggleFavPost from './toggleFavPost.js'
+import getAllFavPosts from './getAllFavPosts.js'
+import toggleFollowUser from './toggleFollowUser.js'
+import getAllPoniesPosts from './getAllPoniesPosts.js'
+import isUserLoggedIn from './isUserLoggedIn.js'
+
+const logic = {
+ getAllPosts,
+ getUserName,
+ getUserUsername,
+ loginUser,
+ logoutUser,
+ registerUser,
+ toggleLikePost,
+ updatePostCaption,
+ createPost,
+ deletePost,
+ toggleFavPost,
+ getAllFavPosts,
+ toggleFollowUser,
+ getAllPoniesPosts,
+ isUserLoggedIn
+}
+
+export default logic
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/registerUser.js b/staff/fabian-romero/react/ponies/api/logic/registerUser.js
new file mode 100644
index 000000000..65cb692f9
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/registerUser.js
@@ -0,0 +1,38 @@
+import data from '../data/index.js'
+import validate from '..//validate.js'
+
+const registerUser = (name, surname, email, username, password, passwordRepeat) => {
+ validate.name(name)
+ validate.name(surname, 'surname')
+ validate.email(email)
+ validate.username(username)
+ validate.password(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,
+ surname,
+ email,
+ username,
+ password,
+ favs: [],
+ following: [],
+ avatar: "https://i.pinimg.com/564x/f6/21/64/f621641d5082d74385fabb5c2afb62f5.jpg"
+ }
+
+ data.insertUser(user)
+}
+
+export default registerUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/registerUser.test.js b/staff/fabian-romero/react/ponies/api/logic/registerUser.test.js
new file mode 100644
index 000000000..c5cea719c
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/registerUser.test.js
@@ -0,0 +1,3 @@
+import registerUser from './registerUser.js'
+
+registerUser("Marti", "Herms", "marti@herms.com", "marti", "123456789", "123456789")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/toggleFavPost.js b/staff/fabian-romero/react/ponies/api/logic/toggleFavPost.js
new file mode 100644
index 000000000..33ba30629
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/toggleFavPost.js
@@ -0,0 +1,26 @@
+import data from '../data/index.js'
+
+function toggleFavPost(username, 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 === username, user)
+}
+
+export default toggleFavPost
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/toggleFavPost.test.js b/staff/fabian-romero/react/ponies/api/logic/toggleFavPost.test.js
new file mode 100644
index 000000000..64a578103
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/toggleFavPost.test.js
@@ -0,0 +1,3 @@
+import toggleFavPost from './toggleFavPost.js'
+
+toggleFavPost("samu", "abcdefghi")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/toggleFollowUser.js b/staff/fabian-romero/react/ponies/api/logic/toggleFollowUser.js
new file mode 100644
index 000000000..62006ca42
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/toggleFollowUser.js
@@ -0,0 +1,24 @@
+import data from '../data/index.js'
+
+function toggleFollowUser(username) {
+ if (!username.trim().length) throw new Error('invalid username')
+
+ const user = data.findUser(user => user.username === username)
+
+ if (!user) throw new Error('user not found')
+
+ const following = data.findUser(user => user.username === targetUsername)
+
+ if (!following) throw new Error('following user not found')
+
+ const index = user.following.indexOf(targetUsername)
+
+ if (index < 0)
+ user.following.push(username)
+ else
+ user.following.splice(index, 1)
+
+ data.updateUser(user => user.username === username, user)
+}
+
+export default toggleFollowUser
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/toggleFollowUser.test.js b/staff/fabian-romero/react/ponies/api/logic/toggleFollowUser.test.js
new file mode 100644
index 000000000..cf197ec9f
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/toggleFollowUser.test.js
@@ -0,0 +1,3 @@
+import toggleFollowUser from './toggleFollowUser.js'
+
+toggleFollowUser("samu", "marti")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/toggleLikePost.js b/staff/fabian-romero/react/ponies/api/logic/toggleLikePost.js
new file mode 100644
index 000000000..04c152ffd
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/toggleLikePost.js
@@ -0,0 +1,25 @@
+import data from '../data/index.js'
+
+function toggleLikePost(username, postId) {
+
+ const user = data.findUser(user => user.username === username)
+ if (!user) throw new Error('user not found')
+
+ 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(username)
+
+ if (index < 0)
+ post.likes.push(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/fabian-romero/react/ponies/api/logic/toggleLikePost.test.js b/staff/fabian-romero/react/ponies/api/logic/toggleLikePost.test.js
new file mode 100644
index 000000000..bf21c4353
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/toggleLikePost.test.js
@@ -0,0 +1,3 @@
+import toggleLikePost from './toggleLikePost.js'
+
+toggleLikePost("samu", "kg6nl8j0imo")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/updateAvatar.js b/staff/fabian-romero/react/ponies/api/logic/updateAvatar.js
new file mode 100644
index 000000000..91779e0a4
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/updateAvatar.js
@@ -0,0 +1,15 @@
+import data from '../data/index.js'
+
+const updateAvatar = (username, newAvatar) => {
+ if (!newAvatar.starWith('http')) throw new Error('invalid image')
+
+ const user = data.findUser(user => user.username === username)
+
+ if (user === null) throw new Error('user not found')
+
+ user.avatar = newAvatar
+
+ data.updateUser(user => user.username === username)
+}
+
+export default updateAvatar
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/updateAvatar.test.js b/staff/fabian-romero/react/ponies/api/logic/updateAvatar.test.js
new file mode 100644
index 000000000..70d2bed29
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/updateAvatar.test.js
@@ -0,0 +1,3 @@
+import updateAvatar from './updateAvatar.js'
+
+updateAvatar("samu", "https//:jbvidbviobfiofobi")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/updatePassword.js b/staff/fabian-romero/react/ponies/api/logic/updatePassword.js
new file mode 100644
index 000000000..79250ef31
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/updatePassword.js
@@ -0,0 +1,27 @@
+import data from '../data/index.js'
+
+const USER_REGEX = /^(?!.*\s{2})[a-zA-Z0-9._-]{4,16}$/
+
+const updatePassword = (username, oldPassword, newPassword, newPasswordRepeat) => {
+ if (!USER_REGEX.test(username)) throw new Error('invalid username')
+
+ if (oldPassword.trim().length < 8) throw new Error('invalid password')
+
+ if (newPassword.trim().length < 8) throw new Error('invalid password')
+
+ if (oldPassword === newPassword) throw new Error('new password is equal to old password')
+
+ if (newPassword !== newPasswordRepeat) throw new Error('passwords do not match')
+
+ const user = data.findUser(user => user.username === username)
+
+ if (user === null) throw new Error('user not found')
+
+ if (oldPassword !== user.password) throw new Error('invalid password')
+
+ user.password = newPassword
+
+ data.updateUser(user => user.username === username, user)
+}
+
+export default updatePassword
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/updatePassword.test.js b/staff/fabian-romero/react/ponies/api/logic/updatePassword.test.js
new file mode 100644
index 000000000..ab8fffebb
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/updatePassword.test.js
@@ -0,0 +1,3 @@
+import updatePassword from './updatePassword.js'
+
+updatePassword("123123123", "123456789", "samu")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/logic/updatePostCaption.js b/staff/fabian-romero/react/ponies/api/logic/updatePostCaption.js
new file mode 100644
index 000000000..094574c93
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/updatePostCaption.js
@@ -0,0 +1,20 @@
+import data from '../data/index.js'
+
+const updatePostCaption = (username, postId, newCaption) => {
+
+ const user = data.findUser(user => user.username === username)
+
+ if (user === null) throw new Error('user not found')
+
+ if (postId.trim().length === 0) throw new Error('invalid postId')
+
+ const post = data.findPost(post => post.id === postId)
+
+ if (post === undefined) 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/fabian-romero/react/ponies/api/logic/updatePostCaption.test.js b/staff/fabian-romero/react/ponies/api/logic/updatePostCaption.test.js
new file mode 100644
index 000000000..ce5a7da27
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/logic/updatePostCaption.test.js
@@ -0,0 +1,3 @@
+import updatePostCaption from './updatePostCaption.js'
+
+updatePostCaption("samu", "abcdefghi", "Hello, soy Samu")
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/package.json b/staff/fabian-romero/react/ponies/api/package.json
new file mode 100644
index 000000000..5b9d33718
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "api",
+ "version": "1.0.0",
+ "description": "",
+ "type": "module",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "",
+ "license": "ISC"
+}
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/test/index.js b/staff/fabian-romero/react/ponies/api/test/index.js
new file mode 100644
index 000000000..fd1dbb539
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/test/index.js
@@ -0,0 +1,9 @@
+import express from 'express'
+
+const api = express()
+
+api.get('/hello', (req, res) => {
+ res.send('Hello, World!')
+})
+
+api.listen(8080, () => console.log('server up'))
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/api/test/validate.js b/staff/fabian-romero/react/ponies/api/test/validate.js
new file mode 100644
index 000000000..e94608ce1
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/api/test/validate.js
@@ -0,0 +1,47 @@
+const USERNAME_REGEX = /^(?!.*\s{2})[a-zA-Z0-9._-]{4,16}$/
+const NAME_REGEX = /^(?!.*\s{2})[a-zA-Z ]{3,16}$/
+const EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/
+
+function validateString(value, explain = 'value') {
+ if (typeof value !== 'string') throw new TypeError(`${explain} is not a string`)
+}
+
+function validateCallback(callback, explain = 'callback') {
+ if (typeof callback !== 'function') throw new TypeError(`${explain} is not a function`)
+}
+
+function validateObject(object, explain = 'object') {
+ if (object === null || typeof object !== 'object' || object.constructor !== Object) throw new TypeError(`${explain} is not an object`)
+}
+
+function validateUsername(username) {
+ validateString(username, 'username')
+ if (!USERNAME_REGEX.test(username)) throw new SyntaxError('invalid username')
+}
+
+function validatePassword(password) {
+ validateString(password, 'password')
+ if (password.trim().length < 8) throw new RangeError('password length is lower than 8 characters')
+ if (password.includes(' ')) throw new SyntaxError('password has empty spaces')
+}
+
+function validateName(name, explain = 'name') {
+ validateString(name, explain)
+ if (!NAME_REGEX.test(name)) throw new SyntaxError(`invalid ${explain}`)
+}
+
+function validateEmail(email) {
+ validateString(email, 'email')
+ if (!EMAIL_REGEX.test(email)) throw new SyntaxError(`invalid ${email}`)
+}
+
+const validate = {
+ callback: validateCallback,
+ object: validateObject,
+ username: validateUsername,
+ password: validatePassword,
+ name: validateName,
+ email: validateEmail
+}
+
+export default validate
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/data/deletePost.mjs b/staff/fabian-romero/react/ponies/app/data/deletePost.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/deletePost.mjs
rename to staff/fabian-romero/react/ponies/app/data/deletePost.js
diff --git a/staff/fabian-romero/react/ponies/app/data/findPost.mjs b/staff/fabian-romero/react/ponies/app/data/findPost.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/findPost.mjs
rename to staff/fabian-romero/react/ponies/app/data/findPost.js
diff --git a/staff/fabian-romero/react/ponies/app/data/findPosts.mjs b/staff/fabian-romero/react/ponies/app/data/findPosts.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/findPosts.mjs
rename to staff/fabian-romero/react/ponies/app/data/findPosts.js
diff --git a/staff/fabian-romero/react/ponies/app/data/findUser.mjs b/staff/fabian-romero/react/ponies/app/data/findUser.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/findUser.mjs
rename to staff/fabian-romero/react/ponies/app/data/findUser.js
diff --git a/staff/fabian-romero/react/ponies/app/data/index.js b/staff/fabian-romero/react/ponies/app/data/index.js
new file mode 100644
index 000000000..15136ddeb
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/app/data/index.js
@@ -0,0 +1,21 @@
+import deletePost from './deletePost.js'
+import findPost from './findPost.js'
+import findPosts from './findPosts.js'
+import findUser from './findUser.js'
+import insertPost from './insertPost.js'
+import insertUser from './insertUser.js'
+import updatePost from './updatePost.js'
+import updateUser from './updateUser.js'
+
+const data = {
+ deletePost,
+ findPost,
+ findPosts,
+ findUser,
+ insertPost,
+ insertUser,
+ updatePost,
+ updateUser
+}
+
+export default data
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/data/index.mjs b/staff/fabian-romero/react/ponies/app/data/index.mjs
deleted file mode 100644
index f3a4a2cb2..000000000
--- a/staff/fabian-romero/react/ponies/app/data/index.mjs
+++ /dev/null
@@ -1,21 +0,0 @@
-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/fabian-romero/react/ponies/app/data/insertPost.mjs b/staff/fabian-romero/react/ponies/app/data/insertPost.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/insertPost.mjs
rename to staff/fabian-romero/react/ponies/app/data/insertPost.js
diff --git a/staff/fabian-romero/react/ponies/app/data/insertUser.mjs b/staff/fabian-romero/react/ponies/app/data/insertUser.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/insertUser.mjs
rename to staff/fabian-romero/react/ponies/app/data/insertUser.js
diff --git a/staff/fabian-romero/react/ponies/app/data/updatePost.mjs b/staff/fabian-romero/react/ponies/app/data/updatePost.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/updatePost.mjs
rename to staff/fabian-romero/react/ponies/app/data/updatePost.js
diff --git a/staff/fabian-romero/react/ponies/app/data/updateUser.mjs b/staff/fabian-romero/react/ponies/app/data/updateUser.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/data/updateUser.mjs
rename to staff/fabian-romero/react/ponies/app/data/updateUser.js
diff --git a/staff/fabian-romero/react/ponies/app/index.css b/staff/fabian-romero/react/ponies/app/index.css
index 4895d276e..b996de3f6 100644
--- a/staff/fabian-romero/react/ponies/app/index.css
+++ b/staff/fabian-romero/react/ponies/app/index.css
@@ -18,8 +18,9 @@ body {
}
-
.main {
- margin-top: 2.5rem;
- margin-bottom: 2.5rem;
+ margin-top: 3.2rem;
+ margin-bottom: 2rem;
+ margin-left: 1rem;
+ margin-right: 1rem;
}
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/logic/createPost.mjs b/staff/fabian-romero/react/ponies/app/logic/createPost.js
similarity index 81%
rename from staff/fabian-romero/react/ponies/app/logic/createPost.mjs
rename to staff/fabian-romero/react/ponies/app/logic/createPost.js
index ff01cfaa4..53305cf00 100644
--- a/staff/fabian-romero/react/ponies/app/logic/createPost.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/createPost.js
@@ -1,6 +1,6 @@
-import data from '../data/index.mjs'
+import data from '../data'
-import generateId from '../util/generateId.mjs'
+import generateId from '../util/generateId'
const createPost = (image, caption) => {
if (!image.startsWith('http'))
diff --git a/staff/fabian-romero/react/ponies/app/logic/deletePost.mjs b/staff/fabian-romero/react/ponies/app/logic/deletePost.js
similarity index 88%
rename from staff/fabian-romero/react/ponies/app/logic/deletePost.mjs
rename to staff/fabian-romero/react/ponies/app/logic/deletePost.js
index 77a135435..801fb6695 100644
--- a/staff/fabian-romero/react/ponies/app/logic/deletePost.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/deletePost.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const deletePost = postId => {
if (postId.trim().length === 0) throw new Error('invalid postId')
diff --git a/staff/fabian-romero/react/ponies/app/logic/getAllFavPosts.mjs b/staff/fabian-romero/react/ponies/app/logic/getAllFavPosts.js
similarity index 95%
rename from staff/fabian-romero/react/ponies/app/logic/getAllFavPosts.mjs
rename to staff/fabian-romero/react/ponies/app/logic/getAllFavPosts.js
index ac4906b92..9f522c193 100644
--- a/staff/fabian-romero/react/ponies/app/logic/getAllFavPosts.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/getAllFavPosts.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const getAllFavPosts = () => {
const user = data.findUser(user => user.username === sessionStorage.username)
diff --git a/staff/fabian-romero/react/ponies/app/logic/getAllPoniesPosts.mjs b/staff/fabian-romero/react/ponies/app/logic/getAllPoniesPosts.js
similarity index 95%
rename from staff/fabian-romero/react/ponies/app/logic/getAllPoniesPosts.mjs
rename to staff/fabian-romero/react/ponies/app/logic/getAllPoniesPosts.js
index 0d551642d..ccb54527c 100644
--- a/staff/fabian-romero/react/ponies/app/logic/getAllPoniesPosts.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/getAllPoniesPosts.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const getAllPoniesPosts = () => {
const user = data.findUser(user => user.username === sessionStorage.username)
diff --git a/staff/fabian-romero/react/ponies/app/logic/getAllPosts.mjs b/staff/fabian-romero/react/ponies/app/logic/getAllPosts.js
similarity index 94%
rename from staff/fabian-romero/react/ponies/app/logic/getAllPosts.mjs
rename to staff/fabian-romero/react/ponies/app/logic/getAllPosts.js
index e6308a959..1b459e6d9 100644
--- a/staff/fabian-romero/react/ponies/app/logic/getAllPosts.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/getAllPosts.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const getAllPosts = () => {
const user = data.findUser(user => user.username === sessionStorage.username)
diff --git a/staff/fabian-romero/react/ponies/app/logic/getUserName.mjs b/staff/fabian-romero/react/ponies/app/logic/getUserName.js
similarity index 86%
rename from staff/fabian-romero/react/ponies/app/logic/getUserName.mjs
rename to staff/fabian-romero/react/ponies/app/logic/getUserName.js
index 11619b67e..911a09a83 100644
--- a/staff/fabian-romero/react/ponies/app/logic/getUserName.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/getUserName.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const getUserName = () => {
const user = data.findUser(user => user.username === sessionStorage.username)
diff --git a/staff/fabian-romero/react/ponies/app/logic/getUserUsername.js b/staff/fabian-romero/react/ponies/app/logic/getUserUsername.js
new file mode 100644
index 000000000..8e33b442d
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/app/logic/getUserUsername.js
@@ -0,0 +1,3 @@
+const getUserUsername = () => sessionStorage.username
+
+export default getUserUsername
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/logic/index.js b/staff/fabian-romero/react/ponies/app/logic/index.js
new file mode 100644
index 000000000..876cc7ee2
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/app/logic/index.js
@@ -0,0 +1,35 @@
+import getAllPosts from './getAllPosts.js'
+import getUserName from './getUserName.js'
+import getUserUsername from './getUserUsername.js'
+import loginUser from './loginUser.js'
+import logoutUser from './logoutUser.js'
+import registerUser from './registerUser.js'
+import toggleLikePost from './toggleLikePost.js'
+import updatePostCaption from './updatePostCaption.js'
+import createPost from './createPost.js'
+import deletePost from './deletePost.js'
+import toggleFavPost from './toggleFavPost.js'
+import getAllFavPosts from './getAllFavPosts.js'
+import toggleFollowUser from './toggleFollowUser.js'
+import getAllPoniesPosts from './getAllPoniesPosts.js'
+import isUserLoggedIn from './isUserLoggedIn.js'
+
+const logic = {
+ getAllPosts,
+ getUserName,
+ getUserUsername,
+ loginUser,
+ logoutUser,
+ registerUser,
+ toggleLikePost,
+ updatePostCaption,
+ createPost,
+ deletePost,
+ toggleFavPost,
+ getAllFavPosts,
+ toggleFollowUser,
+ getAllPoniesPosts,
+ isUserLoggedIn
+}
+
+export default logic
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/logic/index.mjs b/staff/fabian-romero/react/ponies/app/logic/index.mjs
deleted file mode 100644
index cecc540b0..000000000
--- a/staff/fabian-romero/react/ponies/app/logic/index.mjs
+++ /dev/null
@@ -1,33 +0,0 @@
-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 getAllPoniesPosts from './getAllPoniesPosts.mjs'
-
-const logic = {
- getAllPosts,
- getUserName,
- getUserUsername,
- loginUser,
- logoutUser,
- registerUser,
- toggleLikePost,
- updatePostCaption,
- createPost,
- deletePost,
- toggleFavPost,
- getAllFavPosts,
- toggleFollowUser,
- getAllPoniesPosts
-}
-
-export default logic
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/logic/isUserLoggedIn.js b/staff/fabian-romero/react/ponies/app/logic/isUserLoggedIn.js
new file mode 100644
index 000000000..f3ee76d02
--- /dev/null
+++ b/staff/fabian-romero/react/ponies/app/logic/isUserLoggedIn.js
@@ -0,0 +1,10 @@
+function isUserLoggedIn() {
+ //if (sessionStorage.username) return true
+ //return false
+
+ // return sessionStorage.username ? true : false
+
+ return !!sessionStorage.username
+}
+
+export default isUserLoggedIn
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/logic/loginUser.mjs b/staff/fabian-romero/react/ponies/app/logic/loginUser.js
similarity index 93%
rename from staff/fabian-romero/react/ponies/app/logic/loginUser.mjs
rename to staff/fabian-romero/react/ponies/app/logic/loginUser.js
index fef8bd485..7c66a018b 100644
--- a/staff/fabian-romero/react/ponies/app/logic/loginUser.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/loginUser.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const loginUser = (username, password) => {
if (username.trim().length < 4)
diff --git a/staff/fabian-romero/react/ponies/app/logic/logoutUser.mjs b/staff/fabian-romero/react/ponies/app/logic/logoutUser.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/logic/logoutUser.mjs
rename to staff/fabian-romero/react/ponies/app/logic/logoutUser.js
diff --git a/staff/fabian-romero/react/ponies/app/logic/registerUser.mjs b/staff/fabian-romero/react/ponies/app/logic/registerUser.js
similarity index 97%
rename from staff/fabian-romero/react/ponies/app/logic/registerUser.mjs
rename to staff/fabian-romero/react/ponies/app/logic/registerUser.js
index 5bd37b0c0..17c8938a6 100644
--- a/staff/fabian-romero/react/ponies/app/logic/registerUser.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/registerUser.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const EMAIL_REGEX = /^[a-z0-9._]+@[a-z0-9.-]{3,63}\.[a-z]{2,10}$/
diff --git a/staff/fabian-romero/react/ponies/app/logic/toggleFavPost.mjs b/staff/fabian-romero/react/ponies/app/logic/toggleFavPost.js
similarity index 94%
rename from staff/fabian-romero/react/ponies/app/logic/toggleFavPost.mjs
rename to staff/fabian-romero/react/ponies/app/logic/toggleFavPost.js
index e015ccc0c..80f46032d 100644
--- a/staff/fabian-romero/react/ponies/app/logic/toggleFavPost.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/toggleFavPost.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
function toggleFavPost(postId) {
if (postId.trim().length === 0) throw new Error('invalid postId')
diff --git a/staff/fabian-romero/react/ponies/app/logic/toggleFollowUser.mjs b/staff/fabian-romero/react/ponies/app/logic/toggleFollowUser.js
similarity index 94%
rename from staff/fabian-romero/react/ponies/app/logic/toggleFollowUser.mjs
rename to staff/fabian-romero/react/ponies/app/logic/toggleFollowUser.js
index 90b2c90a5..60487736e 100644
--- a/staff/fabian-romero/react/ponies/app/logic/toggleFollowUser.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/toggleFollowUser.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
function toggleFollowUser(username) {
if (!username.trim().length) throw new Error('invalid username')
diff --git a/staff/fabian-romero/react/ponies/app/logic/toggleLikePost.mjs b/staff/fabian-romero/react/ponies/app/logic/toggleLikePost.js
similarity index 93%
rename from staff/fabian-romero/react/ponies/app/logic/toggleLikePost.mjs
rename to staff/fabian-romero/react/ponies/app/logic/toggleLikePost.js
index 5d2974aa1..7b2a8a920 100644
--- a/staff/fabian-romero/react/ponies/app/logic/toggleLikePost.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/toggleLikePost.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
function toggleLikePost(postId) {
if (postId.trim().length === 0) throw new Error('invalid postId')
diff --git a/staff/fabian-romero/react/ponies/app/logic/updatePostCaption.mjs b/staff/fabian-romero/react/ponies/app/logic/updatePostCaption.js
similarity index 90%
rename from staff/fabian-romero/react/ponies/app/logic/updatePostCaption.mjs
rename to staff/fabian-romero/react/ponies/app/logic/updatePostCaption.js
index 06345e3d4..057c931b6 100644
--- a/staff/fabian-romero/react/ponies/app/logic/updatePostCaption.mjs
+++ b/staff/fabian-romero/react/ponies/app/logic/updatePostCaption.js
@@ -1,4 +1,4 @@
-import data from '../data/index.mjs'
+import data from '../data'
const updatePostCaption = (postId, newCaption) => {
if (postId.trim().length === 0) throw new Error('invalid postId')
diff --git a/staff/fabian-romero/react/ponies/app/package.json b/staff/fabian-romero/react/ponies/app/package.json
index 9739a2838..75e05be6b 100644
--- a/staff/fabian-romero/react/ponies/app/package.json
+++ b/staff/fabian-romero/react/ponies/app/package.json
@@ -4,6 +4,7 @@
"version": "0.0.0",
"type": "module",
"scripts": {
+ "start": "vite",
"dev": "vite",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
@@ -23,4 +24,4 @@
"eslint-plugin-react-refresh": "^0.4.7",
"vite": "^5.3.1"
}
-}
+}
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/util/formatTime.mjs b/staff/fabian-romero/react/ponies/app/util/formatTime.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/util/formatTime.mjs
rename to staff/fabian-romero/react/ponies/app/util/formatTime.js
diff --git a/staff/fabian-romero/react/ponies/app/util/generateId.mjs b/staff/fabian-romero/react/ponies/app/util/generateId.js
similarity index 100%
rename from staff/fabian-romero/react/ponies/app/util/generateId.mjs
rename to staff/fabian-romero/react/ponies/app/util/generateId.js
diff --git a/staff/fabian-romero/react/ponies/app/view/App.jsx b/staff/fabian-romero/react/ponies/app/view/App.jsx
index 05e9380c6..c31cdec55 100644
--- a/staff/fabian-romero/react/ponies/app/view/App.jsx
+++ b/staff/fabian-romero/react/ponies/app/view/App.jsx
@@ -4,13 +4,15 @@ import Login from './Login'
import Register from './Register'
import Home from './Home'
+import logic from '../logic'
+
class App extends Component {
constructor() {
console.debug('App -> constructor')
super()
- this.state = { view: 'login' }
+ this.state = { view: logic.isUserloggedIn ? 'home' : 'login' }
}
handleLogin() {
diff --git a/staff/fabian-romero/react/ponies/app/view/Login.jsx b/staff/fabian-romero/react/ponies/app/view/Login.jsx
index 6f5d81a8d..863e10f5c 100644
--- a/staff/fabian-romero/react/ponies/app/view/Login.jsx
+++ b/staff/fabian-romero/react/ponies/app/view/Login.jsx
@@ -1,4 +1,4 @@
-import logic from '../logic/index.mjs'
+import logic from '../logic'
import Heading from './components/Heading'
import Form from './components/Form'
@@ -56,12 +56,10 @@ function Login({ onLogin, onRegisterClick }) {
-
Register
}
-
export default Login
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/view/Register.jsx b/staff/fabian-romero/react/ponies/app/view/Register.jsx
index b445aba5e..f0246572f 100644
--- a/staff/fabian-romero/react/ponies/app/view/Register.jsx
+++ b/staff/fabian-romero/react/ponies/app/view/Register.jsx
@@ -1,4 +1,4 @@
-import logic from '../logic/index.mjs'
+import logic from '../logic'
import Heading from './components/Heading'
import Form from './components/Form'
diff --git a/staff/fabian-romero/react/ponies/app/view/components/Button.css b/staff/fabian-romero/react/ponies/app/view/components/Button.css
index ce0463c3c..8f0fb1d5c 100644
--- a/staff/fabian-romero/react/ponies/app/view/components/Button.css
+++ b/staff/fabian-romero/react/ponies/app/view/components/Button.css
@@ -9,12 +9,13 @@
}
.Button--add {
- background: linear-gradient(to right, #A02BE8, #2fd5d5);
+ background: transparent;
+ align-self: center;
color: white;
border-radius: 5px;
- width: 50px;
- height: 30px;
- border: none;
+ width: 31px;
+ height: 22px;
+ border: 1rem;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
@@ -41,4 +42,17 @@
padding: .2rem;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
margin-top: 1rem;
-}
\ No newline at end of file
+}
+
+/* .Button--Login {
+ background: transparent;
+ align-self: center;
+ color: black;
+ border-radius: 6px;
+ border: none;
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
+ padding: -0.8rem 0.5rem;
+ cursor: pointer;
+ width: 9rem;
+ margin-top: 1rem;
+} */
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/view/components/Form.css b/staff/fabian-romero/react/ponies/app/view/components/Form.css
index 9223b5d51..2ab8d9af3 100644
--- a/staff/fabian-romero/react/ponies/app/view/components/Form.css
+++ b/staff/fabian-romero/react/ponies/app/view/components/Form.css
@@ -3,7 +3,7 @@
unicode-bidi: isolate;
display: flex;
flex-direction: column;
- gap: .5rem;
+ gap: .3rem;
min-width: 80%;
}
diff --git a/staff/fabian-romero/react/ponies/app/view/components/Paragraph.css b/staff/fabian-romero/react/ponies/app/view/components/Paragraph.css
index 654639ae1..233fc0d06 100644
--- a/staff/fabian-romero/react/ponies/app/view/components/Paragraph.css
+++ b/staff/fabian-romero/react/ponies/app/view/components/Paragraph.css
@@ -1,4 +1,5 @@
.Paragraph {
margin: 0.5rem;
align-items: flex-start;
+ padding: 1rem;
}
\ No newline at end of file
diff --git a/staff/fabian-romero/react/ponies/app/view/home/CreatePost.css b/staff/fabian-romero/react/ponies/app/view/home/CreatePost.css
index 6aeef6ad6..52e790c46 100644
--- a/staff/fabian-romero/react/ponies/app/view/home/CreatePost.css
+++ b/staff/fabian-romero/react/ponies/app/view/home/CreatePost.css
@@ -5,7 +5,7 @@
gap: 1rem;
bottom: 0;
left: 0;
- width: 100%;
+ width: 80%;
background-color: white;
padding: 0.5rem;
box-sizing: border-box;
diff --git a/staff/fabian-romero/react/ponies/app/view/home/CreatePost.jsx b/staff/fabian-romero/react/ponies/app/view/home/CreatePost.jsx
index 48cbd2c8f..10b5dcc89 100644
--- a/staff/fabian-romero/react/ponies/app/view/home/CreatePost.jsx
+++ b/staff/fabian-romero/react/ponies/app/view/home/CreatePost.jsx
@@ -1,4 +1,4 @@
-import logic from '../../logic/index.mjs'
+import logic from '../../logic'
import Heading from '../components/Heading'
import Form from '../components/Form'
@@ -43,7 +43,7 @@ function CreatePost({ onPostCreated, onCancelCreatePost }) {
}
return
- Create Post
+ Create Post