AutomaticScreen.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import * as React from "react";
  2. import {
  3. Text,
  4. Layout,
  5. Button,
  6. } from "@ui-kitten/components";
  7. import {
  8. StyleSheet,
  9. View,
  10. } from "react-native";
  11. import { useModel } from "flooks";
  12. import Textarea from "react-native-textarea";
  13. import ScrollPage from "../../components/ScrollPage";
  14. import NavHeaderBar from "../../components/NavHeaderBar";
  15. const styles = StyleSheet.create({
  16. lay: {
  17. paddingHorizontal: 15,
  18. paddingVertical: 20,
  19. marginTop: 10,
  20. },
  21. top: {
  22. paddingVertical: 20,
  23. paddingHorizontal: 13,
  24. },
  25. imgList: {
  26. flexDirection: "row",
  27. },
  28. upload: {
  29. marginRight: 10,
  30. width: 67,
  31. flexShrink: 0,
  32. },
  33. textareaContainer: {
  34. backgroundColor: "#F0F0F0",
  35. height: 100,
  36. alignSelf: "stretch",
  37. borderRadius: 4,
  38. },
  39. textarea: {
  40. textAlignVertical: "top", // hack android
  41. fontSize: 13,
  42. color: "#333",
  43. paddingHorizontal: 14,
  44. paddingVertical: 10,
  45. height: 100,
  46. },
  47. text: {
  48. paddingBottom: 10,
  49. },
  50. button: {
  51. alignSelf: "flex-end",
  52. marginTop: 10,
  53. marginRight: 14,
  54. },
  55. menu: {
  56. borderColor: "#EEEEEE",
  57. borderTopWidth: 6,
  58. backgroundColor: "#fff",
  59. paddingHorizontal: 15,
  60. },
  61. menuItem: {},
  62. buttonGroup: {
  63. justifyContent: "space-around",
  64. paddingVertical: 20,
  65. flexDirection: "row",
  66. },
  67. });
  68. export default function AutomaticScreen({ navigation }) {
  69. const { httpPost, httpGet } = useModel("httpModel", true);
  70. const { userId } = useModel("userModel");
  71. const { success } = useModel("loadingModel");
  72. const {
  73. automaticText1,
  74. automaticText2,
  75. automaticText3,
  76. automaticText4,
  77. save,
  78. cancel,
  79. successText,
  80. } = useModel("wordsModel");
  81. const [goodContent, setGoodContent] = React.useState("");
  82. const [badContent, setBadContent] = React.useState("");
  83. const [id, setId] = React.useState("");
  84. function refreshEvent() {
  85. return httpGet("/automaticResponse/my").then(res => {
  86. if (res) {
  87. setGoodContent(res.goodContent || "");
  88. setBadContent(res.badContent || "");
  89. setId(res.id || "");
  90. }
  91. });
  92. }
  93. function submit() {
  94. httpPost(
  95. "/automaticResponse/save",
  96. {
  97. id,
  98. userId,
  99. goodContent,
  100. badContent,
  101. },
  102. { body: "json" },
  103. true
  104. ).then(() => {
  105. success(save + successText);
  106. navigation.goBack();
  107. });
  108. }
  109. const canSub = React.useMemo(() => {
  110. if (goodContent || badContent) {
  111. return true;
  112. }
  113. return false;
  114. }, [goodContent, badContent]);
  115. return (
  116. <>
  117. <NavHeaderBar title={automaticText1} />
  118. <ScrollPage
  119. enabledFresh
  120. refreshEvent={refreshEvent}
  121. statusType='primary'
  122. >
  123. <Layout style={styles.lay}>
  124. <Text style={styles.text}>{automaticText2}</Text>
  125. <Textarea
  126. containerStyle={styles.textareaContainer}
  127. style={styles.textarea}
  128. onChangeText={setGoodContent}
  129. value={goodContent}
  130. maxLength={100}
  131. placeholder={automaticText4}
  132. placeholderTextColor="#B4B4B4"
  133. underlineColorAndroid="transparent"
  134. />
  135. </Layout>
  136. <Layout style={styles.lay}>
  137. <Text style={styles.text}>{automaticText3}</Text>
  138. <Textarea
  139. containerStyle={styles.textareaContainer}
  140. style={styles.textarea}
  141. onChangeText={setBadContent}
  142. value={badContent}
  143. maxLength={100}
  144. placeholder={automaticText4}
  145. placeholderTextColor="#B4B4B4"
  146. underlineColorAndroid="transparent"
  147. />
  148. </Layout>
  149. <View style={styles.buttonGroup}>
  150. <Button
  151. status='basic'
  152. appearance='outline'
  153. onPress={() => {
  154. navigation.goBack();
  155. }}
  156. >
  157. {cancel}
  158. </Button>
  159. <Button
  160. disabled={!canSub}
  161. appearance='filled'
  162. onPress={submit}
  163. >
  164. {save}
  165. </Button>
  166. </View>
  167. </ScrollPage>
  168. </>
  169. );
  170. }