Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Proyecto-Firebase-baseDatos-Links.
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sonia Vidal Gonzalez
Proyecto-Firebase-baseDatos-Links.
Commits
1d7838bf
Commit
1d7838bf
authored
Sep 06, 2021
by
Sonia Vidal Gonzalez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok
parent
111a0ef5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
8 deletions
+25
-8
.gitignore
.gitignore
+1
-0
application.tsx
src/application.tsx
+2
-1
firebase.ts
src/config/firebase.ts
+2
-0
firestore.ts
src/config/firestore.ts
+7
-0
index.tsx
src/index.tsx
+1
-0
Links.js
src/pages/auth/Links.js
+7
-6
login.tsx
src/pages/auth/login.tsx
+2
-0
register.tsx
src/pages/auth/register.tsx
+3
-1
No files found.
.gitignore
0 → 100644
View file @
1d7838bf
node_modules/
src/application.tsx
View file @
1d7838bf
...
...
@@ -8,10 +8,11 @@ import routes from './config/routes';
export
interface
IApplicationProps
{
}
//Archivo para definir las rutas
//Archivo para definir las rutas
(Página INICIAL)
const
Application
:
React
.
FunctionComponent
<
IApplicationProps
>
=
props
=>
{
const
[
loading
,
setLoading
]
=
useState
<
boolean
>
(
true
);
//Comprobacion si el usuario pertenece a la base de datos con el auth de firebase:
useEffect
(()
=>
{
auth
.
onAuthStateChanged
(
user
=>
{
if
(
user
)
...
...
src/config/firebase.ts
View file @
1d7838bf
...
...
@@ -18,6 +18,8 @@ export const Providers = {
// en todos nuestros comandos de base de firebase.
export
const
auth
=
firebase
.
auth
();
//export const db = Firebase.firestore();
// Por ultimo exportamos el objeto:
export
default
Firebase
;
src/config/firestore.ts
0 → 100644
View file @
1d7838bf
import
fb
from
'./firebase'
;
import
'firebase/firestore'
;
export
const
db
=
fb
.
firestore
();
//Exportamos el firestore para guardar colecciones, guardar datos.. etc
export
default
db
;
src/index.tsx
View file @
1d7838bf
...
...
@@ -5,6 +5,7 @@ import Application from './application';
import
reportWebVitals
from
'./reportWebVitals'
;
import
'bootswatch/dist/superhero/bootstrap.min.css'
;
//import 'bootswatch/dist/cerulean/bootstrap.min.css';
ReactDOM
.
render
(
<
React
.
StrictMode
>
...
...
src/pages/auth/Links.js
View file @
1d7838bf
import
React
,
{
useEffect
,
useState
}
from
"react"
;
import
LinksForm
from
"./LinkForm"
;
import
Firebase
from
"../../config/firebas
e"
;
//Importacion del firestore
import
db
from
"../../config/firestor
e"
;
//Importamos toast para mensajes dinamicos (instalamos librería => npm install --save react-toastify)
import
{
toast
}
from
"react-toastify"
;
...
...
@@ -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.
//Con onSnapshot hacemos que al renderizar aparaezca al instate.
const
getLinks
=
async
()
=>
{
Firebase
.
firestore
.
collection
(
"links"
).
onSnapshot
((
querySnapshot
)
=>
{
db
.
collection
(
"links"
).
onSnapshot
((
querySnapshot
)
=>
{
const
docs
=
[];
querySnapshot
.
forEach
((
doc
)
=>
{
docs
.
push
({
...
doc
.
data
(),
id
:
doc
.
id
});
...
...
@@ -27,7 +28,7 @@ const Links = () => {
// Y creamos un toast para mandar un mensaje dimamico diciendo que lo hemos borrado
const
onDeleteLink
=
async
(
id
)
=>
{
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"
,
{
type
:
"error"
,
// error => color rojo
autoClose
:
2000
// El mensaje se autocierra pasado 2 segundos
...
...
@@ -46,13 +47,13 @@ const Links = () => {
const
addOrEditLink
=
async
(
linkObject
)
=>
{
try
{
if
(
currentId
===
""
)
{
await
Firebase
.
firestore
.
collection
(
"links"
).
doc
().
set
(
linkObject
);
await
db
.
collection
(
"links"
).
doc
().
set
(
linkObject
);
toast
(
"New Link Added"
,
{
type
:
"success"
,
// success => color verde
autoClose
:
2000
// El mensaje se autocierra pasado 2 segundos
});
}
else
{
await
Firebase
.
firestore
.
collection
(
"links"
).
doc
(
currentId
).
update
(
linkObject
);
await
db
.
collection
(
"links"
).
doc
(
currentId
).
update
(
linkObject
);
toast
(
"Link Updated Successfully"
,
{
type
:
"info"
,
// info => color azul
autoClose
:
2000
// El mensaje se autocierra pasado 2 segundos
...
...
src/pages/auth/login.tsx
View file @
1d7838bf
...
...
@@ -67,6 +67,7 @@ const LoginPage: React.FunctionComponent<IPageProps> = props => {
<
AuthContainer
header=
"Login"
>
<
FormGroup
>
<
Input
style=
{
{
color
:
"white"
}
}
type=
"email"
name=
"email"
id=
"email"
...
...
@@ -77,6 +78,7 @@ const LoginPage: React.FunctionComponent<IPageProps> = props => {
</
FormGroup
>
<
FormGroup
>
<
Input
style=
{
{
color
:
"white"
}
}
autoComplete=
"new-password"
type=
"password"
name=
"password"
...
...
src/pages/auth/register.tsx
View file @
1d7838bf
...
...
@@ -79,6 +79,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => {
<
AuthContainer
header=
"Register"
>
<
FormGroup
>
<
Input
style=
{
{
color
:
"white"
}
}
type=
"email"
name=
"email"
id=
"email"
...
...
@@ -90,7 +91,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => {
<
FormGroup
>
{
/** El autocompletado es para que coincidan contrseñas*/
}
<
Input
style=
{
{
color
:
"white"
}
}
autoComplete=
"new-password"
type=
"password"
name=
"password"
...
...
@@ -102,6 +103,7 @@ const RegisterPage: React.FunctionComponent<IPageProps> = props => {
</
FormGroup
>
<
FormGroup
>
<
Input
style=
{
{
color
:
"white"
}
}
autoComplete=
"new-password"
type=
"password"
name=
"confirm"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment