Skip to content
Snippets Groups Projects
Commit d78d9864 authored by Amund Skuggevik Foss's avatar Amund Skuggevik Foss
Browse files

Merge branch '(#6)Structural_changes_to_files' into 'master'

Adjusting functions and styling, deleted searchBar

See merge request !6
parents cb331ee0 2ef43c7e
No related branches found
No related tags found
1 merge request!6Adjusting functions and styling, deleted searchBar
import { textAlign } from '@mui/system';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { Image, Text, StyleSheet, View } from "react-native"; import { Image, Text,TextInput, StyleSheet, View } from "react-native";
import SelectDropdown from 'react-native-select-dropdown' import SelectDropdown from 'react-native-select-dropdown'
import {SearchBar} from './SearchBar'
import {useRecoilState} from 'recoil' import {useRecoilState} from 'recoil'
import { capturedFilterState, typeState } from "../atoms/atoms"; import {searchState, capturedFilterState, typeState } from "../atoms/atoms";
export const Header = () => { export const Header = () => {
const [searchTextValue, setSearchTextValue] = useRecoilState(searchState)
const [capturedSorting, setCapturedSorting] = useRecoilState(capturedFilterState) const [capturedFiltering, setCapturedFiltering] = useRecoilState(capturedFilterState)
const [type, setType] = useRecoilState(typeState) const [type, setType] = useRecoilState(typeState)
const filterTypes = ["All", "Bug", "Dark", "Dragon", "Electric", "Fairy", "Fighting", "Fire", "Flying", "Ghost", "Grass", "Ground", "Ice", "Normal", "Poison", "Psychic", "Rock", "Steel", "Water"];
useEffect(() => { const SearchChange = (value: React.SetStateAction<string>) => {
console.log(capturedSorting) setSearchTextValue(value)
}, [capturedSorting]) };
useEffect(() => {
console.log(type)
}, [type])
const handleCapturedChange = (value: React.SetStateAction<string | boolean | null>) => { const filterTypes = [
"All",
"Bug",
"Dark",
"Dragon",
"Electric",
"Fairy",
"Fighting",
"Fire",
"Flying",
"Ghost",
"Grass",
"Ground",
"Ice",
"Normal",
"Poison",
"Psychic",
"Rock",
"Steel",
"Water"
];
const CapturedChange = (value: React.SetStateAction<string | boolean | null>) => {
console.log(value) console.log(value)
if (value === "All") { if (value == "All") {
setCapturedSorting(null); setCapturedFiltering(null);
} else if (value === "Captured") { } else if (value == "Captured") {
setCapturedSorting(true) setCapturedFiltering(true)
} else { } else {
setCapturedSorting(false) setCapturedFiltering(false)
} }
}; };
const TypeChange = ( value: React.SetStateAction<string>) => {
const handleTypeChange = ( value: React.SetStateAction<string>) => {
if (value === "All") { if (value === "All") {
setType(""); setType("");
} else { } else {
...@@ -45,50 +62,54 @@ export const Header = () => { ...@@ -45,50 +62,54 @@ export const Header = () => {
return ( return (
<View> <View>
{/* Image Container */}
<View style={styles.imgContainer}> <View style={styles.imgContainer}>
<Image style = {styles.pokemonImg} source={require("../resources/pokemonLogo.png")} /> <Image style = {styles.pokemonImg} source={require("../resources/pokemonLogo.png")} />
</View> </View>
{/* Search, Filtering and Sorting Container */}
<View style={styles.filteringSortingContainer}> <View style={styles.filteringContainer}>
<Text>Types</Text> <Text style={{fontSize: 20, marginBottom: 5}}>Types</Text>
<SelectDropdown <SelectDropdown
buttonStyle={styles.DropdownFilter} buttonStyle={styles.DropdownFilter}
defaultValue={"All"} defaultValue={"All"}
data={filterTypes} data={filterTypes}
onSelect={(selectedItem, index) => { onSelect={(selectedItem) => {
handleTypeChange(selectedItem) TypeChange(selectedItem)
}} }}
buttonTextAfterSelection={(selectedItem, index) => { buttonTextAfterSelection={(selectedItem) => {
// text represented after item is selected // text represented after item is selected
return selectedItem return selectedItem
}} }}
rowTextForSelection={(item, index) => { rowTextForSelection={(item) => {
// text represented for each item in dropdown // text represented for each item in dropdown
return item return item
}} }}
/> />
<Text>Status</Text> <Text style={{fontSize: 20, marginBottom: 5}}>Status</Text>
<SelectDropdown <SelectDropdown
buttonStyle={styles.DropdownFilter} buttonStyle={styles.DropdownFilter}
defaultValue={"All"} defaultValue={"All"}
data={["All", "Captured", "Not captured"]} data={["All", "Captured", "Not captured"]}
onSelect={(selectedItem, index) => { onSelect={(selectedItem) => {
handleCapturedChange(selectedItem) CapturedChange(selectedItem)
}} }}
buttonTextAfterSelection={(selectedItem, index) => { buttonTextAfterSelection={(selectedItem) => {
// text represented after item is selected
return selectedItem return selectedItem
}} }}
rowTextForSelection={(item, index) => { rowTextForSelection={(item) => {
// text represented for each item in dropdown
return item return item
}} }}
/> />
<SearchBar /> <TextInput
style={styles.searchBox}
placeholder={"Search Pokemons"}
value={searchTextValue}
onChangeText={(value) => SearchChange(value)}
></TextInput>
</View> </View>
</View> </View>
...@@ -101,8 +122,7 @@ const styles = StyleSheet.create ({ ...@@ -101,8 +122,7 @@ const styles = StyleSheet.create ({
imgContainer: { imgContainer: {
flex: 1, flex: 1,
alignItems: "center", alignItems: "center",
paddingBottom: 15, margin: 5
paddingTop: 5
}, },
pokemonImg: { pokemonImg: {
...@@ -113,8 +133,8 @@ const styles = StyleSheet.create ({ ...@@ -113,8 +133,8 @@ const styles = StyleSheet.create ({
}, },
filteringSortingContainer: { filteringContainer: {
backgroundColor: "#1E90FFFF", borderColor: "black",
maxWidth: "100%", maxWidth: "100%",
minWidth: "85%", minWidth: "85%",
flex: 1, flex: 1,
...@@ -123,10 +143,22 @@ const styles = StyleSheet.create ({ ...@@ -123,10 +143,22 @@ const styles = StyleSheet.create ({
}, },
DropdownFilter: { DropdownFilter: {
marginBottom: 5, marginBottom: 5,
borderColor: "gray", borderColor: "black",
borderWidth: 0.3, borderWidth: 0.3,
borderRadius: 10, borderRadius: 10,
width: 300 width: 300
},
searchBox: {
borderColor: "black",
width: "50%",
borderWidth: 0.3,
borderRadius: 10,
padding: 10,
marginTop: 10,
marginBottom: 10,
backgroundColor: "#FFE",
height: 50,
textAlign: 'center'
} }
}) })
......
import React from "react"
import { StyleSheet, TextInput } from "react-native";
import { useRecoilState } from "recoil";
import { searchState } from "../atoms/atoms";
export const SearchBar = () => {
const [searchText, setSearchText] = useRecoilState(searchState)
const handleSearchChange = (value: React.SetStateAction<string>) => {
setSearchText(value)
};
return (
<TextInput
style={styles.searchBar}
placeholder={"Search Pokemons"}
textAlign={'center'}
value={searchText}
onChangeText={(value) => handleSearchChange(value)}
></TextInput>
)
}
const styles = StyleSheet.create({
searchBar: {
borderColor: "gray",
width: "50%",
borderWidth: 0.3,
borderRadius: 10,
padding: 10,
marginTop: 10,
marginBottom: 10,
backgroundColor: "#FFE",
height: 50
}
})
export default SearchBar
\ No newline at end of file
...@@ -14,7 +14,8 @@ export const PokemonsContainer = () => { ...@@ -14,7 +14,8 @@ export const PokemonsContainer = () => {
const searchText = useRecoilValue(searchState) const searchText = useRecoilValue(searchState)
const typeText = useRecoilValue(typeState) const typeText = useRecoilValue(typeState)
const capturedState = useRecoilValue(capturedFilterState) const capturedState = useRecoilValue(capturedFilterState)
const limit = 14
const [limit, setLimit] = useState(15)
const [skip, setSkip] = useState(0) const [skip, setSkip] = useState(0)
const {loading, data} = useQuery(SEARCH_POKEMONS, { const {loading, data} = useQuery(SEARCH_POKEMONS, {
...@@ -30,21 +31,24 @@ export const PokemonsContainer = () => { ...@@ -30,21 +31,24 @@ export const PokemonsContainer = () => {
} }
}) })
const handlePaginationButton = (newPage: string) => { const updateLabelAndSkip = (prevOrNext: string) => {
if(newPage === 'prev'){
setSkip(skip - 14) if (prevOrNext === "next"){
setSkip(skip + 15)
} else { } else {
setSkip(skip + 14) setSkip(skip - 15)
} }
} }
useEffect(() => { useEffect(() => {
setSkip(0) setSkip(0)
setLimit(15)
}, [searchText, typeText, capturedState]) }, [searchText, typeText, capturedState])
if (loading){ if (loading){
return ( return (
<Text>LOADING..</Text> <Text>Please wait..</Text>
) )
} else if (data.searchPokemon === 0) { } else if (data.searchPokemon === 0) {
<Text>No matches for this search</Text> <Text>No matches for this search</Text>
...@@ -59,19 +63,15 @@ export const PokemonsContainer = () => { ...@@ -59,19 +63,15 @@ export const PokemonsContainer = () => {
<View style = {styles.paginationContainers}> <View style = {styles.paginationContainers}>
{skip >= 14 && data.searchPokemon.length >= 4 && {
<TouchableOpacity style={styles.paginationButtonPrevPage} onPress={() => handlePaginationButton("prev")}> skip >= 15 &&
<Image <TouchableOpacity style={styles.ButtonPrevTouch} onPress={() => updateLabelAndSkip("prev")}>
style = {styles.prevButton} <Image style = {styles.prevButton} source={require('../resources/button.png')}/>
source={require('../resources/button.png')}
/>
</TouchableOpacity>} </TouchableOpacity>}
{data.searchPokemon.length >= 14 && {
<TouchableOpacity style={styles.paginationButtonNextPage} onPress={() => handlePaginationButton("next")}> data.searchPokemon.length >= 15 &&
<Image <TouchableOpacity style={styles.ButtonNextTouch} onPress={() => updateLabelAndSkip("next")}>
style = {styles.nextButton} <Image style = {styles.nextButton} source={require('../resources/button.png')}/>
source={require('../resources/button.png')}
/>
</TouchableOpacity>} </TouchableOpacity>}
</View> </View>
...@@ -104,13 +104,13 @@ const styles = StyleSheet.create({ ...@@ -104,13 +104,13 @@ const styles = StyleSheet.create({
height: "100%" height: "100%"
}, },
paginationButtonNextPage: { ButtonNextTouch: {
width: 50, width: 50,
height: 50, height: 50,
color: "white" color: "white"
}, },
paginationButtonPrevPage: { ButtonPrevTouch: {
width: 50, width: 50,
height: 50, height: 50,
color: "white", color: "white",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment