Best JavaScript code snippet using devicefarmer-stf
archive.page.ts
Source:archive.page.ts
...84 this.idata = data;85 this.idata.desc = data.description[this.language];86 if (data.type == 'people') {87 setTimeout(() => {88 // this.idata = this.updateImageArea(this.selectedImage);89 this.updateImageArea(this.idata, this.selectedImage);90 // console.log('this.idata.src = ', this.idata.src);91 },300);92 this.showDetail = false;93 // } else if (data.type == 'image') {94 // } else if (data.type == 'html') {95 }96 }97 // updateImageArea(id) {98 updateImageArea(idata, id) {99 // let idata = this.data[id];100 // container includes 'row' and 'image'101 let rowEle = document.getElementById("row");102 let rectRow:any = rowEle.getBoundingClientRect();103 let imageEle = document.getElementById("image");104 let rectImage:any = imageEle.getBoundingClientRect();105 106 let imageWidth = idata.image.width;107 let imageHeight = idata.image.height;108 let ratioWidth = rectImage.width / imageWidth;109 let ratioHeight = rectImage.height / imageHeight;110 let xImage = 0;111 let yImage = parseInt(rectRow.height);112 idata.areas.forEach((area:any) => {...
index.js
Source:index.js
1import React, { useEffect, useState } from 'react';2import { Modal } from 'react-native';3import { useSelector, connect } from 'react-redux';4import { launchImageLibrary } from 'react-native-image-picker';5import { useNavigation } from '@react-navigation/native';6import Header from '../../components/Header';7import { defaultColor, grayFont } from '../../globals';8import { api } from '../../services/api';9import ModalLoading from '../../components/ModalLoading';10import ServerMessage from '../../components/ServerMessage';11import FontAwesome from 'react-native-vector-icons/FontAwesome';12import AntDesign from 'react-native-vector-icons/AntDesign';13import {14 UpdateProfileContainer,15 UpdateButton,16 UpdateButtonText,17 UpdateProfileArea,18 19 UpdateImageArea,20 UpdateImage,21 UpdateImageButton,22 FormArea,23 InputArea,24 Label,25 Input,26} from './styles';27function UpdateProfile (props) {28 const [dataImg, setDataImg] = useState('');29 const [name, setName] = useState('');30 const [email, setEmail] = useState('');31 const [user, setUser] = useState('');32 const [hasChanges, setHasChanges] = useState(false);33 const [modalVisible, setModalVisible] = useState(false);34 const [serverMsg, setServerMsg] = useState('');35 const token = useSelector(state => state.user.token);36 const avatarLoggedIn = useSelector(state => state.user.avatar);37 const nameLoggedIn = useSelector(state => state.user.name);38 const emailLoggedIn = useSelector(state => state.user.email);39 const userLoggedIn = useSelector(state => state.user.user);40 const navigation = useNavigation();41 useEffect(() => {42 setName(nameLoggedIn);43 setEmail(emailLoggedIn);44 setUser(userLoggedIn);45 setDataImg(avatarLoggedIn);46 }, []);47 useEffect(() => {48 setTimeout(() => {49 setServerMsg('');50 }, 2500)51 }, [serverMsg]);52 function submitData () {53 setModalVisible(true);54 let formData = new FormData();55 if(name) {56 formData.append('name', name);57 } if (email) {58 formData.append('email', email);59 } if (user) {60 formData.append('user', user);61 } 62 if(dataImg === avatarLoggedIn) {63 formData.append('img', dataImg);64 } else {65 let fileExtension = dataImg.slice(-3);66 formData.append('img', {67 uri: dataImg,68 type: `image/${fileExtension}`,69 name: 'image'70 })71 }72 formData.append('token', token);73 api.post(`/edit-profile/auth?token=${token}`, formData)74 .then((res) => {75 if(res.data.error) {76 console.log(res.data.error);77 } else {78 console.log(res.data);79 props.setName(name);80 props.setEmail(email);81 props.setUser(user);82 83 if(res.data.filename) {84 props.setAvatar(res.data.filename);85 }86 setTimeout(() => {87 setHasChanges(false);88 setServerMsg(res.data.result);89 }, 2500)90 }91 }).catch((err) => console.log(err));92 setTimeout(() => {93 setModalVisible(false);94 }, 2500)95 }96 function chooseImageGallery () {97 launchImageLibrary(null, (res) => {98 let data = res.assets;99 setDataImg(data[0].uri);100 });101 setHasChanges(true);102 }103 return(104 <UpdateProfileContainer>105 <Header />106 <UpdateButton onPress={submitData} disabled={hasChanges ? false : true}>107 <UpdateButtonText color={hasChanges ? '#2196F3' : grayFont}>Update</UpdateButtonText>108 </UpdateButton>109 {serverMsg ? 110 <ServerMessage type="result" text={serverMsg} />111 :112 undefined113 }114 <Modal115 animationType="fade"116 transparent={true}117 visible={modalVisible}118 onRequestClose={() => setModalVisible(!modalVisible)}119 >120 <ModalLoading />121 </Modal>122 <UpdateProfileArea>123 <UpdateImageArea>124 {dataImg ?125 // Essa imagem vai verificar qual tipo de arquivo vem, se as 4 primeiras letras forem === file, é pq é um arquivo vindo do celular do usuário126 <UpdateImage source={{uri: dataImg.substring(4, 0) !== 'file' ? `http://192.168.0.110:3000/media/${dataImg}` : dataImg}} /> 127 :128 <FontAwesome name="user" color="#aaa" size={80} /> 129 }130 <UpdateImageButton onPress={chooseImageGallery}>131 <AntDesign name="camerao" color="#aaa" size={30} />132 </UpdateImageButton>133 </UpdateImageArea>134 <FormArea>135 <InputArea>136 <Label>Name</Label>137 <Input onChange={() => setHasChanges(true)} onChangeText={v => setName(v)} defaultValue={name} />138 </InputArea>139 <InputArea>140 <Label>Email</Label>141 <Input onChange={() => setHasChanges(true)} onChangeText={v => setEmail(v)} defaultValue={email} />142 </InputArea>143 <InputArea>144 <Label>User</Label>145 <Input onChange={() => setHasChanges(true)} onChangeText={v => setUser(v)} defaultValue={user} />146 </InputArea>147 </FormArea>148 </UpdateProfileArea>149 </UpdateProfileContainer>150 )151}152const mapDispatchToProps = (dispatch) => {153 return {154 setName:(name)=>dispatch({type:'SET_NAME', payload: {name}}), // Seta o nome do usuário com redux155 setEmail:(email)=>dispatch({type:'SET_EMAIL', payload: {email}}), // Seta o email do usuário com redux156 setAvatar:(avatar)=>dispatch({type:'SET_AVATAR', payload: {avatar}}), // Seta o token do usuário com redux157 setUser:(user)=>dispatch({type:'SET_USER', payload: {user}}) // Seta o user do usuário com redux158 };159}...
styles.js
Source:styles.js
1import styled from 'styled-components/native';2import { black, blackish, defaultColor, grayish, white } from '../../globals';3export const UpdateProfileContainer = styled.SafeAreaView`4 flex: 1;5 background-color: ${white};6`;7/** ---------------------------------------------------- **/8export const UpdateButton = styled.TouchableOpacity`9 position: absolute;10 z-index: 999;11 right: 20px;12 top: 25px;13`;14export const UpdateButtonText = styled.Text`15 color: ${props=>props.color};16 font-size: 16px;17`;18/** ---------------------------------------------------- **/19export const UpdateProfileArea = styled.View`20 align-items: center;21 margin-top: 50px;22`;23/** ---------------------------------------------------- **/24export const UpdateImageArea = styled.View`25 background-color: ${grayish};26 align-items: center;27 justify-content: center;28 width: 130px;29 height: 130px;30 border-radius: 65px;31`;32export const UpdateImage = styled.Image`33 width: 130px;34 height: 130px;35 border-radius: 65px;36`; 37export const UpdateImageButton = styled.TouchableOpacity`38 align-items: center;39 justify-content: center;40 position: absolute;41 right: 10px;42 bottom: 10px;43 background-color: rgba(0, 0, 0, 0.5);44 width: 60px;45 height: 60px;46 border-radius: 30px;47`;48/** ---------------------------------------------------- **/49export const FormArea = styled.View`50 margin-top: 30px;51 width: 100%;52`;53export const InputArea = styled.View`54 margin-top: 20px;55 padding: 0 20px;56`;57export const Label = styled.Text`58 color: ${blackish};59 font-size: 16px;60`;61export const Input = styled.TextInput`62 background-color: ${grayish};63 color: ${black};64 height: 52px;65 padding-left: 10px;66 margin-top: 10px;67 border-radius: 10px;...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var client = stf.connect();3client.updateImageArea(0, 0, 100, 100);4client.disconnect();5var stf = require('devicefarmer-stf');6var client = stf.connect();7client.updateImageArea(0, 0, 100, 100);8client.disconnect();9client.updateImageArea(0, 0, 100, 100);10client.updateImageArea(0, 0, 100, 100, function (err, res) {11 if (err) {12 console.log(err);13 } else {14 console.log(res);15 }16});17client.updateImageArea(0, 0, 100, 100, function (err, res) {18 if (err) {19 console.log(err);20 }21});22client.updateImageArea(0, 0, 100, 100, function (res) {23 console.log(res);24});25client.updateImageArea(0, 0, 100, 100, function (err) {26 if (err) {27 console.log(err);28 }29});30client.updateImageArea(0, 0, 100, 100, function (res) {31 console.log(res);32});33client.updateImageArea(0, 0, 100, 100, function (err) {34 if (err) {35 console.log(err);36 }37});38client.updateImageArea(0, 0, 100, 100, function (res) {39 console.log(res);40});41client.updateImageArea(0, 0, 100, 100, function (err) {42 if (err) {43 console.log(err);44 }45});
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf');2client.updateImageArea('deviceID', 'imageArea', function(err, res) {3 if (err) {4 console.log(err);5 } else {6 console.log(res);7 }8});9var DeviceFarmer = require('devicefarmer-stf');10client.getDisplayMetrics('deviceID', function(err, res) {11 if (err) {12 console.log(err);13 } else {14 console.log(res);15 }16});17var DeviceFarmer = require('devicefarmer-stf');18client.getDeviceList(function(err, res) {19 if (err) {20 console.log(err);21 } else {22 console.log(res);23 }24});25var DeviceFarmer = require('devicefarmer-stf');26client.getDeviceDetails('deviceID', function(err, res) {27 if (err) {28 console.log(err);29 } else {30 console.log(res);31 }32});33var DeviceFarmer = require('devicefarmer-stf');34client.getDeviceState('deviceID', function(err, res) {35 if (err) {36 console.log(err);37 } else {38 console.log(res);39 }40});41var DeviceFarmer = require('devicefarmer-stf');42client.getDeviceOwner('deviceID', function(err, res) {43 if (err) {44 console.log(err);45 } else
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = new stf.Device();3device.updateImageArea('path/to/image', 'path/to/area', function(err, res) {4 if (err) {5 console.log('error: ' + err);6 } else {7 console.log(res);8 }9});10var stf = require('devicefarmer-stf');11var device = new stf.Device();12device.updateImageArea('path/to/image', 'path/to/area', function(err, res) {13 if (err) {14 console.log('error: ' + err);15 } else {16 console.log(res);17 }18});19var stf = require('devicefarmer-stf');20var device = new stf.Device();21device.updateImageArea('path/to/image', 'path/to/area', function(err, res) {22 if (err) {23 console.log('error: ' + err);24 } else {25 console.log(res);26 }27});28var stf = require('devicefarmer-stf');29var device = new stf.Device();30device.updateImageArea('path/to/image', 'path/to/area', function(err, res) {31 if (err) {32 console.log('error: ' + err);33 } else {34 console.log(res);35 }36});37var stf = require('devicefarmer-stf');38var device = new stf.Device();39device.updateImageArea('path/to/image', 'path/to/area', function(err, res) {40 if (err) {41 console.log('error: ' + err);42 } else {43 console.log(res);44 }45});46var stf = require('devicefarmer-stf');47var device = new stf.Device();48device.updateImageArea('path/to/image', 'path/to/area', function(err, res) {49 if (err) {
Using AI Code Generation
1var stf = require('devicefarmer-stf');2stfClient.updateImageArea('device id', {3}, function(err, res) {4 console.log(err, res);5});6var stf = require('devicefarmer-stf');7stfClient.updateImageArea('device id', {8}, function(err, res) {9 console.log(err, res);10});11The updateImageArea() method takes three arguments:12{ success: true }13{ success: false, error: 'error message' }14The updateImageArea() method takes three arguments:15{ success: true }16{ success: false, error: 'error message' }17The updateImageArea() method takes three arguments:18{ success: true }19{ success: false, error: 'error message' }20The updateImageArea() method takes three arguments:
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var client = new stf.StfClient();3var device = client.getDevice('LGH870f5c4d4');4var imageArea = new stf.ImageArea(0, 0, 100, 100);5device.updateImageArea(imageArea, function (err) {6 if (err) {7 console.log(err);8 }9});10var imageArea = new stf.ImageArea(0, 0, 200, 200);11device.updateImageArea(imageArea, function (err) {12 if (err) {13 console.log(err);14 }15});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!