Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Ondřej Bazala
PV247
Commits
835c8c85
Unverified
Commit
835c8c85
authored
Nov 06, 2021
by
Michal Čaniga
Browse files
Add data
parent
2d995363
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/data/dummyUserData.ts
0 → 100644
View file @
835c8c85
import
{
UserData
}
from
'
../utils/firebase
'
;
const
dummyUserData
:
UserData
[]
=
[
{
userId
:
'
1
'
,
catchedPokemonIds
:
[
1
,
2
,
3
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
213
,
highestScore
:
1647
,
highestSecondsAlive
:
8
},
{
userId
:
'
2
'
,
catchedPokemonIds
:
[
5
,
8
],
pokeballIds
:
[
2
],
foodIds
:
[],
actualScore
:
1365
,
highestScore
:
13657
,
highestSecondsAlive
:
21
},
{
userId
:
'
3
'
,
catchedPokemonIds
:
[
6
,
9
],
pokeballIds
:
[],
foodIds
:
[
1
],
actualScore
:
1234
,
highestScore
:
2348
,
highestSecondsAlive
:
81
},
{
userId
:
'
4
'
,
catchedPokemonIds
:
[
1
,
2
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
1234
,
highestScore
:
64123
,
highestSecondsAlive
:
312
},
{
userId
:
'
5
'
,
catchedPokemonIds
:
[
2
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
2136
,
highestScore
:
21487
,
highestSecondsAlive
:
124
},
{
userId
:
'
6
'
,
catchedPokemonIds
:
[
3
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
75
,
highestScore
:
513
,
highestSecondsAlive
:
12
},
{
userId
:
'
7
'
,
catchedPokemonIds
:
[
1
,
2
,
3
,
8
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
1235
,
highestScore
:
5413
,
highestSecondsAlive
:
123
},
{
userId
:
'
8
'
,
catchedPokemonIds
:
[
1
,
3
,
4
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
654
,
highestScore
:
2486
,
highestSecondsAlive
:
71
},
{
userId
:
'
9
'
,
catchedPokemonIds
:
[
30
,
31
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
1003
,
highestScore
:
4879
,
highestSecondsAlive
:
96
},
{
userId
:
'
10
'
,
catchedPokemonIds
:
[
100
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
745
,
highestScore
:
12387
,
highestSecondsAlive
:
12
},
{
userId
:
'
11
'
,
catchedPokemonIds
:
[
82
,
83
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
819
,
highestScore
:
67512
,
highestSecondsAlive
:
16
},
{
userId
:
'
12
'
,
catchedPokemonIds
:
[
84
,
86
],
pokeballIds
:
[
1
],
foodIds
:
[
1
],
actualScore
:
123
,
highestScore
:
41235
,
highestSecondsAlive
:
19
}
];
src/data/food.ts
View file @
835c8c85
import
{
getDataByIds
}
from
'
../utils/dataUtils
'
;
export
type
Food
=
{
id
:
number
;
name
:
string
;
price
:
number
;
restores
:
number
;
image
?:
string
;
};
// export const food: Food[] = [{}, {}, {}];
export
const
food
:
Food
[]
=
[
{
id
:
1
,
name
:
'
Beer
'
,
price
:
123
,
restores
:
1
},
{
id
:
2
,
name
:
'
Chicken Wings
'
,
price
:
471
,
restores
:
2
}
];
export
const
getUserFood
=
(
foodIds
:
number
[]):
Food
[]
=>
getDataByIds
(
food
,
foodIds
);
src/data/pokeballs.ts
View file @
835c8c85
import
{
getDataByIds
}
from
'
../utils/dataUtils
'
;
export
type
Pokeballs
=
{
id
:
number
;
name
:
string
;
price
:
number
;
image
?:
string
;
};
// export const pokeballs: Pokeballs[] = [{}, {}, {}];
export
const
pokeballs
:
Pokeballs
[]
=
[
{
id
:
1
,
name
:
'
Pokeball 1
'
,
price
:
12
},
{
id
:
2
,
name
:
'
Pokeball 2
'
,
price
:
48
},
{
id
:
3
,
name
:
'
Pokeball 3
'
,
price
:
19
}
];
export
const
getUserPokeballs
=
(
pokeballIds
:
number
[]):
Pokeballs
[]
=>
getDataByIds
(
pokeballs
,
pokeballIds
);
src/data/pokemons.ts
View file @
835c8c85
import
{
getDataByIds
}
from
'
../utils/dataUtils
'
;
import
{
Pokemon
}
from
'
./pokemonFetcher
'
;
export
const
getCatchedPokemons
=
(
catchedPokemonIds
:
number
[]):
Pokemon
[]
=>
getDataByIds
(
pokemons
,
catchedPokemonIds
);
// data is saved result of getPokemons obtained from src/pokemonFetcher.ts
export
const
pokemons
=
[
export
const
pokemons
:
Pokemon
[]
=
[
{
id
:
1
,
name
:
'
bulbasaur
'
,
...
...
src/utils/dataUtils.ts
0 → 100644
View file @
835c8c85
// Arrow functions doesn't support generics
// eslint-disable-next-line prefer-arrow/prefer-arrow-functions
export
function
getDataByIds
<
T
extends
{
id
:
number
}
>
(
data
:
T
[],
ids
:
number
[]
):
T
[]
{
return
data
.
filter
(
obj
=>
ids
.
includes
(
obj
.
id
));
}
src/utils/firebase.ts
View file @
835c8c85
...
...
@@ -7,7 +7,13 @@ import {
onAuthStateChanged
,
User
}
from
'
firebase/auth
'
;
import
{
getFirestore
}
from
'
firebase/firestore
'
;
import
{
collection
,
CollectionReference
,
doc
,
DocumentReference
,
getFirestore
}
from
'
firebase/firestore
'
;
// Initialize Firebase
initializeApp
({
...
...
@@ -39,3 +45,21 @@ export const onAuthChanged = (callback: (u: User | null) => void) =>
// Firestore
const
db
=
getFirestore
();
export
type
UserData
=
{
userId
:
string
;
catchedPokemonIds
:
number
[];
pokeballIds
:
number
[];
foodIds
:
number
[];
actualScore
:
number
;
highestScore
:
number
;
highestSecondsAlive
:
number
;
};
export
const
userDataCollection
=
collection
(
db
,
'
userData
'
)
as
CollectionReference
<
UserData
>
;
export
const
userDataDocument
=
(
id
:
string
)
=>
doc
(
db
,
'
userData
'
,
id
)
as
DocumentReference
<
UserData
>
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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