Advertisement
vandasche

Untitled

Dec 10th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 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 { getTalent, getNewestTalent, resetGetTalentByTag } from "../Actions";
  16. import { LinearGradient } from "expo-linear-gradient";
  17.  
  18. console.disableYellowBox = true;
  19.  
  20. const { height } = Dimensions.get("window");
  21. const styles = StyleSheet.create({
  22. containerStyle: { flex: 1, backgroundColor: "#000", position: "relative" },
  23. wrapperStyle: {
  24. position: "absolute",
  25. top: 0,
  26. left: 0,
  27. width: "100%",
  28. ...Platform.select({
  29. ios: { height: height, paddingTop: 140 },
  30. android: { height: "100%", paddingTop: 120 },
  31. }),
  32. },
  33. scrollerWrapper: {
  34. flexDirection: "row",
  35. justifyContent: "space-around",
  36. flexWrap: "wrap",
  37. padding: 10,
  38. },
  39. btnContainer: { width: "100%", padding: 10, alignSelf: "flex-end" },
  40. btnStyle: {
  41. justifyContent: "center",
  42. alignSelf: "center",
  43. borderRadius: 30,
  44. height: 40,
  45. marginHorizontal: 10,
  46. backgroundColor: "#00D3FD",
  47. width: "100%",
  48. ...Platform.select({
  49. android: { paddingBottom: 2 },
  50. }),
  51. },
  52. btnTextStyle: {
  53. fontFamily: "Montserrat-Bold",
  54. fontSize: 15,
  55. textAlign: "center",
  56. color: "#FFF",
  57. },
  58. });
  59.  
  60. const Home = (props) => {
  61. const fetchPage = 1;
  62. const fetchTotal = 8;
  63. const fetchTotalNewest = 4;
  64.  
  65. const [profile, setProfile] = useState(false);
  66. const [newestTalent, setNewestTalent] = useState("");
  67. const [modalMessage, setModalMessage] = useState("");
  68. const [showModal, setShowModal] = useState(false);
  69.  
  70. //redux state
  71. // const listTalent = useSelector((state) => state.talent_list);
  72. console.log(props, "props");
  73. //redux action
  74. const dispatch = useDispatch();
  75. const getTalent = (data) => dispatch(getTalent(data));
  76.  
  77. useEffect(() => {
  78. if (!props.talent_list) {
  79. fetchData();
  80. }
  81. }, []);
  82.  
  83. const fetchData = async () => {
  84. const payload = {
  85. page: fetchPage,
  86. total: fetchTotal,
  87. };
  88. getTalent(payload);
  89. };
  90.  
  91. const toggleModal = () => {
  92. setShowModal(!showModal);
  93. };
  94.  
  95. // const featured =
  96. // listTalent && listTalent.length > 2 ? listTalent.slice(0, 2) : listTalent;
  97. // console.log(listTalent, "listTalent");
  98. return (
  99. <SafeAreaView style={styles.containerStyle}>
  100. <StatusBar
  101. backgroundColor="#000"
  102. barStyle="light-content"
  103. translucent={false}
  104. hidden={false}
  105. />
  106. <View style={[styles.wrapperStyle, { paddingBottom: profile ? 55 : 0 }]}>
  107. <ScrollView contentContainerStyle={styles.scrollerWrapper}>
  108. <TeaserCard
  109. title="Featured"
  110. onPress={() => Actions.Featured()}
  111. user={profile}
  112. // listData={talent_list}
  113. />
  114.  
  115. {!profile ? (
  116. <View style={styles.btnContainer}>
  117. <LinearGradient
  118. colors={["#1B99B3", "#622dff"]}
  119. style={styles.btnStyle}
  120. >
  121. <Button
  122. // containerStyle={styles.btnStyle}
  123. textStyle={styles.btnTextStyle}
  124. onPress={() => Actions.Login()}
  125. title={`SIGN IN`}
  126. />
  127. </LinearGradient>
  128. </View>
  129. ) : null}
  130.  
  131. <TeaserCard title="Newest" user={profile} listData={newestTalent} />
  132. </ScrollView>
  133. </View>
  134. <ModalBox
  135. infoText={modalMessage}
  136. closeModal={toggleModal}
  137. show={showModal}
  138. />
  139. </SafeAreaView>
  140. );
  141. };
  142.  
  143. const mapStateToProps = (state) => {
  144. return {
  145. talent_list: state.talent_list,
  146. };
  147. };
  148.  
  149. export default connect(mapStateToProps)(Home);
  150.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement