Skip to content

Commit

Permalink
add new pages: Profile (Email & Password), Upload and Download | Crea…
Browse files Browse the repository at this point in the history
…te routes to API from diferents pages b00tc4mp#382
  • Loading branch information
Abel Prieto authored and Abel Prieto committed Mar 7, 2024
1 parent 903e7b0 commit 09b3b58
Show file tree
Hide file tree
Showing 27 changed files with 477 additions and 189 deletions.
28 changes: 27 additions & 1 deletion staff/abel-prieto/PROYECT/HiInit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion staff/abel-prieto/PROYECT/HiInit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"dependencies": {
"com": "file:../com",
"dotenv": "^16.4.4",
"pnpm": "^8.15.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.0",
"sass": "^1.69.5"
"sass": "^1.69.5",
"sweetalert2": "^11.10.5"
},
"devDependencies": {
"@types/react": "^18.2.43",
Expand Down
5 changes: 5 additions & 0 deletions staff/abel-prieto/PROYECT/HiInit/src/Context.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from 'react'

const Context = createContext()

export default Context
75 changes: 75 additions & 0 deletions staff/abel-prieto/PROYECT/HiInit/src/components/Download.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { useState, useEffect, useContext } from "react"
import { useNavigate } from "react-router-dom"
import Context from "../Context"
import { CommandBar, Pointer } from "../utils"

function Download() {

// POINTER, UKNOWN COMMAND & POINTER STATE
const [commandText, setCommandText] = useState('')
const [uknownCommand, setUknownCommand] = useState(false)
const { pointer } = Pointer()

// VIEWS
const navigate = useNavigate()
const { handleError } = useContext(Context)

// ESCUCHA TECLADO, ERROR Y ESCRITURA
useEffect(() => {
const handleKeyPress = (event) => {
let commandText = document.getElementById('command').value

if ((commandText === 'desktop' || commandText === 'DESKTOP') && event.key === 'Enter') {
setUknownCommand(false)
navigate('/desktop')
} else if ((commandText === 'EXIT' || commandText === 'exit') && event.key === 'Enter') {
handleLogout()
} else if (event.key === 'Enter') {
setUknownCommand(!uknownCommand)
}
}

const handleKeyDown = () => {
setUknownCommand(false)
}

document.addEventListener('keypress', handleKeyPress)
document.addEventListener('keydown', handleKeyDown)

return () => {
document.removeEventListener('keypress', handleKeyPress)
document.removeEventListener('keydown', handleKeyDown)
}
}, [navigate, uknownCommand])

return <>
<div className="container">

<p>~$</p>
<p id="client-error-upload">Entry 'ls' command to list all your save files: </p>

<br />

<div className="command-bar">
<CommandBar />
<div id="command-form">
<input id="command" type="text" contentEditable="true" autoFocus autoComplete="off" value={commandText} onChange={(event) => setCommandText(event.target.value)}
style={{ width: `${Math.max(10, commandText.length * 8)}px` }} />
</div>
<p>{pointer}</p>
</div>

<br />

{uknownCommand && (
<>
<span>
<p>shell: command not found: '{commandText}'. Entry desktop, ls or exit</p>
</span>
</>
)}
</div>
</>
}

export default Download
18 changes: 15 additions & 3 deletions staff/abel-prieto/PROYECT/HiInit/src/components/Email.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { useState } from 'react'
import { useState, useContext } from 'react'
import { useNavigate } from 'react-router-dom'
import logic from '../logic'
import Context from '../Context'

function Email() {
// FIELDS STATE
const [showNewEmail, setShowNewEmail] = useState(true)
const [showPassword, setShowPassword] = useState(false)
const [showRepeatPass, setShowRepeatPass] = useState(false)

const { handleError } = useContext(Context)
const navigate = useNavigate()

function showInputPassword() {
setShowPassword(true)
}
Expand Down Expand Up @@ -34,12 +39,19 @@ function Email() {
const clientError = document.querySelector('#client-error-email')

clientError.innerText = error.message
clientError.style.color = 'red'
clientError.style.color = 'tomato'

handleError(error, navigate)

return
})
} catch (error) {
alert(error.message)
const clientError = document.querySelector('#client-error-email')

clientError.innerText = error.message
clientError.style.color = 'tomato'

handleError(error, navigate)
}

