Commit 1d7838bf authored by Sonia Vidal Gonzalez's avatar Sonia Vidal Gonzalez

ok

parent 111a0ef5
node_modules/
...@@ -8,10 +8,11 @@ import routes from './config/routes'; ...@@ -8,10 +8,11 @@ import routes from './config/routes';
export interface IApplicationProps { } export interface IApplicationProps { }
//Archivo para definir las rutas //Archivo para definir las rutas (Página INICIAL)
const Application: React.FunctionComponent<IApplicationProps> = props => { const Application: React.FunctionComponent<IApplicationProps> = props => {
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
//Comprobacion si el usuario pertenece a la base de datos con el auth de firebase:
useEffect(() => { useEffect(() => {
auth.onAuthStateChanged(user => { auth.onAuthStateChanged(user => {
if (user) if (user)
......
...@@ -18,6 +18,8 @@ export const Providers = { ...@@ -18,6 +18,8 @@ export const Providers = {
// en todos nuestros comandos de base de firebase. // en todos nuestros comandos de base de firebase.
export const auth = firebase.auth(); export const auth = firebase.auth();
//export const db = Firebase.firestore();
// Por ultimo exportamos el objeto: // Por ultimo exportamos el objeto:
export default Firebase; export default Firebase;
import fb from './firebase';
import 'firebase/firestore';
export const db = fb.firestore();
//Exportamos el firestore para guardar colecciones, guardar datos.. etc
export default db;
...@@ -5,6 +5,7 @@ import Application from './application'; ...@@ -5,6 +5,7 @@ import Application from './application';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
import 'bootswatch/dist/superhero/bootstrap.min.css'; import 'bootswatch/dist/superhero/bootstrap.min.css';
//import 'bootswatch/dist/cerulean/bootstrap.min.css';
ReactDOM.render( ReactDOM.render(
<React.StrictMode> <React.StrictMode>
......
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import LinksForm from "./LinkForm"; import LinksForm from "./LinkForm";
//Importacion del firestore
import Firebase from "../../config/firebase"; import db from "../../config/firestore";
//Importamos toast para mensajes dinamicos (instalamos librería => npm install --save react-toastify) //Importamos toast para mensajes dinamicos (instalamos librería => npm install --save react-toastify)
import { toast } from "react-toastify"; import { toast } from "react-toastify";
...@@ -14,7 +14,8 @@ const Links = () => { ...@@ -14,7 +14,8 @@ const Links = () => {
//Hacemos la consulta para traernos todos los links de firebase. Es de manera asincrona asi que tenemos que usar async. //Hacemos la consulta para traernos todos los links de firebase. Es de manera asincrona asi que tenemos que usar async.
//Con onSnapshot hacemos que al renderizar aparaezca al instate. //Con onSnapshot hacemos que al renderizar aparaezca al instate.
const getLinks = async () => { const getLinks = async () => {
Firebase.firestore.collection("links").onSnapshot((querySnapshot) => {
db.collection("links").onSnapshot((querySnapshot) => {
const docs = []; const docs = [];
querySnapshot.forEach((doc) => { querySnapshot.forEach((doc) => {
docs.push({ ...doc.data(), id: doc.id }); docs.push({ ...doc.data(), id: doc.id });
...@@ -27,7 +28,7 @@ const Links = () => { ...@@ -27,7 +28,7 @@ const Links = () => {
// Y creamos un toast para mandar un mensaje dimamico diciendo que lo hemos borrado // Y creamos un toast para mandar un mensaje dimamico diciendo que lo hemos borrado
const onDeleteLink = async (id) => { const onDeleteLink = async (id) => {
if (window.confirm("are you sure you want to delete this link?")) { if (window.confirm("are you sure you want to delete this link?")) {
await Firebase.firestore.collection("links").doc(id).delete(); await db.collection("links").doc(id).delete();
toast("Link Removed Successfully", { toast("Link Removed Successfully", {
type: "error", // error => color rojo type: "error", // error => color rojo
autoClose: 2000 // El mensaje se autocierra pasado 2 segundos autoClose: 2000 // El mensaje se autocierra pasado 2 segundos
...@@ -46,13 +47,13 @@ const Links = () => { ...@@ -46,13 +47,13 @@ const Links = () => {
const addOrEditLink = async (linkObject) => { const addOrEditLink = async (linkObject) => {
try { try {
if (currentId === "") { if (currentId === "") {
await Firebase.firestore.collection("links").doc().set(linkObject); await db.collection("links").doc().set(linkObject);
toast("New Link Added", { toast("New Link Added", {
type: "success", // success => color verde type: "success", // success => color verde
autoClose: 2000 // El mensaje se autocierra pasado 2 segundos autoClose: 2000 // El mensaje se autocierra pasado 2 segundos
}); });
} else { } else {
await Firebase.firestore.collection("links").doc(currentId).update(linkObject); await db.collection("links").doc(currentId).update(linkObject);
toast("Link Updated Successfully", { toast("Link Updated Successfully", {
type: "info", // info => color azul type: "info", // info => color azul
autoClose: 2000 // El mensaje se autocierra pasado 2 segundos autoClose: 2000 // El mensaje se autocierra pasado 2 segundos
......
...@@ -67,6 +67,7 @@ const LoginPage: React.FunctionComponent<IPageProps> = props => { ...@@ -67,6 +67,7 @@ const LoginPage: React.FunctionComponent<IPageProps> = props => {
<AuthContainer header="Login"> <AuthContainer header="Login">
<FormGroup> <FormGroup>
<Input <Input
style={{ color: "white" }}
type="email" type="email"
name="email" name="email"
id="email" id="email"
...@@ -77,6 +78,7 @@ const LoginPage: React.FunctionComponent<IPageProps> = props => { ...@@ -77,6 +78,7 @@ const LoginPage: React.FunctionComponent<IPageProps> = props => {
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<Input <Input
style={{ color: "white" }}
autoComplete="new-password" autoComplete="new-password"
type="password" type="password"
name="password" name="password"
......
...@@ -79,6 +79,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => { ...@@ -79,6 +79,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => {
<AuthContainer header="Register"> <AuthContainer header="Register">
<FormGroup> <FormGroup>
<Input <Input
style={{ color: "white" }}
type="email" type="email"
name="email" name="email"
id="email" id="email"
...@@ -90,7 +91,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => { ...@@ -90,7 +91,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => {
<FormGroup> <FormGroup>
{/** El autocompletado es para que coincidan contrseñas*/} {/** El autocompletado es para que coincidan contrseñas*/}
<Input <Input
style={{ color: "white" }}
autoComplete="new-password" autoComplete="new-password"
type="password" type="password"
name="password" name="password"
...@@ -102,6 +103,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => { ...@@ -102,6 +103,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => {
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<Input <Input
style={{ color: "white" }}
autoComplete="new-password" autoComplete="new-password"
type="password" type="password"
name="confirm" name="confirm"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment