cleanUp #8

Merged
corentin.richard merged 2 commits from cleanUp into master 2 years ago

@ -3,7 +3,7 @@ import { Card } from "../models/Card";
import { setFavList } from "../redux/actions/action_setFavList";
import { ImageBackground, TouchableHighlight, View } from "react-native";
import React, { useEffect } from "react";
import {CardProps} from "../props/favprops"
import {CardProps} from "../props/favProps"
import { FontAwesome } from '@expo/vector-icons';
import { StyleSheet} from 'react-native';
@ -15,8 +15,7 @@ export default function Item(props: CardProps){ // a mettre dans components et d
const dispatch = useDispatch()
const HandleAddFav = (props : CardProps) => {
console.log("add new card")
dispatch(setFavList(props));
dispatch(setFavList(props));
}
return(

@ -1,41 +0,0 @@
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import React, { useState } from "react";
// @ts-ignore
export default function Main(props : mainProps){
const [count, setCount] = useState(0);
return (
<View style={styles.container}>
<View style={styles.border}>
<Text>Maman, prend la caméra ! !</Text>
<StatusBar style="auto" />
<Text>{count}</Text>
<Button onPress={()=> setCount(count+1)} title="+1"/>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ffffff',
alignItems: 'center',
justifyContent: 'center',
borderWidth: 5,
borderColor : "#ff00ff",
},
border: {
flex: 1,
backgroundColor: '#ff0000',
maxHeight : 100,
borderWidth : 15,
borderRadius : 15,
borderColor : '#00ffaa',
alignItems: 'center',
justifyContent: 'center',
}
});

@ -1,138 +1,27 @@
import {isValidNumber} from "react-native-gesture-handler/lib/typescript/web_hammer/utils";
import {CardSet} from "./CardSet";
import {Type} from "./Type";
import {Classe} from "./Classe";
export class Card {
constructor(id: string,name :string, img : string, imgGold : string,fav : boolean = true){//,set : CardSet,type : Type,clas : Classe,rarity : string,cost : number,attack : number, health : number, desc : string,flavor : string,artist : string,collectible : boolean,elite : boolean,race : string, cropImg :string ) {
constructor(id: string,name :string, img : string, imgGold : string,fav : boolean = true){
this.id=id
this.name=name
//this._set=set
// this._type=type
// this._class=clas
// this._rarity=rarity
// this._cost=cost
// this._attack = attack
// this._health = health
// this._desc = desc
// this._flavor = flavor
// this._artist = artist
// this._collectible = collectible
this.img = img
this.imgGold = imgGold
// this._cropImg = cropImg
this.fav = fav
}
// ID //
public id;
// NAME //
public name;
// private _set : CardSet;
// get set(): CardSet{
// return this._set
// }
// set set(value : CardSet){
// this._set = value
// }
// private _type : Type;
// get type():Type{
// return this._type
// }
// set type(value : Type){
// this._type=value
// }
// private _class : Classe;
// get class():Classe{
// return this._class
// }
// set class(value : Classe){
// this._class=value
// }
// private _rarity : string
// get rarity(): string {
// return this._rarity;
// }
// set rarity(value: string) {
// this._rarity = value ;
// }
// private _cost : number
// get cost(): number {
// return this._cost;
// }
// set cost(value: number) {
// this._cost = value ;
// }
// private _attack : number
// get attack(): number {
// return this._attack;
// }
// set attack(value: number) {
// this._attack = value ;
// }
// private _health : number
// get health(): number {
// return this._health;
// }
// set health(value: number) {
// this._health = value ;
// }
// private _desc : string
// get desc(): string {
// return this._desc;
// }
// set desc(value: string) {
// this._desc = value ;
// }
// private _flavor : string
// get flavor(): string {
// return this._flavor;
// }
// set flavor(value: string) {
// this._flavor = value ;
// }
// private _artist : string
// get artist(): string {
// return this._artist;
// }
// set artist(value: string) {
// this._artist = value ;
// }
// private _collectible : boolean
// get collectible(): boolean {
// return this._collectible;
// }
// set collectible(value: boolean ){
// this._collectible = value;
// }
//IMG//
public img;
public imgGold;
// private _cropImg : string
// get cropImg(): string {
// return this._cropImg;
// }
// set cropImg(value: string) {
// this._cropImg = value;
// }
//IMGGOLD//
public imgGold;
//FAV//
public fav;
}

@ -1,37 +0,0 @@
export class CardSet {
constructor(id: number,name : string, type : string ) {
this._id = id
this._name =name
this._type = type
}
private _id : number
get id(): number {
return this._id
}
// NAME //
private _name : string;
get name(): string {
return this._name;
}
set name(value: string) {
this._name = value;
}
private _type : string;
get type(): string {
return this._type;
}
set type(value: string) {
this._type = value;
}
}

@ -1,4 +0,0 @@
export class Classe {
constructor(private id : number, private name : string) {
}
}

@ -1,5 +0,0 @@
export class Type{
constructor(private id : number, private name : string) {
}
}

@ -1,21 +0,0 @@
// import { NavigationContainer } from '@react-navigation/native';
// import { createStackNavigator } from '@react-navigation/stack';
// import HomeScreen from '../screens/HomeScreen';
// import ListScreen from '../screens/ListScreen';
// import ListFav from '../screens/ListFav';
// export default function ListNavigator() {
// const Stack = createStackNavigator();
// return (
// <Stack.Navigator initialRouteName="List">
// <Stack.Screen name="List" component={ListScreen}/>
// <Stack.Screen name="ListFav" component={ListFav}/>
// </Stack.Navigator>
// )
// }

@ -1,20 +1,13 @@
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, Button } from 'react-native';
import React, { useState } from "react";
import { NavigationContainer } from '@react-navigation/native';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import HomeScreen from '../screens/HomeScreen';
import ListScreen from '../screens/ListScreen';
import ListFav from '../screens/ListFav';
import TabBarIcon from '../components/TabBarIcon';
import StackNavigation from './StackNavigation';
export default function Navigation() {
const BottomTabNavigator = createBottomTabNavigator();
return (

@ -11,12 +11,10 @@ import ListFav from '../screens/ListFav';
export default function StackNavigation() {
const Stack = createStackNavigator();
return (
//<NavigationContainer>
<Stack.Navigator initialRouteName="Home">
<Stack.Screen name="Home" component={HomeScreen}/>
<Stack.Screen name="ListScreen" component={ListScreen}/>
<Stack.Screen name="ListFav" component={ListFav}/>
</Stack.Navigator>
//</NavigationContainer>
)
}

@ -1,75 +1,28 @@
import { setCardsList } from "./action_setCardsList";
import { Card } from "../../models/Card";
//! se fichier devra possiblement changer de dossier !!!
//! classe pour tester
// export class Card {
// cardId : String
// name : String
// manaCost : number
// attack : number
// health : number
// desc : String
// // constructor() {
// // this.cardId = "cardId";
// // this.name = "name";
// // this.manaCost = 0;
// // this.attack = 0;
// // this.health = 0;
// // this.desc = "desc";
// // }
// constructor(cardId : String, name : String, manaCost : number, attack : number, health : number, desc : String){
// this.cardId = cardId;
// this.name = name;
// this.manaCost = manaCost;ADD_FAVORITE_DATA, FETCH_DATA,
// this.attack = attack;
// this.health = health;
// this.desc = desc;
// }
// }
//Define your action creators that will be responsible for asynchronous operations
//Fonction chargé de l'appel à l'API
export const getAllCards = () => {
//In order to use await your callback must be asynchronous using async keyword.
console.log("getallcard")
//@ts-ignore
return async dispatch => {
//Then perform your asynchronous operations.
try {
//Have it first fetch data from our starwars url.
const options = {
method: 'GET',
// headers: {
// 'content-length':'9505',
// 'content-type':'application/json; charset=utf-8',
// 'etag':'W/"74bb-QMT8DIj6saBS1wT4u5WWcEmZAdw"'
// }ADD_FAVORITE_DATA, FETCH_DATA,
//! Actualisation de l'API (16/03) :
method: 'GET',
headers: {
'content-length': '9508',
'content-type': 'application/json; charset=utf-8',
'etag': 'W/"74bb-d4gMlMNks7UGES3Jmn6wzUTXaLI"',
}
//'pageSize':'100'
};
//! Actualisation de l'API (16/03) :
//! Actualisation de l'API (19/04) :
const CardsPromise = await fetch('https://us.api.blizzard.com/hearthstone/cards?locale=en_US&access_token=EUo8Snb09AfE3zQR4CoaB71gq1q3qvSmgL', options);
//const CardsPromise = await fetch('https://us.api.blizzard.com/hearthstone/cards?locale=en_US&access_token=EURTWhjBC2SRb4Ez42BT1kx8R2NcJc07kL', options);
//console.log("FETCH")
//console.log(CardsPromise)
//Then use the json method to get json data from api/
const CardsListJson = await CardsPromise.json();
//console.log(CardsListJson['cards'])
//@ts-ignore
@ -79,17 +32,13 @@ export const getAllCards = () => {
elt["imageGold"] ? elt["imageGold"] : "",
)); //, elt["cardSet"], elt["type"], elt["faction"], elt["rarity"], elt["cost"], elt["attack"], elt["health"],elt["text"], elt["flavor"], elt["artist"], elt["collectible"], elt["elite"], elt["race"], elt["img"], elt["imgGold"]
//elt["cardId"] == null ? elt["cardId"] : ""
//console.log("TOTO")
//console.log(CardsList)
//call the action
dispatch(setCardsList(CardsList));
} catch (error) {
console.log('Error---------', error);
//You can dispatch to another action if you want to display an error message in the application
//dispatch(fetchDataRejected(error))
}
}
}

@ -1,8 +1,5 @@
import {ADD_FAVORITE_DATA, FETCH_DATA} from '../constants';
//? Changer cette importe quand la classe sera definit dans un fichier correctement.
import {Card} from '../../models/Card'
import { Card } from '../../models/Card';
import {FETCH_DATA} from '../constants';
export const setCardsList = (List: Card[]) => {
return {
type: FETCH_DATA,

@ -1,6 +1,6 @@
import { Card } from '../../models/Card';
import { CardProps } from '../../props/favprops';
import {ADD_FAVORITE_DATA, FETCH_DATA} from '../constants';
import { CardProps } from '../../props/favProps';
import {ADD_FAVORITE_DATA} from '../constants';
export const setFavList = (props : CardProps) => {
return {

@ -1,10 +1,6 @@
export const FETCH_DATA = "FETCH_DATA"
export const ADD_FAVORITE_DATA = "ADD_FAVORITE_DATA"
export const DISPLAY_ALL_CARD = "DISPLAY_ALL_CARD"
export const SET_FAVS = "SET_FAVS"

@ -1,4 +1,4 @@
import { CardProps } from '../../props/favprops'
import { CardProps } from '../../props/favProps'
import {FETCH_DATA, ADD_FAVORITE_DATA, SET_FAVS} from '../constants'
import StorageHeart from '../../service/AsyncStorage'
@ -11,7 +11,7 @@ const initialState = {
// @ts-ignore
export default appReducer = (state = initialState, action) => {
switch (action.type) {
case ADD_FAVORITE_DATA:
case ADD_FAVORITE_DATA: //Ajout d'une carte aux favoris
const a : CardProps = action.payload
if(a.route.bool ==false){
@ -24,7 +24,6 @@ export default appReducer = (state = initialState, action) => {
//@ts-ignore
const tab = state.favoriteCards.concat([a.route.card])
console.log(state.favoriteCards)
StorageHeart.setItem("favoriteList",tab)
return {...state, favoriteCards : tab};
}
@ -35,11 +34,14 @@ export default appReducer = (state = initialState, action) => {
StorageHeart.setItem("favoriteList",tab)
return {...state, favoriteCards : tab };
}
case FETCH_DATA:
case FETCH_DATA: //Récupération des données des cartes depuis l'API
return {...state, cards: action.payload};
case SET_FAVS:
case SET_FAVS: //Récupération des favoris depuis l'async storage
//@ts-ignore
console.log("Set_favs : ",action.payload)
return {...state, favoriteCards: action.payload}
default:
return state;

@ -1,7 +1,6 @@
import {configureStore} from '@reduxjs/toolkit'
import appReducer from './reducers/appReducer';
// Reference here all your application reducers
const reducer = {
appReducer: appReducer,
}
@ -10,7 +9,6 @@ const reducer = {
const store = configureStore({
// @ts-ignore
reducer,
// @ts-ignore
middleware: (getDefaultMiddleware) => getDefaultMiddleware({serializableCheck : false}), //desactive le check de la serialization (primitif)
},);

@ -1,37 +1,22 @@
import { StyleSheet, Text, View, TouchableNativeFeedback, Image } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { NavigationContainer } from '@react-navigation/native';
import StackNavigation from '../navigation/StackNavigation'
import { Colors } from 'react-native/Libraries/NewAppScreen';
import { useDispatch } from 'react-redux';
import { useEffect } from 'react';
import { getAllCards } from "../redux/actions/actionSelection"
import StorageHeart from '../service/AsyncStorage';
import { setFavList } from '../redux/actions/action_setFavList';
import { setList } from '../redux/actions/action_setFavs';
import { Card } from '../models/Card';
//import { setList } from '../redux/actions/action_setList';
import Navigation from '../navigation/Navigation';
// @ts-ignore //
export default function HomeScreen({navigation}) {
const dispatch = useDispatch();
//chargement des listes
useEffect(() => {
console.log("USEEFFECT")
const loadFavCards = async () => {
//@ts-ignore
//await dispatch(getAllCards());
const list = await StorageHeart.getItem("favoriteList")
console.log("async favs : ",list)
//@ts-ignore
dispatch(setList(list))
@ -39,7 +24,7 @@ export default function HomeScreen({navigation}) {
loadFavCards();
}, [dispatch]);
useEffect(() => {
console.log("USEEFFECT")
const loadCards = async () => {
//@ts-ignore
await dispatch(getAllCards());
@ -47,10 +32,10 @@ export default function HomeScreen({navigation}) {
loadCards();
}, [dispatch]);
const tabNav = Navigation()
// affichage de la homePage
return (
<View style={styles.container}>
<View style={styles.centered}>
@ -64,7 +49,7 @@ export default function HomeScreen({navigation}) {
<View style={styles.butContain}>
<TouchableNativeFeedback onPress={() => navigation.navigate("ListScreen")}>
<TouchableNativeFeedback onPress={() => navigation.navigate("ListScreen")}>
<Text style={styles.ButtonStyle}>List</Text>
</TouchableNativeFeedback>
@ -107,10 +92,10 @@ export default function HomeScreen({navigation}) {
},
ButtonStyle :{
backgroundColor: "#2E8AE6",
backgroundColor: "#F5F5F5",
borderRadius: 15,
padding: 20,
color: "white",
color: "black",
fontSize : 36,
width: "45%",
textAlign: 'center',

@ -1,25 +1,12 @@
import { StyleSheet, Text, View, Button, TouchableHighlight, TextInput, ImageBackground } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from "react";
import { StyleSheet, View, TouchableHighlight, TextInput } from 'react-native';
import React, { useState} from "react";
import { FlatList } from 'react-native-gesture-handler';
import {useDispatch, useSelector} from 'react-redux';
import { FontAwesome } from '@expo/vector-icons';
import { ThunkAction } from 'redux-thunk';
import {useSelector} from 'react-redux';
//? possiblement à supprimer
import { getAllCards } from "../redux/actions/actionSelection"
import { Card } from '../models/Card';
import { Image } from 'react-native';
import { ImageURISource } from 'react-native';
import Item from '../components/ListItemComponent';
//* Icons
// import { BiSearchAlt } from 'react-icons';
//* Components
@ -28,7 +15,6 @@ export default function ListScreen({navigation}){
//@ts-ignore
var nList : Card[] = useSelector(state => state.appReducer.favoriteCards);
console.log(" favs : ",nList)
const [searchValue, setSearchValue] = useState('');

@ -1,49 +1,19 @@
import { StyleSheet, Text, View, Button, TouchableHighlight, TextInput, ImageBackground, LogBox } from 'react-native';
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from "react";
import { StyleSheet,View,TouchableHighlight, TextInput} from 'react-native';
import React, { useState} from "react";
import { FlatList } from 'react-native-gesture-handler';
import {useDispatch, useSelector} from 'react-redux';
import { FontAwesome } from '@expo/vector-icons';
import { ThunkAction } from 'redux-thunk';
//? possiblement à supprimer
import { getAllCards } from "../redux/actions/actionSelection"
import {useSelector} from 'react-redux';
import { Card } from '../models/Card';
import { Image } from 'react-native';
import { ImageURISource } from 'react-native';
//* Icons
// import { BiSearchAlt } from 'react-icons';
//* Components
import { setFavList } from '../redux/actions/action_setFavList';
import Item from '../components/ListItemComponent';
//@ts-ignore
export default function ListScreen({navigation}){
const [count, setCount] = useState(0);
// // Initialize the binding content with the application initial state
//@ts-ignore
var nList = useSelector(state => state.appReducer.cards);
// Create a const that will hold the react-redux events dispatcher
const dispatch = useDispatch();
// Let's define a hook that will be used to update the rendered state after the return will be called
// You cannot perform side-effects outside of a useEffect hook
// useEffect(() => {
// console.log("USEEFFECT")
// const loadCards = async () => {
// //@ts-ignore
// await dispatch(getAllCards());
// };
// loadCards();
// }, [dispatch]);
//* Search :
const [searchValue, setSearchValue] = useState('');

@ -7,7 +7,7 @@ export default class StorageHeart {
static async getItem(key: string): Promise<any> {
try {
const value = await AsyncStorage.getItem(key);
console.log("load")
if (value !== null) {
return JSON.parse(value);
}
@ -20,7 +20,7 @@ export default class StorageHeart {
static async setItem(key: string, value: any): Promise<void> {
try {
await AsyncStorage.setItem(key, JSON.stringify(value));
console.log("save")
} catch (e) {
console.error(`AsyncStorage setItem error: ${e}`);
}

Loading…
Cancel
Save