From ab4934bd8393764ab25166caecbbf24d203959a0 Mon Sep 17 00:00:00 2001 From: Jose Quero Date: Wed, 13 Nov 2024 18:57:19 +0100 Subject: [PATCH] create new app using js6 #40 --- staff/jose-quero/app 1/App.js | 37 ++++++++++++++++ .../jose-quero/app 1/data/logic/createPost.js | 24 +++++++++++ staff/jose-quero/app 1/data/post.js | 19 ++++++++ staff/jose-quero/app 1/data/users.js | 22 ++++++++++ staff/jose-quero/app 1/data/uuid.js | 3 ++ staff/jose-quero/app 1/index.html | 43 +++++++++++++++++++ staff/jose-quero/app 1/main.js | 5 +++ staff/jose-quero/app 1/styles.css | 0 8 files changed, 153 insertions(+) create mode 100644 staff/jose-quero/app 1/App.js create mode 100644 staff/jose-quero/app 1/data/logic/createPost.js create mode 100644 staff/jose-quero/app 1/data/post.js create mode 100644 staff/jose-quero/app 1/data/users.js create mode 100644 staff/jose-quero/app 1/data/uuid.js create mode 100644 staff/jose-quero/app 1/index.html create mode 100644 staff/jose-quero/app 1/main.js create mode 100644 staff/jose-quero/app 1/styles.css diff --git a/staff/jose-quero/app 1/App.js b/staff/jose-quero/app 1/App.js new file mode 100644 index 00000000..eaaad113 --- /dev/null +++ b/staff/jose-quero/app 1/App.js @@ -0,0 +1,37 @@ +class App extends Component { + constructor() { + super(document.body) + + const title = new Heading(1) + tittle.setText("Hola, App!") + this.add(title) + + const landing = new landing + this.add(title) + + landing.onRegisterClick(() => { + this.remove(landing) + this.add(register) + }) + + landing.onLoginClick(() => { + this.remove(landing) + this.add(login) + }) + + const login = new login + login.onRegisterClick(() => { + this.remove(login) + this.add(register) + }) + + const register = new register + register.onLoginClick(() => { + this.remove(register) + this.add(login) + }) + + // const home = new Home + // this.add(home) + } +} \ No newline at end of file diff --git a/staff/jose-quero/app 1/data/logic/createPost.js b/staff/jose-quero/app 1/data/logic/createPost.js new file mode 100644 index 00000000..d4f375dc --- /dev/null +++ b/staff/jose-quero/app 1/data/logic/createPost.js @@ -0,0 +1,24 @@ +(function () { + function createPost(image, text) { + if (typeof image !== "string") throw new Error("invalid image type") + if (typeof text !== "string") throw new Error("invalid text type") + + var posts = JSON.parse(localStorage.posts) + + // Crea un nuevo objeto 'post' con las siguientes propiedades: + + var post = { + id: uuid(), + author: sessionStorage.userId, // el ID del usuario logueado, almacenado en 'sessionStorage'?? + image: image, + text: text, + date: new Date().toISOString() // la fecha y hora actuales en formato ISO. + } + + posts.push(post) // Añade el nuevo 'post' al array de 'posts' + + localStorage.posts = JSON.stringify(posts) // Convierte el array 'posts' nuevamente a una cadena JSON y lo guarda en 'localStorage' + } + + logic.createPost = createPost // Asigna la función 'createPost' al objeto 'logic', de modo que esté disponible globalmente en 'logic'. +})() \ No newline at end of file diff --git a/staff/jose-quero/app 1/data/post.js b/staff/jose-quero/app 1/data/post.js new file mode 100644 index 00000000..3d755778 --- /dev/null +++ b/staff/jose-quero/app 1/data/post.js @@ -0,0 +1,19 @@ +var posts = [] + +posts.push({ + id: 'uuid()', // Genera un ID único para el usuario usando la función uuid() + author: 'uuid()', // Poner el username; + image: 'https://spirit.scene7.com/is/image/Spirit/01642859-a?wid=400&qlt=85,1&resMode=bicub&fmt=jpeg&op_sharpen=1&hei=400', + text: 'here me', + date: new Date().toISOString() +}) + +posts.push({ + id: 'm2w92r8h44', + author: 'm2w92r8h10', + image: 'https://i.ytimg.com/vi/9oWEZSL_53U/maxresdefault.jpg', + text: 'dream team', + date: new Date().toISOString() +}) + +localStorage.posts = JSON.stringify(posts) diff --git a/staff/jose-quero/app 1/data/users.js b/staff/jose-quero/app 1/data/users.js new file mode 100644 index 00000000..a38f8895 --- /dev/null +++ b/staff/jose-quero/app 1/data/users.js @@ -0,0 +1,22 @@ +//users + +var users = [] + +users.push({ + id: uuid(), //Genera un ID único para el usuario usando la función uuid() + name: 'quero', + email: 'jose@quero.com', + username: 'querito', + password: '123123' +}) + +users.push({ + id: uuid(), + name: 'sora', + email: 'keyblade@light.com', + username: 'Chosen One', + password: 713 +}) + + +localStorage.users = JSON.stringify(users) // Almacena el array de usuarios en localStorage como una cadena de texto de JSON \ No newline at end of file diff --git a/staff/jose-quero/app 1/data/uuid.js b/staff/jose-quero/app 1/data/uuid.js new file mode 100644 index 00000000..9c7d7340 --- /dev/null +++ b/staff/jose-quero/app 1/data/uuid.js @@ -0,0 +1,3 @@ +function uuid() { + return (Date.now() + Math.random()).toString(36).replace('.', '') +} \ No newline at end of file diff --git a/staff/jose-quero/app 1/index.html b/staff/jose-quero/app 1/index.html new file mode 100644 index 00000000..17b8e59a --- /dev/null +++ b/staff/jose-quero/app 1/index.html @@ -0,0 +1,43 @@ + + + + + + + App + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/staff/jose-quero/app 1/main.js b/staff/jose-quero/app 1/main.js new file mode 100644 index 00000000..199d3cf4 --- /dev/null +++ b/staff/jose-quero/app 1/main.js @@ -0,0 +1,5 @@ +var body = document.body + +var title = document.createElement('h1') +title.innerText = 'Hola, App!' +body.appendChild(title) \ No newline at end of file diff --git a/staff/jose-quero/app 1/styles.css b/staff/jose-quero/app 1/styles.css new file mode 100644 index 00000000..e69de29b