|
|
@ -14,10 +14,16 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
|
|
export default function FiltersSelection(props) {
|
|
|
|
export default function FiltersSelection(props) {
|
|
|
|
const {colors} = useContext(ColorContext);
|
|
|
|
const {colors} = useContext(ColorContext);
|
|
|
|
const profilesHand = [
|
|
|
|
const profilesHand = [
|
|
|
|
{name: "None", avatar: "logo.png", isActive: "none", isWaiting: "none"},
|
|
|
|
{name: "None", avatar: "logo.png", diets: [], allergies: [], isActive: "none", isWaiting: "none"},
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
|
|
|
|
|
|
|
|
|
|
|
|
const [profiles, setProfiles] = useState(profilesHand);
|
|
|
|
const [profiles, setProfiles] = useState(profilesHand);
|
|
|
|
|
|
|
|
const [dieProfiles, setDieProfiles] = useState([])
|
|
|
|
|
|
|
|
const [allProfiles, setAllProfiles] = useState([])
|
|
|
|
|
|
|
|
const [dieAdd, setDieAdd] = useState([])
|
|
|
|
|
|
|
|
const [allAdd, setAllAdd] = useState([])
|
|
|
|
|
|
|
|
const [selectedDiets, setSelectedDiets] = useState([]);
|
|
|
|
|
|
|
|
|
|
|
|
const handleGetProfiles = async () => {
|
|
|
|
const handleGetProfiles = async () => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -30,16 +36,22 @@ export default function FiltersSelection(props) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const fetchProfiles = async () => {
|
|
|
|
const fetchProfiles = async () => {
|
|
|
|
const existingProfiles = await handleGetProfiles();
|
|
|
|
const existingProfiles = await handleGetProfiles()
|
|
|
|
setProfiles(existingProfiles);
|
|
|
|
setProfiles(existingProfiles)
|
|
|
|
|
|
|
|
console.log("FetchProfiles:",profiles)
|
|
|
|
|
|
|
|
console.log("FetchProfiles const:",existingProfiles)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const subscription = EventEmitter.addListener('profileAdded', async () => {
|
|
|
|
const subscription = EventEmitter.addListener('profileAdded', async () => {
|
|
|
|
fetchProfiles();
|
|
|
|
fetchProfiles()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
fetchProfiles();
|
|
|
|
fetchProfiles()
|
|
|
|
|
|
|
|
console.log("UseEffect:",profiles)
|
|
|
|
|
|
|
|
updateDiets()
|
|
|
|
|
|
|
|
setDieAdd(die.filter(isInProfileDiets))
|
|
|
|
|
|
|
|
updateAllergies()
|
|
|
|
}, []);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const handleSaveSelectedProfiles = async () => {
|
|
|
|
const handleSaveSelectedProfiles = async () => {
|
|
|
@ -57,16 +69,48 @@ export default function FiltersSelection(props) {
|
|
|
|
})
|
|
|
|
})
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(profiles));
|
|
|
|
await AsyncStorage.setItem('profiles', JSON.stringify(profiles));
|
|
|
|
EventEmitter.emit('selectedProfilesUpdated');
|
|
|
|
EventEmitter.emit('selectedProfilesUpdated');
|
|
|
|
fetchProfiles();
|
|
|
|
updateDiets()
|
|
|
|
|
|
|
|
setDieAdd(die.filter(isInProfileDiets))
|
|
|
|
|
|
|
|
updateAllergies()
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Error occured when updating active profiles:', error);
|
|
|
|
console.error('Error occured when updating active profiles:', error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const subscriptionUpdateSelectedProfiles = EventEmitter.addListener('selectedProfilesUpdated', async () => {
|
|
|
|
const subscriptionUpdateSelectedProfiles = EventEmitter.addListener('selectedProfilesUpdated', async () => {
|
|
|
|
fetchProfiles();
|
|
|
|
fetchProfiles()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateDiets = () => {
|
|
|
|
|
|
|
|
let dieTemp = []
|
|
|
|
|
|
|
|
let retType = true
|
|
|
|
|
|
|
|
profiles.forEach((profile) => {
|
|
|
|
|
|
|
|
if(profile.isActive == "flex"){
|
|
|
|
|
|
|
|
profile.diets.forEach((diet) => {
|
|
|
|
|
|
|
|
console.log("Diet:",diet)
|
|
|
|
|
|
|
|
retType = true
|
|
|
|
|
|
|
|
dieTemp.forEach((val) => {
|
|
|
|
|
|
|
|
if(val.value == diet.value){
|
|
|
|
|
|
|
|
retType = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
if(retType){
|
|
|
|
|
|
|
|
dieTemp.push({value: diet})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log("========================================")
|
|
|
|
|
|
|
|
console.log("DieTemp:",dieTemp)
|
|
|
|
|
|
|
|
setDieProfiles(dieTemp)
|
|
|
|
|
|
|
|
console.log("DieProfiles:",dieProfiles)
|
|
|
|
|
|
|
|
console.log("========================================")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateAllergies = () => {
|
|
|
|
|
|
|
|
setAllAdd([])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const changeStatusWaiting = (cpt) => {
|
|
|
|
const changeStatusWaiting = (cpt) => {
|
|
|
|
if(profiles[cpt].isWaiting == "none"){
|
|
|
|
if(profiles[cpt].isWaiting == "none"){
|
|
|
|
profiles[cpt].isWaiting = "flex"
|
|
|
|
profiles[cpt].isWaiting = "flex"
|
|
|
@ -106,28 +150,19 @@ export default function FiltersSelection(props) {
|
|
|
|
updateCptActive()
|
|
|
|
updateCptActive()
|
|
|
|
updateCptWaiting()
|
|
|
|
updateCptWaiting()
|
|
|
|
|
|
|
|
|
|
|
|
const die = [{value: "Dairy free"}, {value: "Gluten free"}, {value: "Porkless"}, {value: "Vegan"}, {value: "Vegetarian"}, {value: "Pescatarian"}]
|
|
|
|
function isInProfileDiets(element) {
|
|
|
|
|
|
|
|
let retType = true
|
|
|
|
const allProfiles = [{value: "Skimmed Milk"}, {value: "Nuts"}]
|
|
|
|
dieProfiles.forEach(function (diet) {
|
|
|
|
const dieProfiles = [{value: "Porkless"}, {value: "Pescatarian"}]
|
|
|
|
if(diet.value==element.value){
|
|
|
|
|
|
|
|
retType = false
|
|
|
|
function isInProfileDiets(element, index, array) {
|
|
|
|
}
|
|
|
|
let retType = true
|
|
|
|
})
|
|
|
|
dieProfiles.forEach(function (diets) {
|
|
|
|
return retType
|
|
|
|
if(diets.value==element.value){
|
|
|
|
}
|
|
|
|
retType = false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
return retType
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const dieAdd = die.filter(isInProfileDiets);
|
|
|
|
|
|
|
|
const allAdd = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [selectedDiets, setSelectedDiets] = useState([]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleSelectedDiets = (selectedValues) => {
|
|
|
|
const handleSelectedDiets = (selectedValues) => {
|
|
|
|
setSelectedDiets(selectedValues);
|
|
|
|
setSelectedDiets(selectedValues);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
container: {
|
|
|
|