Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
APP-Guardar-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
APP-Guardar-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';
...
@@ -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
)
...
...
src/config/firebase.ts
View file @
1d7838bf
...
@@ -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
;
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';
...
@@ -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
>
...
...
src/pages/auth/Links.js
View file @
1d7838bf
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/firebas
e"
;
import
db
from
"../../config/firestor
e"
;
//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
...
...
src/pages/auth/login.tsx
View file @
1d7838bf
...
@@ -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"
...
...
src/pages/auth/register.tsx
View file @
1d7838bf
...
@@ -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"
...
...
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