|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
|
|
|
|
|
import { StyleSheet, Text, View, Button, TouchableHighlight } from 'react-native';
|
|
|
|
|
import { StyleSheet, Text, View, Button, TouchableHighlight, Pressable } from 'react-native';
|
|
|
|
|
import { StatusBar } from 'expo-status-bar';
|
|
|
|
|
import React, { useState, useEffect } from "react";
|
|
|
|
|
import { FlatList } from 'react-native-gesture-handler';
|
|
|
|
@ -11,11 +11,12 @@ import { ThunkAction } from 'redux-thunk';
|
|
|
|
|
//? possiblement à supprimer
|
|
|
|
|
import { getAllCards } from "../redux/actions/actionSelection"
|
|
|
|
|
|
|
|
|
|
import { StubLib } from '../data/stub';
|
|
|
|
|
import { Card } from '../models/Card';
|
|
|
|
|
import { Image } from 'react-native';
|
|
|
|
|
import { ImageURISource } from 'react-native';
|
|
|
|
|
|
|
|
|
|
import { switchMode } from '../redux/actions/action_switchMode';
|
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const Item = ({url}) => (
|
|
|
|
|
// <View style={styles.item}>
|
|
|
|
@ -25,20 +26,20 @@ const Item = ({url}) => (
|
|
|
|
|
<Image
|
|
|
|
|
source={{uri:url}}
|
|
|
|
|
style={{flex:1, minHeight:250, minWidth:180}}/>
|
|
|
|
|
|
|
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
export default function ListScreen({navigation}){
|
|
|
|
|
const [count, setCount] = useState(0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// // Initialize the binding content with the application initial state
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const theme = useSelector(state => state.theme);
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const nList = useSelector(state => state.appReducer.cards);
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const mode = useSelector(state => state.appReducer.mode);
|
|
|
|
|
|
|
|
|
|
// Create a const that will hold the react-redux events dispatcher
|
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
|
@ -46,7 +47,6 @@ export default function ListScreen({navigation}){
|
|
|
|
|
// You cannot perform side-effects outside of a useEffect hook
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
console.log("USEEFFECT")
|
|
|
|
|
const loadCards = async () => {
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
await dispatch(getAllCards());
|
|
|
|
@ -54,21 +54,20 @@ export default function ListScreen({navigation}){
|
|
|
|
|
loadCards();
|
|
|
|
|
}, [dispatch]);
|
|
|
|
|
|
|
|
|
|
// Handle changing the theme mode
|
|
|
|
|
|
|
|
|
|
//@ts-ignore
|
|
|
|
|
const handleThemeChange = (mode) => {
|
|
|
|
|
dispatch(switchMode(mode === 'light' ? 'dark' : 'light'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//* Stub
|
|
|
|
|
// const {getCards} = new StubLib();
|
|
|
|
|
// const list: Card[] = getCards();
|
|
|
|
|
// const req = fetch('https://omgvamp-hearthstone-v1.p.rapidapi.com/cards')
|
|
|
|
|
|
|
|
|
|
//https://us.api.blizzard.com/hearthstone/cards/678?locale=en_US
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<View style={styles.container}>
|
|
|
|
|
{/* <FlatList data={nList}
|
|
|
|
|
renderItem={({item}) => <Item title={item.name} />}
|
|
|
|
|
keyExtractor={item => item.id}/> */}
|
|
|
|
|
|
|
|
|
|
<View style={mode === 'light' ? styles.container_light : styles.container_dark}>
|
|
|
|
|
<Pressable style={mode === 'light' ? styles.button_white : styles.button_black} onPress={() => handleThemeChange(mode)}>
|
|
|
|
|
<Text>Switch Mode</Text>
|
|
|
|
|
</Pressable>
|
|
|
|
|
<FlatList
|
|
|
|
|
numColumns={2}
|
|
|
|
|
data={nList}
|
|
|
|
@ -78,18 +77,9 @@ export default function ListScreen({navigation}){
|
|
|
|
|
<TouchableHighlight onPress={() => navigation.navigate("ListFav")}>
|
|
|
|
|
<Item url={item.img}/>
|
|
|
|
|
</TouchableHighlight>
|
|
|
|
|
|
|
|
|
|
// //<Text>{item.name}</Text>
|
|
|
|
|
// // <View>
|
|
|
|
|
// // <Image
|
|
|
|
|
// // source={{uri:item.img}}
|
|
|
|
|
// // style={{flex:1, minHeight:250, minWidth:180}}/>
|
|
|
|
|
|
|
|
|
|
// // </View>
|
|
|
|
|
} keyExtractor={(item: Card) => item.id.toString()}/>
|
|
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -121,5 +111,45 @@ const styles = StyleSheet.create({
|
|
|
|
|
},
|
|
|
|
|
title: {
|
|
|
|
|
fontStyle: "italic",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
///themes
|
|
|
|
|
container_light: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
backgroundColor: '#fff',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
},
|
|
|
|
|
container_dark: {
|
|
|
|
|
flex: 1,
|
|
|
|
|
backgroundColor: '#3e3e42',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
},
|
|
|
|
|
text_light: {
|
|
|
|
|
marginBottom: 20,
|
|
|
|
|
color: '#000'
|
|
|
|
|
},
|
|
|
|
|
text_dark: {
|
|
|
|
|
marginBottom: 20,
|
|
|
|
|
color: "#fff"
|
|
|
|
|
},
|
|
|
|
|
button_black: {
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
paddingVertical: 12,
|
|
|
|
|
paddingHorizontal: 32,
|
|
|
|
|
borderRadius: 4,
|
|
|
|
|
elevation: 3,
|
|
|
|
|
backgroundColor: 'black',
|
|
|
|
|
},
|
|
|
|
|
button_white: {
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
paddingVertical: 12,
|
|
|
|
|
paddingHorizontal: 32,
|
|
|
|
|
borderRadius: 4,
|
|
|
|
|
elevation: 3,
|
|
|
|
|
backgroundColor: 'white',
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|