Fakultas Ilmu Komputer UI

Commit 5694c238 authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

refactor: move getCategories function

parent d33d65b8
Pipeline #86127 passed with stage
in 9 minutes and 4 seconds
import { FlatList, SafeAreaView, StyleSheet } from "react-native"; import { FlatList, SafeAreaView, StyleSheet } from "react-native";
import React, { useState } from "react"; import React, { useState } from "react";
import HorizontalCards from "../components/Cards/HorizontalCards"; import HorizontalCards from "../components/Cards/HorizontalCards";
import { useNavigation } from "@react-navigation/core"; // import { useNavigation } from "@react-navigation/core";
import Colors from "../constants/Colors"; import Colors from "../constants/Colors";
import { View } from "../components/Themed"; import { View } from "../components/Themed";
import Spacer from "../components/Spacer/Spacer"; import Spacer from "../components/Spacer/Spacer";
import { IEcosystem } from "../types/firestore/ecosystems"; // import { IEcosystem } from "../types/firestore/ecosystems";
import IconForm from "../components/Forms/IconForm"; import IconForm from "../components/Forms/IconForm";
const CategoryEcosystemListScreen = () => { const CategoryEcosystemListScreen = () => {
const nav = useNavigation(); // const nav = useNavigation();
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const [listData, setListData] = useState([ const [
listData,
// setListData
] = useState([
{ {
id: "1", id: "1",
image: image:
......
import { FlatList, SafeAreaView, StyleSheet } from "react-native"; import { FlatList, SafeAreaView, StyleSheet } from "react-native";
import React, { useState } from "react"; import React, { useState } from "react";
import HorizontalCards from "../components/Cards/HorizontalCards"; import HorizontalCards from "../components/Cards/HorizontalCards";
import { useNavigation } from "@react-navigation/core"; // import { useNavigation } from "@react-navigation/core";
import Colors from "../constants/Colors"; import Colors from "../constants/Colors";
import { View } from "../components/Themed"; import { View } from "../components/Themed";
import Spacer from "../components/Spacer/Spacer"; import Spacer from "../components/Spacer/Spacer";
import { IEcosystem } from "../types/firestore/ecosystems"; // import { IEcosystem } from "../types/firestore/ecosystems";
import { IEcosystemList } from "../types/ecosystemList"; // import { IEcosystemList } from "../types/ecosystemList";
const EcosystemListScreen = () => { const EcosystemListScreen = () => {
const nav = useNavigation(); // const nav = useNavigation();
const [listData, setListData] = useState([ const [
listData,
// setListData
] = useState([
{ {
id: "1", id: "1",
image: image:
......
...@@ -23,6 +23,8 @@ const RegisterScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => { ...@@ -23,6 +23,8 @@ const RegisterScreen = ({ navigation }: RootTabScreenProps<"TabOne">) => {
const [password, setPassword] = useState(""); const [password, setPassword] = useState("");
const [phoneNo, setPhoneNo] = useState(""); const [phoneNo, setPhoneNo] = useState("");
const [picked, setPicked] = useState(""); const [picked, setPicked] = useState("");
// TODO: Use getCategories firestore function to fetch categories
const [categories, setCategories] = useState([ const [categories, setCategories] = useState([
{ label: "Agrikultur", value: "B" }, { label: "Agrikultur", value: "B" },
{ label: "Pertanian", value: "D" }, { label: "Pertanian", value: "D" },
......
import firebase from "firebase"; import firebase from "firebase";
import { ICategory } from "../types/firestore"; import { ICategory } from "../../types/firestore";
export const getCategories = async (): Promise<ICategory[]> => { export const getCategories = async (): Promise<ICategory[]> => {
const db = firebase.firestore(); const db = firebase.firestore();
...@@ -8,7 +8,7 @@ export const getCategories = async (): Promise<ICategory[]> => { ...@@ -8,7 +8,7 @@ export const getCategories = async (): Promise<ICategory[]> => {
const categories: ICategory[] = []; const categories: ICategory[] = [];
snap.docs.forEach((doc) => { snap.docs.forEach((doc) => {
const data: ICategory = { ...(doc.data() as ICategory), id: doc.id }; const data: ICategory = { ...(doc.data() as ICategory), id: doc.id };
categories.push({ name: data.name, id: doc.id }); categories.push(data);
}); });
return categories; return categories;
}; };
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment