Advertisement
vandasche

Untitled

Dec 14th, 2020
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. import React, { useEffect, useState } from "react";
  2. import {
  3. StyleSheet,
  4. StatusBar,
  5. SafeAreaView,
  6. ScrollView,
  7. View,
  8. Platform,
  9. Dimensions,
  10. } from "react-native";
  11. import { connect, useSelector, useDispatch } from "react-redux";
  12. import { Actions } from "react-native-router-flux";
  13. import { ModalBox, Button } from "../common";
  14. import { TeaserCard } from "../cards";
  15. import { LinearGradient } from "expo-linear-gradient";
  16. import * as actUser from "../Actions";
  17. import { API_URL } from "react-native-dotenv";
  18. import { getTalentByTag } from "../Actions";
  19.  
  20. console.disableYellowBox = true;
  21.  
  22. const { height } = Dimensions.get("window");
  23. const styles = StyleSheet.create({
  24. containerStyle: { flex: 1, backgroundColor: "#000", position: "relative" },
  25. wrapperStyle: {
  26. position: "absolute",
  27. top: 0,
  28. left: 0,
  29. width: "100%",
  30. ...Platform.select({
  31. ios: { height: height, paddingTop: 140 },
  32. android: { height: "100%", paddingTop: 120 },
  33. }),
  34. },
  35. scrollerWrapper: {
  36. flexDirection: "row",
  37. justifyContent: "space-around",
  38. flexWrap: "wrap",
  39. padding: 10,
  40. },
  41. btnContainer: { width: "100%", padding: 10, alignSelf: "flex-end" },
  42. btnStyle: {
  43. justifyContent: "center",
  44. alignSelf: "center",
  45. borderRadius: 30,
  46. height: 40,
  47. marginHorizontal: 10,
  48. backgroundColor: "#00D3FD",
  49. width: "100%",
  50. ...Platform.select({
  51. android: { paddingBottom: 2 },
  52. }),
  53. },
  54. btnTextStyle: {
  55. fontFamily: "Montserrat-Bold",
  56. fontSize: 15,
  57. textAlign: "center",
  58. color: "#FFF",
  59. },
  60. });
  61.  
  62. const Home = (props) => {
  63. const fetchPage = 1;
  64. const options = {
  65. method: "GET",
  66. headers: {
  67. Accept: "application/json",
  68. "Content-Type": "application/x-www-form-urlencoded;",
  69. },
  70. };
  71. const [profile, setProfile] = useState(false);
  72. const [actorTalent, setActorTalent] = useState("");
  73. const [modalMessage, setModalMessage] = useState("");
  74. const [showModal, setShowModal] = useState(false);
  75. const [comedyTalent, setComedyTalent] = useState("");
  76. const [singerTalent, setSingerTalent] = useState("");
  77. const [movieTalent, setMovieTalent] = useState("");
  78. const [influencer, setInfluencer] = useState("");
  79. const [chefTalent, setChefTalent] = useState("");
  80. const [tvPresenter, setTvPresenter] = useState("");
  81. const [radioHost, setRadioHost] = useState("");
  82. const [modelTalent, setModelTalent] = useState("");
  83. const [athleteTalent, setAthleteTalent] = useState("");
  84.  
  85. useEffect(() => {
  86. props.dispatch(actUser.getTalent({ page: fetchPage, total: 8 }));
  87. props.dispatch(actUser.getNewestTalent({ page: fetchPage, total: 2 }));
  88. fetchData();
  89. }, [fetchPage]);
  90.  
  91. // const fetchActor = async () => {
  92. // const url = `${API_URL}/get/search?tag=1&page=1&size=2&sort=-created_at`;
  93. // const res = await fetch(url, options);
  94. // const data = await res.json();
  95. // setActorTalent(data.content);
  96. // };
  97.  
  98. // const fetchComedy = async () => {
  99. // const url = `${API_URL}/get/search?tag=2&page=1&size=2&sort=-created_at`;
  100. // const res = await fetch(url, options);
  101. // const data = await res.json();
  102. // setComedyTalent(data.content);
  103. // };
  104.  
  105. // const fetchSinger = async () => {
  106. // const url = `${API_URL}/get/search?tag=3&page=1&size=2&sort=-created_at`;
  107. // const res = await fetch(url, options);
  108. // const data = await res.json();
  109. // setSingerTalent(data.content);
  110. // };
  111.  
  112. const fetchData = async () => {
  113. const url = `${API_URL}/get/tags`;
  114. const res = await fetch(url);
  115. const categories = await res.json();
  116. console.log(categories, "categories");
  117. categories.map(async (data) => {
  118. const url = `${API_URL}/get/search?tag=${data.id}&page=1&size=2&sort=-created_at`;
  119. const res = await fetch(url, options);
  120. const content = await res.json();
  121. data.push(content);
  122. });
  123. console.log(categories, "categories after");
  124. };
  125.  
  126. const toggleModal = () => {
  127. setShowModal(!showModal);
  128. };
  129.  
  130. const featured =
  131. props.talent_list && props.talent_list.length > 2
  132. ? props.talent_list.slice(0, 2)
  133. : props.talent_list;
  134.  
  135. //debug
  136.  
  137. console.log("debug");
  138.  
  139. //end debug
  140.  
  141. return (
  142. <SafeAreaView style={styles.containerStyle}>
  143. <StatusBar
  144. backgroundColor="#000"
  145. barStyle="light-content"
  146. translucent={false}
  147. hidden={false}
  148. />
  149. <View style={[styles.wrapperStyle, { paddingBottom: profile ? 55 : 0 }]}>
  150. <ScrollView contentContainerStyle={styles.scrollerWrapper}>
  151. <TeaserCard
  152. title="Featured"
  153. onPress={() => Actions.Featured()}
  154. user={profile}
  155. listData={featured}
  156. />
  157.  
  158. {!profile ? (
  159. <View style={styles.btnContainer}>
  160. <LinearGradient
  161. colors={["#1B99B3", "#622dff"]}
  162. style={styles.btnStyle}
  163. >
  164. <Button
  165. // containerStyle={styles.btnStyle}
  166. textStyle={styles.btnTextStyle}
  167. onPress={() => Actions.Login()}
  168. title={`SIGN IN`}
  169. />
  170. </LinearGradient>
  171. </View>
  172. ) : null}
  173.  
  174. <TeaserCard
  175. title="Newest"
  176. user={profile}
  177. listData={props.new_talent_list}
  178. />
  179. {/* {actorTalent.length !== 0 && (
  180. <TeaserCard
  181. title="Actor"
  182. user={profile}
  183. listData={actorTalent}
  184. onPress={() => Actions.Search({ keywords: "actor" })}
  185. />
  186. )}
  187. {comedyTalent.length !== 0 && (
  188. <TeaserCard
  189. title="Comedian"
  190. user={profile}
  191. listData={comedyTalent}
  192. onPress={() => Actions.Search({ keywords: "comedian" })}
  193. />
  194. )}
  195. {singerTalent.length !== 0 && (
  196. <TeaserCard
  197. title="Singer"
  198. user={profile}
  199. listData={singerTalent}
  200. onPress={() => Actions.Search({ keywords: "singer" })}
  201. />
  202. )}
  203. {movieTalent.length !== 0 && (
  204. <TeaserCard
  205. title="Movie Star"
  206. user={profile}
  207. listData={movieTalent}
  208. onPress={() => Actions.Search({ keywords: "Movie Star" })}
  209. />
  210. )}
  211. {influencer.length !== 0 && (
  212. <TeaserCard
  213. title="Influencer"
  214. user={profile}
  215. listData={influencer}
  216. onPress={() => Actions.Search({ keywords: "Influencer" })}
  217. />
  218. )} */}
  219. </ScrollView>
  220. </View>
  221. <ModalBox
  222. infoText={modalMessage}
  223. closeModal={toggleModal}
  224. show={showModal}
  225. />
  226. </SafeAreaView>
  227. );
  228. };
  229.  
  230. const mapStateToProps = (state) => {
  231. return {
  232. talent_list: state.talent_list,
  233. new_talent_list: state.new_talent_list,
  234. tagged_list: state.tagged_list,
  235. };
  236. };
  237.  
  238. export default connect(mapStateToProps)(Home);
  239.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement