Members
(constant) filterPokemons
Selector: Filters the Pokemon based on search query and filters.
filteredPokemonsElements
Renders the filtered Pokemon cards if the search exists and returns search results.
It the search exists, but returns no results, the user is notified.
(constant) initialState
Initial state
(constant) persistConfig
Configuration object for redux-persist.
Only objects on the whitelist are stored.
- Source:
(constant) persistedReducer
Persisted reducer
- Source:
(constant) persistor
The Redux persistor for persisting store state.
- Source:
(constant) pokemonsAdapter
Entity adapter
pokemonsElements
Renders the Pokemon cards.
(constant) pokemonsSelectors
Creates a selector object for working with the entity data, e.g. selectEntities.
(constant) searchExists
To check if a search exists
(constant) store
The Redux store.
- Source:
Methods
abilitiesElements(abilities) → {Array}
Creates the JSX elements of the Pokemon's abilities
Parameters:
Name | Type | Description |
---|---|---|
abilities |
Object | Containg data on the Pokemon's abilities. |
Returns:
- Containing JSX elements with the Pokemon's abilities.
- Type
- Array
extraReducers()
Handles the async actions for fetching Pokemon.
(async) fetchPokemons() → {Promise:.<Array:.<Object:>>}
Fetches the Pokemon data from the API.
- Source:
Throws:
-
If there is an error fetching the data.
- Type
- Error
Returns:
The array of Pokemon data.
fetchPokemonsThunk()
Fetches the Pokemon with a thunk function
filterByAbility(abilityFilter, pokemon) → {boolean}
Filters Pokemons by ability based on the ability filter.
Parameters:
Name | Type | Description |
---|---|---|
abilityFilter |
string | The ability filter string. |
pokemon |
Object | The Pokemon object to filter. |
Returns:
Whether the Pokemon has the ability or not.
- Type
- boolean
filterByQuery(searchQuery, pokemons) → {Array}
Filters Pokemons by name based on the search query.
Parameters:
Name | Type | Description |
---|---|---|
searchQuery |
string | The search query string. |
pokemons |
Array | The array of Pokemons to filter. |
Returns:
The filtered array of Pokemons.
- Type
- Array
filterByType(typeFilter, pokemon) → {boolean}
Filters Pokemons by type based on the type filter.
Parameters:
Name | Type | Description |
---|---|---|
typeFilter |
string | The type filter string. |
pokemon |
Object | The Pokemon object to filter. |
Returns:
Whether the Pokemon matches the type filter or not.
- Type
- boolean
handleAbilityFilterChange(event)
Dispatches the action to update ability filter and performs the filtering by ability.
Parameters:
Name | Type | Description |
---|---|---|
event |
Object | The event to get the value from the selected ability. |
handleKeyDownNameForm()
Handles when the user presses Enter instead of "Save" button.
Prevents the default action of submitting the form, causing a refresh.
handleOnKeyDownSearchForm()
Prevents the default submitting of the form if the user presses Enter.
handleQueryChange(event)
Dispatches the action to update the search query and performs the search.
Parameters:
Name | Type | Description |
---|---|---|
event |
Object | The event to get the value in the form. |
handleResetFilters()
Dispatches actions to reset all the filters.
handleRetry()
Handles the retry action when fetching Pokemon fails.
handleSavePokemon()
Dispatches the action to save/delete a Pokemon when the user clicks on the save/delete icon.
handleSortByHP()
Dispatches the action to sort by HP(high to low).
handleSortByName()
Dispatches the action to sort alphabetically.
handleSubmitNewName()
Dispatches action for updating the Pokemon's name.
handleTypeFilterChange(event)
Dispatches the action to update type filter and performs the filtering by type.
Parameters:
Name | Type | Description |
---|---|---|
event |
Object | The event to get the value from the selected type. |
pokemonSlice()
Slice containing the reducers and actions.
Generates action creators and action types.
savedPokemonsElements() → {Array:.<JSX.Element:>}
Renders the saved Pokemon cards.
Returns:
The array of rendered Pokemon cards.
selectAllPokemons()
Selector: Selects all Pokemon that are not saved by the user.
selectAllPokemons()
Selector: Selects all Pokemon that are saved by the user.
sortPokemons(sortBy, pokemons) → {Array}
Sorts Pokemons based on the given sort criteria.
Parameters:
Name | Type | Description |
---|---|---|
sortBy |
string | The sort criteria (e.g., 'name', 'hp'). |
pokemons |
Array | The array of Pokemons to sort. |
Returns:
The sorted array of Pokemons.
- Type
- Array
toggleEditNameForm()
Sets the local state to show/hide the edit name form.
toggleSavePokemon()
Reducer: Toggles the save state for pokemons (myPokemon)
Parameters:
Type | Description |
---|---|
Object |
updateAbilityFilter(state, action)
Reducer: Updates the ability filter and filters Pokemon by chosen ability.
Parameters:
Name | Type | Description |
---|---|---|
state |
Object | Current state. |
action |
Object | Action containing the ability to filter by, e.g. "Run-Away" |
updatePokemonName()
Reducer: Updates the name of a saved pokemon.
Parameters:
Type | Description |
---|---|
Object |
updateSearchQuery(state, action)
Reducer: Updates the search query and filters the Pokemon based on the query.
Parameters:
Name | Type | Description |
---|---|---|
state |
Object | Current state. |
action |
Object | Action containing the search query. |
updateSortBy(state, action)
Reducer: Updates the sort by in state and sorts either alphabetically or by HP.
Parameters:
Name | Type | Description |
---|---|---|
state |
Object | Current state. |
action |
Object | Action containing either "name" or "hp". |
updateTypeFilter(state, action)
Reducer: Updates the type filter and filters Pokemon based on chosen type.
Parameters:
Name | Type | Description |
---|---|---|
state |
Object | Current state. |
action |
Object | Action containing the Pokemon type, e.g. "Grass". |
Type Definitions
PokemonData
Type:
- Object
Properties:
- Source: