Skip to content

Commit 20ff473

Browse files
authored
Merge pull request #12 from 4GeeksAcademy/notes
correccion de develop se elimina parte del merge de AA, se corrige home Todo queda funcionando con normalidad
2 parents ed657fc + 4c19e39 commit 20ff473

File tree

9 files changed

+139
-132
lines changed

9 files changed

+139
-132
lines changed

src/api/routes.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This module takes care of starting the API Server, Loading the DB and Adding the endpoints
33
"""
44
from flask import Flask, request, jsonify, url_for, Blueprint
5-
from api.models import db, User
5+
from api.models import db, User, Notes
66
from api.utils import generate_sitemap, APIException
77
from flask_cors import CORS
88
from sqlalchemy.exc import NoResultFound
@@ -76,6 +76,7 @@ def login():
7676
# establecer condiciones si el email que me envian desde el front es distinto envia error si no envia el token
7777
if email != user.email or password != user.password:
7878
return jsonify({"msg": "Bad password or email"}), 401
79+
7980

8081
access_token = create_access_token(identity=email)
8182
return jsonify({"access_token":access_token, "user": user.serialize()})
@@ -104,4 +105,30 @@ def protected():
104105
#con la busqueda del señor anterior en la tabla favoritos fijate cuantos tiene y traemelos
105106
# user = db.session.execute(db.select(User).filter_by(email=email)).scalar_one()
106107
# la entidad verificada se guarda en el espacio de memoria
107-
return jsonify(logged_in_as=current_user), 200
108+
return jsonify(logged_in_as=current_user), 200
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
@api.route("/notes", methods=["GET"])
123+
@jwt_required()
124+
def call_notes():
125+
# Access the identity of the current user with get_jwt_identity
126+
current_user = get_jwt_identity()
127+
user = db.session.execute(db.select(User).filter_by(email=current_user)).scalar_one()
128+
#aplicar logica para mostar profile
129+
notes = db.session.execute(db.select(Notes).filter_by(user_id=user.id)).scalars()
130+
print(list(notes))
131+
132+
133+
#cambiar el mensaje de return que no muestre datos personales
134+
return jsonify(result = "your notes"), 200

src/front/js/component/footer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from "react";
1+
import React from "react";
22

33
export const Footer = () => {
44
return (
@@ -7,12 +7,12 @@ export const Footer = () => {
77
{/* Social Icons */}
88
<div className="flex items-center space-x-3">
99
<a href="#" className="opacity-75 hover:opacity-100">
10-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-instagram" viewBox="0 0 16 16">
10+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-instagram" viewBox="0 0 16 16">
1111
<path d="M8 0C5.829 0 5.556.01 4.703.048 3.85.088 3.269.222 2.76.42a3.9 3.9 0 0 0-1.417.923A3.9 3.9 0 0 0 .42 2.76C.222 3.268.087 3.85.048 4.7.01 5.555 0 5.827 0 8.001c0 2.172.01 2.444.048 3.297.04.852.174 1.433.372 1.942.205.526.478.972.923 1.417.444.445.89.719 1.416.923.51.198 1.09.333 1.942.372C5.555 15.99 5.827 16 8 16s2.444-.01 3.298-.048c.851-.04 1.434-.174 1.943-.372a3.9 3.9 0 0 0 1.416-.923c.445-.445.718-.891.923-1.417.197-.509.332-1.09.372-1.942C15.99 10.445 16 10.173 16 8s-.01-2.445-.048-3.299c-.04-.851-.175-1.433-.372-1.941a3.9 3.9 0 0 0-.923-1.417A3.9 3.9 0 0 0 13.24.42c-.51-.198-1.092-.333-1.943-.372C10.443.01 10.172 0 7.998 0zm-.717 1.442h.718c2.136 0 2.389.007 3.232.046.78.035 1.204.166 1.486.275.373.145.64.319.92.599s.453.546.598.92c.11.281.24.705.275 1.485.039.843.047 1.096.047 3.231s-.008 2.389-.047 3.232c-.035.78-.166 1.203-.275 1.485a2.5 2.5 0 0 1-.599.919c-.28.28-.546.453-.92.598-.28.11-.704.24-1.485.276-.843.038-1.096.047-3.232.047s-2.39-.009-3.233-.047c-.78-.036-1.203-.166-1.485-.276a2.5 2.5 0 0 1-.92-.598 2.5 2.5 0 0 1-.6-.92c-.109-.281-.24-.705-.275-1.485-.038-.843-.046-1.096-.046-3.233s.008-2.388.046-3.231c.036-.78.166-1.204.276-1.486.145-.373.319-.64.599-.92s.546-.453.92-.598c.282-.11.705-.24 1.485-.276.738-.034 1.024-.044 2.515-.045zm4.988 1.328a.96.96 0 1 0 0 1.92.96.96 0 0 0 0-1.92m-4.27 1.122a4.109 4.109 0 1 0 0 8.217 4.109 4.109 0 0 0 0-8.217m0 1.441a2.667 2.667 0 1 1 0 5.334 2.667 2.667 0 0 1 0-5.334"/>
1212
</svg>
1313
</a>
1414
<a href="#" className="opacity-75 hover:opacity-100">
15-
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-facebook" viewBox="0 0 16 16">
15+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" className="bi bi-facebook" viewBox="0 0 16 16">
1616
<path d="M16 8.049c0-4.446-3.582-8.05-8-8.05C3.58 0-.002 3.603-.002 8.05c0 4.017 2.926 7.347 6.75 7.951v-5.625h-2.03V8.05H6.75V6.275c0-2.017 1.195-3.131 3.022-3.131.876 0 1.791.157 1.791.157v1.98h-1.009c-.993 0-1.303.621-1.303 1.258v1.51h2.218l-.354 2.326H9.25V16c3.824-.604 6.75-3.934 6.75-7.951"/>
1717
</svg>
1818
</a>

src/front/js/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ import "../styles/index.css";
99
import Layout from "./layout";
1010

1111
//render your react application
12-
ReactDOM.render(<Layout />, document.querySelector("#app"));
12+
ReactDOM.render(<Layout />, document.querySelector("#app"));

src/front/js/layout.js

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Demo } from "./pages/demo";
1010
import { Single } from "./pages/single";
1111
import injectContext from "./store/appContext";
1212
import { Profile } from "./pages/profile"
13+
import { Notes } from "./pages/notes"
1314

1415
import { Navbar } from "./component/navbar";
1516
import { Footer } from "./component/footer";
@@ -31,6 +32,7 @@ const Layout = () => {
3132
<Route element={<Home />} path="/" />
3233
<Route element={<Loginview />} path="/login" />
3334
<Route element={<ForgoPassword />} path="/resetpassword" />
35+
<Route element={<Notes />} path="/notes" />
3436
<Route element={<Demo />} path="/demo" />
3537
<Route element={<Single />} path="/single/:theid" />
3638
<Route element={<h1>Not found!</h1>} />

src/front/js/pages/home.js

+18-96
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,26 @@
1-
import React, { useContext, useState } from 'react';
1+
import React, { useContext } from "react";
22
import { Context } from "../store/appContext";
3-
import { Link } from "react-router-dom";
4-
import { Eye, EyeOff } from 'lucide-react';
5-
3+
import rigoImageUrl from "../../img/rigo-baby.jpg";
4+
import "../../styles/home.css";
65

76
export const Home = () => {
87
const { store, actions } = useContext(Context);
9-
const [showPassword, setShowPassword] = useState(false);
10-
const [formData, setFormData] = useState({
11-
name: '',
12-
email: '',
13-
password: '',
14-
confirmPassword: ''
15-
});
16-
const handleInputChange = (e) => {
17-
const { name, value } = e.target;
18-
setFormData(prevState => ({
19-
...prevState,
20-
[name]: value
21-
}));
22-
};
23-
const handleSubmit = (e) => {
24-
e.preventDefault();
25-
// Add signup logic here
26-
console.log('Signup data:', formData);
27-
};
8+
289
return (
29-
<div className="min-h-screen flex items-center justify-center bg-white p-4">
30-
<div className="w-full max-w-4xl bg-white shadow-md rounded-lg overflow-hidden flex">
31-
{/* Left Side - Description */}
32-
<div className="w-1/2 bg-[#E6EDF3] p-8 flex flex-col justify-center">
33-
<h2 className="text-2xl font-bold text-[#24292F] mb-4">Become a member</h2>
34-
<p className="text-[#57606A]">
35-
Onmino helps you organize your ideas, tasks, and projects simply and efficiently. Start today!
10+
<div className="text-center mt-5">
11+
<h1>Hello Rigo!!</h1>
12+
<p>
13+
<img src={rigoImageUrl} />
14+
</p>
15+
<div className="alert alert-info">
16+
{store.message || "Loading message from the backend (make sure your python backend is running)..."}
17+
</div>
18+
<p>
19+
This boilerplate comes with lots of documentation:{" "}
20+
<a href="https://start.4geeksacademy.com/starters/react-flask">
21+
Read documentation
22+
</a>
3623
</p>
37-
</div>
38-
39-
{/* Right Side - Signup Form */}
40-
<div className="w-1/2 p-8 bg-white">
41-
<form onSubmit={handleSubmit}>
42-
<div className="mb-4">
43-
<input
44-
type="text"
45-
name="name"
46-
placeholder="Name"
47-
value={formData.name}
48-
onChange={handleInputChange}
49-
className="w-full px-3 py-2 border border-[#D0D7DE] rounded-md focus:outline-none focus:ring-2 focus:ring-[#1F6FEB]"
50-
required
51-
/>
52-
</div>
53-
<div className="mb-4">
54-
<input
55-
type="email"
56-
name="email"
57-
placeholder="Email"
58-
value={formData.email}
59-
onChange={handleInputChange}
60-
className="w-full px-3 py-2 border border-[#D0D7DE] rounded-md focus:outline-none focus:ring-2 focus:ring-[#1F6FEB]"
61-
required
62-
/>
63-
</div>
64-
<div className="mb-4 relative">
65-
<input
66-
type={showPassword ? "text" : "password"}
67-
name="password"
68-
placeholder="Password"
69-
value={formData.password}
70-
onChange={handleInputChange}
71-
className="w-full px-3 py-2 border border-[#D0D7DE] rounded-md focus:outline-none focus:ring-2 focus:ring-[#1F6FEB]"
72-
required
73-
/>
74-
<button
75-
type="button"
76-
onClick={() => setShowPassword(!showPassword)}
77-
className="absolute right-3 top-1/2 transform -translate-y-1/2 text-[#57606A]"
78-
>
79-
{showPassword ? <EyeOff size={20} /> : <Eye size={20} />}
80-
</button>
81-
</div>
82-
<div className="mb-4 relative">
83-
<input
84-
type={showPassword ? "text" : "password"}
85-
name="confirmPassword"
86-
placeholder="Confirm Password"
87-
value={formData.confirmPassword}
88-
onChange={handleInputChange}
89-
className="w-full px-3 py-2 border border-[#D0D7DE] rounded-md focus:outline-none focus:ring-2 focus:ring-[#1F6FEB]"
90-
required
91-
/>
92-
</div>
93-
<button
94-
type="submit"
95-
className="w-full bg-[#1F6FEB] text-white py-2 rounded-md hover:bg-[#1160D3] transition duration-300"
96-
>
97-
Register
98-
</button>
99-
</form>
100-
</div>
10124
</div>
102-
</div>
10325
);
104-
};
26+
};

src/front/js/pages/loginview.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import React, { useContext, useState } from "react";
22
import { Context } from "../store/appContext";
33
import "../../styles/home.css";
44
import { Link, useNavigate } from "react-router-dom";
5-
// import logo from "../store/logo-sin-fondo.jpg"
5+
import logo from "../store/logo-sin-fondo.jpg"
66

77
export const Loginview = () => {
88
const [email, setEmail] = useState("")
99
const [password, setPassword] = useState("")
1010
const { store, actions } = useContext(Context);
1111
let navigate = useNavigate();
12+
1213
async function handleSubmit(e) {
1314
e.preventDefault()
1415
//console.log(email, password);

src/front/js/pages/notes.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, { useContext } from "react";
2+
import { Context } from "../store/appContext";
3+
import rigoImageUrl from "../../img/rigo-baby.jpg";
4+
import "../../styles/home.css";
5+
import { Link } from "react-router-dom";
6+
7+
8+
9+
export const Notes = () => {
10+
const { store, actions } = useContext(Context);
11+
12+
return (
13+
<div className="text-center mt-5">
14+
<h1>Notes</h1>
15+
16+
17+
18+
19+
20+
21+
22+
</div>
23+
);
24+
};
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
// return (
36+
// <div className="container mt-5 w-50">
37+
// <div className="d-flex justify-content-center fs-2 mb-2"><input className="w-75 border-2 rounded-pill text-center" type="text" placeholder="What do you need to do?" onKeyDown={agregarLista} value={tarea} onChange={agregarTarea} /></div>
38+
// <ul className="my-2 p-0 d-flex justify-content-between">
39+
// {/* Crear con map lista */}
40+
// <div className="list-group">
41+
// {listaTareas.length > 0 ? listaTareas.map((item) => <li className="list-group-item list-group-item-dark" key={item.id}>{item.label}<button type="button" className="btn btn-light position end-0" onClick={() => eliminarTarea(item.id)}>x</button></li>) : null}
42+
// </div>
43+
// </ul>
44+
// {listaTareas.length + ` Task left`}
45+
// </div>
46+
// );

src/front/js/pages/profile.js

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Context } from "../store/appContext";
33
import "../../styles/home.css";
44
import { Link } from "react-router-dom";
55
import logo from "../store/logo-sin-fondo.jpg"
6+
67
export const Profile = () => {
78

89
return(

src/front/js/store/flux.js

+37-29
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,52 @@ const getState = ({ getStore, getActions, setStore }) => {
2424
},
2525

2626

27-
login: async (email, password) => {
28-
//console.log(email, password);
29-
const myHeaders = new Headers();
30-
myHeaders.append("Content-Type", "application/json");
31-
const raw = JSON.stringify({
32-
"email": email,
33-
"password": password
34-
});
35-
const requestOptions = {
36-
method: "POST",
37-
headers: myHeaders,
38-
body: raw
39-
};
40-
try {
41-
const response = await fetch("https://glorious-garbanzo-x5vw5j6w55gxhpvqr-3001.app.github.dev/api/login", requestOptions);
42-
const result = await response.json();
43-
console.log(response);
44-
console.log(result)
45-
if (response.status !== 200){
46-
return false
47-
}
48-
localStorage.setItem("token", result.access_token)
49-
return true
50-
} catch (error) {
51-
console.error(error);
52-
};
53-
27+
login: async (email, password) => {
28+
29+
//console.log(email, password);
30+
const myHeaders = new Headers();
31+
myHeaders.append("Content-Type", "application/json");
32+
33+
const raw = JSON.stringify({
34+
"email": email,
35+
"password": password
36+
});
37+
38+
const requestOptions = {
39+
method: "POST",
40+
headers: myHeaders,
41+
body: raw
42+
};
43+
44+
try {
45+
const response = await fetch("https://symmetrical-journey-69r6wvr76v5x25g4-3001.app.github.dev/api/login", requestOptions);
46+
const result = await response.json();
47+
console.log(response);
48+
49+
console.log(result)
50+
51+
if (response.status !== 200){
52+
return false
53+
}
54+
localStorage.setItem("token", result.access_token)
55+
return true
56+
} catch (error) {
57+
console.error(error);
58+
};
59+
60+
61+
5462
},
5563

5664
getMessage: async () => {
57-
try{
65+
try {
5866
// fetching data from the backend
5967
const resp = await fetch(process.env.BACKEND_URL + "/api/hello")
6068
const data = await resp.json()
6169
setStore({ message: data.message })
6270
// don't forget to return something, that is how the async resolves
6371
return data;
64-
}catch(error){
72+
} catch (error) {
6573
console.log("Error loading message from backend", error)
6674
}
6775
},

0 commit comments

Comments
 (0)