|
| 1 | +/* eslint-disable react-native/no-inline-styles */ |
| 2 | +/* eslint-disable react/react-in-jsx-scope */ |
| 3 | +import { |
| 4 | + Image, |
| 5 | + ScrollView, |
| 6 | + Text, |
| 7 | + TextInput, |
| 8 | + TouchableOpacity, |
| 9 | + View, |
| 10 | + Clipboard, |
| 11 | + Dimensions, |
| 12 | +} from 'react-native'; |
| 13 | +import {TopHeader} from '../Components/Global/TopHeader'; |
| 14 | +import {useState} from 'react'; |
| 15 | +import {useToast} from 'react-native-toast-notifications'; |
| 16 | +import axios from 'axios'; |
| 17 | +import ResultDiaplay from '../Components/Global/ReaultDiaplay'; |
| 18 | + |
| 19 | +export const PlagiarismPage = ({navigation}) => { |
| 20 | + const windowWidth = Dimensions.get('window').width; |
| 21 | + const [input, setInput] = useState(''); |
| 22 | + const [loading, setloading] = useState(false); |
| 23 | + const [result, setResult] = useState(''); |
| 24 | + const toast = useToast(); |
| 25 | + async function GenerateCode() { |
| 26 | + if (input === '') { |
| 27 | + toast.show('Enter Paragraph', { |
| 28 | + type: 'danger', |
| 29 | + placement: 'center', |
| 30 | + duration: 4000, |
| 31 | + offset: 30, |
| 32 | + animationType: 'zoom-in', |
| 33 | + }); |
| 34 | + } else { |
| 35 | + setloading(true); |
| 36 | + let config = { |
| 37 | + method: 'post', |
| 38 | + maxBodyLength: Infinity, |
| 39 | + url: 'https://generativelanguage.googleapis.com/v1beta2/models/chat-bison-001:generateMessage?key=AIzaSyD46fzT8jTrrC8mFSoZWtHFzoCh79MpkYk', |
| 40 | + headers: { |
| 41 | + 'Content-Type': 'application/json', |
| 42 | + }, |
| 43 | + data: JSON.stringify({ |
| 44 | + prompt: { |
| 45 | + messages: [ |
| 46 | + { |
| 47 | + content: `remove plagiarism from following text: \n |
| 48 | + ${input}`, |
| 49 | + }, |
| 50 | + ], |
| 51 | + }, |
| 52 | + }), |
| 53 | + }; |
| 54 | + axios |
| 55 | + .request(config) |
| 56 | + .then(r => { |
| 57 | + setResult(r.data.candidates[0].content); |
| 58 | + setInput(''); |
| 59 | + setloading(false); |
| 60 | + }) |
| 61 | + .catch(e => { |
| 62 | + setloading(false); |
| 63 | + if (e.message === 'Network Error') { |
| 64 | + toast.show('No Internet 😟', { |
| 65 | + type: 'danger', |
| 66 | + placement: 'top', |
| 67 | + duration: 3000, |
| 68 | + offset: 30, |
| 69 | + animationType: 'zoom-in', |
| 70 | + }); |
| 71 | + } |
| 72 | + console.log(e.message); |
| 73 | + }); |
| 74 | + } |
| 75 | + } |
| 76 | + return ( |
| 77 | + <View |
| 78 | + style={{ |
| 79 | + flex: 1, |
| 80 | + backgroundColor: '#1e1b38', |
| 81 | + }}> |
| 82 | + <TopHeader text={'Plagiarism'} navigation={navigation} /> |
| 83 | + <ScrollView> |
| 84 | + <View style={{paddingHorizontal: 20}}> |
| 85 | + <View |
| 86 | + style={{ |
| 87 | + backgroundColor: '#292250', |
| 88 | + borderTopRightRadius: 10, |
| 89 | + borderTopLeftRadius: 10, |
| 90 | + overflow: 'hidden', |
| 91 | + }}> |
| 92 | + <TextInput |
| 93 | + clearButtonMode="while-editing" |
| 94 | + multiline={true} |
| 95 | + numberOfLines={6} |
| 96 | + placeholder={'Paragraph...'} |
| 97 | + value={input} |
| 98 | + onChangeText={text => { |
| 99 | + setInput(text); |
| 100 | + }} |
| 101 | + placeholderTextColor={'rgb(197, 195, 195)'} |
| 102 | + style={{ |
| 103 | + backgroundColor: '#292250', |
| 104 | + alignItems: 'flex-start', |
| 105 | + textAlignVertical: 'top', |
| 106 | + padding: 15, |
| 107 | + color: 'white', |
| 108 | + borderBottomWidth: 1, |
| 109 | + borderBottomColor: '#100b2e', |
| 110 | + }} |
| 111 | + /> |
| 112 | + </View> |
| 113 | + </View> |
| 114 | + {!loading && ( |
| 115 | + <View |
| 116 | + style={{ |
| 117 | + flexDirection: 'row', |
| 118 | + gap: 2, |
| 119 | + }}> |
| 120 | + <TouchableOpacity |
| 121 | + onPress={() => { |
| 122 | + if (!loading) { |
| 123 | + setInput(''); |
| 124 | + } |
| 125 | + }} |
| 126 | + style={{ |
| 127 | + backgroundColor: '#4341c2', |
| 128 | + marginLeft: 20, |
| 129 | + alignItems: 'center', |
| 130 | + justifyContent: 'center', |
| 131 | + height: 50, |
| 132 | + flex: 1, |
| 133 | + borderBottomLeftRadius: 10, |
| 134 | + }}> |
| 135 | + <Text |
| 136 | + style={{ |
| 137 | + textAlign: 'center', |
| 138 | + fontSize: windowWidth * 0.032, |
| 139 | + color: 'rgb(236, 236, 236)', |
| 140 | + }}> |
| 141 | + Clear text |
| 142 | + </Text> |
| 143 | + </TouchableOpacity> |
| 144 | + <TouchableOpacity |
| 145 | + onPress={() => { |
| 146 | + if (!loading) { |
| 147 | + GenerateCode(); |
| 148 | + } |
| 149 | + }} |
| 150 | + style={{ |
| 151 | + backgroundColor: '#4341c2', |
| 152 | + marginRight: 20, |
| 153 | + alignItems: 'center', |
| 154 | + justifyContent: 'center', |
| 155 | + height: 50, |
| 156 | + flex: 1, |
| 157 | + borderBottomRightRadius: 10, |
| 158 | + }}> |
| 159 | + <Text |
| 160 | + style={{ |
| 161 | + textAlign: 'center', |
| 162 | + fontSize: windowWidth * 0.032, |
| 163 | + color: 'rgb(236, 236, 236)', |
| 164 | + }}> |
| 165 | + Remove plagiarism |
| 166 | + </Text> |
| 167 | + </TouchableOpacity> |
| 168 | + </View> |
| 169 | + )} |
| 170 | + {loading && ( |
| 171 | + <View |
| 172 | + style={{ |
| 173 | + backgroundColor: '#292250', |
| 174 | + marginHorizontal: 20, |
| 175 | + alignItems: 'center', |
| 176 | + justifyContent: 'center', |
| 177 | + height: 50, |
| 178 | + borderBottomRightRadius: 10, |
| 179 | + borderBottomLeftRadius: 10, |
| 180 | + }}> |
| 181 | + <Image |
| 182 | + source={require('../Assets/loading.gif')} |
| 183 | + style={{ |
| 184 | + width: 100, |
| 185 | + height: 50, |
| 186 | + }} |
| 187 | + /> |
| 188 | + </View> |
| 189 | + )} |
| 190 | + {result.length !== 0 && <ResultDiaplay text={result} />} |
| 191 | + </ScrollView> |
| 192 | + </View> |
| 193 | + ); |
| 194 | +}; |
0 commit comments