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

Merge branch '(#5)Add_design_and_comments' into 'master'

(#5)add design and comments

See merge request !5
parents 6f319824 15c954bb
No related branches found
No related tags found
2 merge requests!5(#5)add design and comments,!4Finished pagination
import React from 'react'; import React from 'react';
import { SafeAreaView, SafeAreaViewBase, ScrollView, StyleSheet, Text, View } from 'react-native'; import { SafeAreaView, ScrollView, StyleSheet, Text, View } from 'react-native';
import PokemonsContainer from './containers/PokemonsContainer'; import PokemonsContainer from './containers/PokemonsContainer';
import {ApolloClient, ApolloProvider, InMemoryCache} from "@apollo/client"; import {ApolloClient, ApolloProvider, InMemoryCache} from "@apollo/client";
import { Header } from './containers/Header'; import { Header } from './components/Header';
import { import {
RecoilRoot, RecoilRoot,
atom,
selector,
useRecoilState,
useRecoilValue,
} from 'recoil'; } from 'recoil';
const App = () => { const App = () => {
......
import { Select } from '@mui/material';
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { Image, Text, StyleSheet, View, TouchableOpacity } from "react-native"; import { Image, Text, StyleSheet, View } from "react-native";
import SelectDropdown from 'react-native-select-dropdown' import SelectDropdown from 'react-native-select-dropdown'
import {SearchBar} from "./SearchBar" import {SearchBar} from './SearchBar'
import {useRecoilState} from 'recoil' import {useRecoilState} from 'recoil'
import { capturedFilterState, typeState } from "../atoms/atoms"; import { capturedFilterState, typeState } from "../atoms/atoms";
import { maxHeight, maxWidth } from '@mui/system';
export const Header = () => { export const Header = () => {
const [capturedSorting, setCapturedSorting] = useRecoilState(capturedFilterState) const [capturedSorting, setCapturedSorting] = useRecoilState(capturedFilterState)
const [type, setType] = useRecoilState(typeState) const [type, setType] = useRecoilState(typeState)
...@@ -109,7 +108,9 @@ const styles = StyleSheet.create ({ ...@@ -109,7 +108,9 @@ const styles = StyleSheet.create ({
pokemonImg: { pokemonImg: {
flex: 1, flex: 1,
width: 250, width: 250,
height: 110 height: 110,
resizeMode: 'contain'
}, },
filteringSortingContainer: { filteringSortingContainer: {
...@@ -128,8 +129,6 @@ const styles = StyleSheet.create ({ ...@@ -128,8 +129,6 @@ const styles = StyleSheet.create ({
width: 300 width: 300
} }
}) })
export default Header export default Header
function typeFilter(arg0: () => void, typeFilter: any) {
throw new Error('Function not implemented.');
}
...@@ -30,7 +30,7 @@ const PokemonCard: React.FC<{ pokemon: Pokemon }> = ({pokemon}) => { ...@@ -30,7 +30,7 @@ const PokemonCard: React.FC<{ pokemon: Pokemon }> = ({pokemon}) => {
return ( //touchablewithoutfeedback for mer info knappen return ( //touchablewithoutfeedback for mer info knappen
<View style={styles.pokemon}> <View style={styles.pokemon}>
<View style={styles.pokemon__name}> <View style={styles.pokemon__name}>
<Text>{pokemon.name}</Text> <Text style = {styles.pokeman__name_text}>{pokemon.name}</Text>
</View> </View>
{clicked && {clicked &&
...@@ -86,7 +86,14 @@ const styles = StyleSheet.create({ ...@@ -86,7 +86,14 @@ const styles = StyleSheet.create({
textAlign: 'center', textAlign: 'center',
alignItems: 'center', alignItems: 'center',
padding: 10, padding: 10,
},
pokeman__name_text: {
color: 'white',
fontWeight: 'bold',
fontSize: 15,
}, },
pokemon__meta: { pokemon__meta: {
flex: 1, flex: 1,
justifyContent: 'center', justifyContent: 'center',
...@@ -95,15 +102,17 @@ const styles = StyleSheet.create({ ...@@ -95,15 +102,17 @@ const styles = StyleSheet.create({
padding: 0, padding: 0,
}, },
pokemon__meta_text: { pokemon__meta_text: {
color: 'white',
backgroundColor: '#7bb7b7', backgroundColor: '#7bb7b7',
color: 'white',
fontWeight: 'bold', fontWeight: 'bold',
fontSize: 15,
margin: 0, margin: 0,
paddingTop: 5, paddingTop: 5,
paddingBottom: 10, paddingBottom: 10,
borderRadius: 5, borderRadius: 5,
width: 50, width: 50,
textAlign: 'center', textAlign: 'center',
}, },
pokemon__image: { pokemon__image: {
padding: 15, padding: 15,
...@@ -111,12 +120,16 @@ const styles = StyleSheet.create({ ...@@ -111,12 +120,16 @@ const styles = StyleSheet.create({
marginBottom: 10, marginBottom: 10,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
}, },
pokemon__image_img: { pokemon__image_img: {
maxWidth: 120, maxWidth: 120,
maxHeight: 127, maxHeight: 130,
minHeight: 115, minHeight: 120,
minWidth: 120, minWidth: 120,
aspectRatio: 1,
resizeMode: 'contain'
}, },
pokemon__type: { pokemon__type: {
flex: 1, flex: 1,
...@@ -161,5 +174,4 @@ const styles = StyleSheet.create({ ...@@ -161,5 +174,4 @@ const styles = StyleSheet.create({
} }
}); });
export default PokemonCard export default PokemonCard
\ No newline at end of file
import React, { useEffect } from "react" import React from "react"
import { StyleSheet, TextInput } from "react-native"; import { StyleSheet, TextInput } from "react-native";
import { useRecoilState } from "recoil"; import { useRecoilState } from "recoil";
import { searchState } from "../atoms/atoms"; import { searchState } from "../atoms/atoms";
...@@ -6,6 +6,7 @@ import { searchState } from "../atoms/atoms"; ...@@ -6,6 +6,7 @@ import { searchState } from "../atoms/atoms";
export const SearchBar = () => { export const SearchBar = () => {
const [searchText, setSearchText] = useRecoilState(searchState) const [searchText, setSearchText] = useRecoilState(searchState)
const handleSearchChange = (value: React.SetStateAction<string>) => { const handleSearchChange = (value: React.SetStateAction<string>) => {
......
import React, { useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Alert, Button, NativeSyntheticEvent, NativeTouchEvent, ScrollView, StyleSheet, Text, View } from 'react-native'; import { Image, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import PokemonCard from '../components/PokemonCard'; import PokemonCard from '../components/PokemonCard';
import {SEARCH_POKEMONS} from '../graphql/get-pokemons'; import {SEARCH_POKEMONS} from '../graphql/get-pokemons';
import {useQuery} from '@apollo/react-hooks'; import {useQuery} from '@apollo/react-hooks';
import {Pokemon} from "../types/types"; import {Pokemon} from "../types/types";
import { useRecoilValue } from "recoil"; import { useRecoilValue } from "recoil";
import { capturedFilterState, searchState, typeState } from '../atoms/atoms'; import { capturedFilterState, searchState, typeState } from '../atoms/atoms';
import { borderColor, borders } from '@mui/system';
const PokemonsContainer = () => { 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, error, data} = useQuery(SEARCH_POKEMONS, { const {loading, data} = useQuery(SEARCH_POKEMONS, {
fetchPolicy: "no-cache", fetchPolicy: "no-cache",
variables: { variables: {
searchInput: { searchInput: {
...@@ -32,10 +30,25 @@ const PokemonsContainer = () => { ...@@ -32,10 +30,25 @@ const PokemonsContainer = () => {
} }
}) })
const handlePaginationButton = (newPage: string) => {
if(newPage === 'prev'){
setSkip(skip - 14)
} else {
setSkip(skip + 14)
}
}
useEffect(() => {
setSkip(0)
}, [searchText, typeText, capturedState])
if (loading){ if (loading){
return ( return (
<Text>LOADING..</Text> <Text>LOADING..</Text>
) )
} else if (data.searchPokemon === 0) {
<Text>No matches for this search</Text>
} }
else{ else{
return ( return (
...@@ -44,6 +57,24 @@ const PokemonsContainer = () => { ...@@ -44,6 +57,24 @@ const PokemonsContainer = () => {
<PokemonCard key={pokemon.id} pokemon={pokemon}/>) <PokemonCard key={pokemon.id} pokemon={pokemon}/>)
} }
<View style = {styles.paginationContainers}>
{skip >= 14 && data.searchPokemon.length >= 4 &&
<TouchableOpacity style={styles.paginationButtonPrevPage} onPress={() => handlePaginationButton("prev")}>
<Image
style = {styles.prevButton}
source={require('../resources/button.png')}
/>
</TouchableOpacity>}
{data.searchPokemon.length >= 14 &&
<TouchableOpacity style={styles.paginationButtonNextPage} onPress={() => handlePaginationButton("next")}>
<Image
style = {styles.nextButton}
source={require('../resources/button.png')}
/>
</TouchableOpacity>}
</View>
</View> </View>
) )
...@@ -63,6 +94,38 @@ const styles = StyleSheet.create({ ...@@ -63,6 +94,38 @@ const styles = StyleSheet.create({
}, },
prevButton: {
width: "100%",
height: "100%"
},
nextButton: {
width: "100%",
height: "100%"
},
paginationButtonNextPage: {
width: 50,
height: 50,
color: "white"
},
paginationButtonPrevPage: {
width: 50,
height: 50,
color: "white",
transform: [
{scaleX: -1} //horizontally flip for previous button
]
},
paginationContainers: {
flex: 1,
justifyContent: 'space-between',
flexDirection: 'row',
marginBottom: 15,
marginRight: 10,
marginLeft: 10
}
}); });
......
documentation_images/QR-Scan.PNG

15.8 KiB

resources/button.png

1.98 KiB | W: | H:

resources/button.png

20.4 KiB | W: | H:

resources/button.png
resources/button.png
resources/button.png
resources/button.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment