Fakultas Ilmu Komputer UI

Commit 8a8ad18e authored by Ahmad Izzudin Alifyandra's avatar Ahmad Izzudin Alifyandra
Browse files

Merge branch 'recommended-ecosystem-screen' into 'master'

feat: Recommended ecosystem screen

See merge request !97
parents 835b0841 58e370ad
Pipeline #86265 passed with stage
in 10 minutes and 43 seconds
import React, { useEffect } from "react";
import { StyleSheet } from "react-native";
import { Text, View } from "../../components/Themed";
import React, { useEffect, useState } from "react";
import { StyleSheet, FlatList, ListRenderItem } from "react-native";
import { View } from "../../components/Themed";
import Colors from "../../constants/Colors";
import { EcosystemStackScreenProps } from "../../types/navigation";
import { LogBox } from "react-native";
import ecosystemService from "../../service/firestore/ecosystem";
import { useSelector } from "react-redux";
import { IUser } from "../../types/firestore/User";
import { RootState } from "../../redux/store";
import { IEcosystem } from "../../types/firestore/ecosystems";
import HorizontalCards from "../../components/Cards/HorizontalCards";
import { useNavigation } from "@react-navigation/core";
const RecommendedEcosystemScreen = ({
route,
}: EcosystemStackScreenProps<"Recommended">) => {
const { toFetch } = route.params;
const nav = useNavigation();
const [ecosystems, setEcosystems] = useState([]);
const user: IUser = useSelector((state: RootState) => state.user);
const userId = user.id;
useEffect(() => {
switch (toFetch) {
case "popular":
(async () => {
setEcosystems(await ecosystemService.getByPopularity());
})();
break;
case "myEcosystem":
(async () => {
setEcosystems(await ecosystemService.getByCreated(userId));
})();
break;
case "mostRecent":
(async () => {
setEcosystems(await ecosystemService.getByMostRecent());
})();
break;
case "joined":
(async () => {
setEcosystems(await ecosystemService.getByFollowed(userId));
})();
break;
default:
break;
}
}, []);
LogBox.ignoreLogs([
"Non-serializable values were found in the navigation state",
]);
const renderItem: ListRenderItem<IEcosystem> = ({ item }) => (
<View>
<HorizontalCards
title={item.name}
image={item.pic}
member={item.followerCount.toString()}
onPress={() => {
nav.navigate("Ecosystem", {
screen: "EcosystemDetails",
params: {
headerTitle: item.name,
title: item.name,
desc: item.description,
image: item.pic,
member: item.followerCount.toString(),
rating: item.rating.toString(),
},
});
}}
rate={item.rating.toString()}
/>
</View>
);
return (
<View style={styles.container}>
<View>
<Text>Layar Rekomendasi Ekosistem</Text>
{ecosystems && <FlatList data={ecosystems} renderItem={renderItem} />}
</View>
</View>
);
......
Supports Markdown
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