document.body.addEventListener('keydown', function () {
Expand Down
27 changes: 19 additions & 8 deletions staff/abel-prieto/PROYECT/HiInit/src/components/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useState, useContext } from 'react'
import logic from '../logic'
import Context from '../Context'

function Login({ onSuccess }) {

// FIELDS STATE
const [showEmail, setShowEmail] = useState(true)
const [showPassword, setShowPassword] = useState(false)

const navigate = useNavigate()
const { handleError } = useContext(Context)

function showInputPassword() {
setShowPassword(true)
}
Expand All @@ -21,32 +26,38 @@ function Login({ onSuccess }) {
logic.loginUser(email, password)
.then(() => onSuccess())
.catch(error => {
const clientError = document.querySelector('#client-error')
const clientError = document.querySelector('#client-error-login')

clientError.innerText = error.message
clientError.style.color = 'red'
clientError.style.color = 'tomato'

handleError(error, navigate)

return
})
} catch (error) {
alert(error.message)
const clientError = document.querySelector('#client-error-login')

clientError.innerText = error.message
clientError.style.color = 'tomato'

handleError(error, navigate)
}

document.body.addEventListener('keydown', function () {
const clientError = document.querySelector('#client-error')
const clientError = document.querySelector('#client-error-login')

clientError.innerText = 'Entry your credentials: '
clientError.innerText = 'Login - Entry your credentials: '
clientError.style.color = '#EBDBB2'
})
}

return <>
<div>
<p>~$</p>

<span>
<form className="login-form" onSubmit={handleSubmit}>
<p id="client-error">Entry your credentials: </p>
<p id="client-error-login">Login - Entry your credentials: </p>

{showEmail && (
<div className="fields">
Expand Down
18 changes: 15 additions & 3 deletions staff/abel-prieto/PROYECT/HiInit/src/components/Password.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { useState } from 'react'
import { useContext, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import logic from '../logic'
import Context from '../Context'

function Password() {
// FIELDS STATE
const [showPassword, setShowPassword] = useState(true)
const [showNewPassword, setShowNewPassword] = useState(false)
const [showRepeatNewPass, setShowRepeatNewPass] = useState(false)

const navigate = useNavigate()
const { handleError } = useContext(Context)

function showInputNewPassword() {
setShowNewPassword(true)
}
Expand Down Expand Up @@ -34,12 +39,19 @@ function Password() {
const clientError = document.querySelector('#client-error-password')

clientError.innerText = error.message
clientError.style.color = 'red'
clientError.style.color = 'tomato'

handleError(error, navigate)

return
})
} catch (error) {
alert(error.message)
const clientError = document.querySelector('#client-error-password')

clientError.innerText = error.message
clientError.style.color = 'tomato'

handleError(error, navigate)
}

document.body.addEventListener('keydown', function () {
Expand Down
27 changes: 20 additions & 7 deletions staff/abel-prieto/PROYECT/HiInit/src/components/Register.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useState } from 'react'
import { useState, useContext } from 'react'
import { useNavigate } from 'react-router-dom'
import logic from '../logic'
import Context from '../Context'

function Register({ onSuccess }) {

Expand All @@ -8,6 +10,9 @@ function Register({ onSuccess }) {
const [showEmail, setShowEmail] = useState(false)
const [showPassword, setShowPassword] = useState(false)

const navigate = useNavigate()
const { handleError } = useContext(Context)

// SHOW EMAIL INPUT
function showInputEmail() {
setShowEmail(true)
Expand All @@ -30,31 +35,39 @@ function Register({ onSuccess }) {
return logic.registerUser(username, email, password)
.then(() => onSuccess())
.catch(error => {
const clientError = document.querySelector('#client-error')
const clientError = document.querySelector('#client-error-register')

clientError.innerText = error.message
clientError.style.color = 'red'
clientError.style.color = 'tomato'

handleError(error, navigate)

return
})
} catch (error) {
alert(error.message)
const clientError = document.querySelector('#client-error-register')

clientError.innerText = error.message
clientError.style.color = 'tomato'

handleError(error, navigate)
}

document.body.addEventListener('keydown', function () {
const clientError = document.querySelector('#client-error')
const clientError = document.querySelector('#client-error-register')

clientError.innerText = 'Create your account data: '
clientError.innerText = 'Register - Create your account data: '
clientError.style.color = '#EBDBB2'
})
}


return <>
<div>
<p>~$</p>
<span>
<form className="register-form" onSubmit={handleSubmit}>
<p id="client-error">Create your account data: </p>
<p id="client-error-register">Register - Create your account data: </p>

<div className="space-between">
{showUsername && (
Expand Down
Loading

0 comments on commit 09b3b58

Please sign in to comment.