import { useQuery } from "@apollo/react-hooks";
import { useNavigation } from "@react-navigation/native";
import gql from "graphql-tag";
import React, { useContext, useLayoutEffect } from "react";
import { FlatList, View } from "react-native";
import { categories } from "../../apollo/server";
import EmptyFood from "../../assets/images/SVG/imageComponents/EmptyFood";
import {
MenuCard,
Spinner,
StatusCard,
TextDefault,
TextError,
WrapperView,
} from "../../components";
import UserContext from "../../context/User";
import { alignment } from "../../utils/alignment";
import { NAVIGATION_SCREEN } from "../../utils/constant";
import { scale } from "../../utils/scaling";
import useStyle from "./styles";
// constants
const CATEGORIES = gql`
${categories}
`;
function Menu() {
const styles = useStyle();
const navigation = useNavigation();
const { isLoggedIn, profile } = useContext(UserContext);
const { data, refetch, networkStatus, loading, error } = useQuery(CATEGORIES);
useLayoutEffect(() => {
navigation.setOptions({
title: "Home",
});
}, []);
function emptyView() {
if (loading) {
return ;
} else if (error) {
return (
);
} else {
return (
No item found
);
}
}
return (
String(index)}
ListEmptyComponent={emptyView()}
data={loading ? [] : error ? [] : data.categories}
refreshing={networkStatus === 4}
onRefresh={() => refetch()}
ListHeaderComponent={() => {
if (!error && !loading) {
return (
<>
{isLoggedIn && profile && }
Featured
>
);
}
return null;
}}
renderItem={({ item }) => (
navigation.navigate(NAVIGATION_SCREEN.MenuItems, {
...item,
})
}
title={item.title}
description={item.description}
image={item.img_menu || ""}
/>
)}
/>
);
}
export default React.memo(Menu);