I have to send an codeActivation with my API after calling this codeActivation from asyncStorage so I use this code:
componentDidMount() {
AsyncStorage.getItem(CODEACTIVATION_STORED)
.then(code => {
this.setState({ codeActivation: code})
console.log('t2 ' + this.state.codeActivation); << output : t1 544875962
});
AsyncStorage.getItem(TOKEN_STORED)
.then(code => {
this.setState({ Token: code})
});
console.log('t1 ' + this.state.codeActivation); << output: t1
this.pwHash(); << where I use this.state.codeActivation
}
how to call pwHash after setting my codeActivation from asyncStorage in this.state.codeActivation ?
componentDidMount() {
setInterval(() => {
AsyncStorage.getItem(CODEACTIVATION_STORED)
.then(code => {
this.setState({ codeActivation: code})
console.log('t2 ' + this.state.codeActivation); << output : t1 544875962
});
AsyncStorage.getItem(TOKEN_STORED)
.then(code => {
this.setState({ Token: code})
console.log('t1 ' + this.state.codeActivation); << output: t1
this.pwHash(); << where I use this.state.codeActivation && this.state.token
});
}, 5000);
}
you can call it like this or you can just ignore setInterval() if that is not you need.
Related
I am working in Vue Js with Laravel. But specifically in iPhone Chrome my dispatch method is not working after dispatching.
Here the API call code.
ProviderProfileService.addAddress(this.$apiUrl, this.address).then(
(response) => {
let result = response.data.createServiceLocation;
if (result.status == "success") {
let steps_status = JSON.parse(
result.service_location.user.providerProfileItems.profile_steps_status
);
if (steps_status.addrestime == true) {
alert(1);
this.$store
.dispatch("update_provider_profile_status", {
providerProfileStatus: steps_status,
})
.then((res) => {
alert(2);
this.$store.dispatch("update_progress_bar").then((res1) => {
if (response.data.createServiceLocation.status == "error") {
alert(0);
self.updateAddress();
} else {
this.$router.push(
"/provider-profile/language/" + this.userConfig.unique_identifier
);
alert(3);
// this.$router.push({
// name: "Language",
// params: { id: this.userConfig.unique_identifier },
// });
alert(4);
// window.location.href =
// "https://19b0-2404-3100-1c81-8081-e0bc-c658-121c-836b.ngrok.io/provider-profile/language/" +
// this.userConfig.unique_identifier;
this.scrollToTop();
alert(5);
}
});
});
}
}
},
(error) => {
self.content =
(error.response && error.response.data) || error.message || error.toString();
}
);
Here is the dispatch method code.
state.providerProfileStatus.basicinfo = (payload.basicinfo)?true:false;
state.providerProfileStatus.rates = (payload.rates)?true:false;
state.providerProfileStatus.services = (payload.services)?true:false;
state.providerProfileStatus.addrestime = (payload.addrestime)?true:false;
state.providerProfileStatus.availability = (payload.availability)?true:false;
state.providerProfileStatus.integrations = (payload.integrations)?true:false;
state.providerProfileStatus.certifications = (payload.certifications)?true:false;
state.providerProfileStatus.payment_settings = (payload.payment_settings)?true:false;
state.providerProfileStatus.documents_and_vaccination = (payload.documents_and_vaccination)?true:false;
state.providerProfileStatus.language_and_introduction = (payload.language_and_introduction)?true:false;
how can get values from va-select when user choose the data?
I use this method to show my data in va-select
<va-select
:label="$t('Unit Code')"
v-model="aircraftData.afta_ProcUnit1"
textBy="name"
searchable
:options="optionsProcUnit1"
:addBtn="true"
placeholder=""
:error="!!afta_ProcUnit1Errors.length"
:error-messages="afta_ProcUnit1Errors"
/>
apiRelatedUnit(postData) {
let self = this;
this.isLoading = true;
SmsApis.relatedUnit.post
.GetRelatedUnit(postData)
.then((xhr) => {
self.isLoading = false;
if (xhr.data.result[0].smsB_RelatedUnit) {
xhr.data.result[0].smsB_RelatedUnit.forEach(function (g, i) {
if (g.runt_Category === "0") {
self.optionsProcUnit2.push({
id: g.runt_unitID,
name: g.runt_unitID + " / " + g.runt_UnitTitle,
tel: g.runt_UnitTel,
});
}
if (g.runt_Category === "2") {
self.optionsProcUnit1.push({
id: g.runt_unitID,
name: g.runt_unitID + " / " + g.runt_UnitTitle,
tel: g.runt_UnitTel,
});
}
});
} else {
self.$swal.fire("Error", xhr.data.result[0].Error, "error");
}
})
.catch(function (error) {
self.isLoading = false;
if (error.message === "Cannot read property 'status' of undefined")
self.$swal.fire("Connect Error", "", "warning");
});
},
And the va-select will show like this one
Test / Sales
Test2 / Dev
Test3 / Bus
and when user click submit, it's will send date and writing in database
pdbt = {
tableA: [
{
afta_ProcUnit1: xxx, //how can get unit code in here???
afta_ProcUnit2: ProcUnit2,
}
]
}
Apis.AircraftAnomaly.post
.EditAircraftAnomaly(pdbt )
.then(function (xhr) {
self.isLoading = false;
if (xhr.data.result[0].Result === "OK") {
self.onEditAnomalyCL();
self.isLoading = true;
}
})
}
how can get value when user choose the options in va-select?
After downloading video and audio, I use react-native-ffmpeg to get the final video file. It works. I want to delete the 1.mp4 and 2.mp4 when I get the final video file. The problem is that the code after await getFinalVideo(path, path1, path2, titleVideo) doesn't run. The 1.mp4 and 2.mp4 still exists in the filesystem. How to fix it? Where is my fault?
import React from "react";
import { PermissionsAndroid } from "react-native";
import RNFS from "react-native-fs";
import { LogLevel, RNFFmpeg } from "react-native-ffmpeg";
// url1 video , url2 audio
export const fetchDashFile = async (url1, url2, title) => {
let options1 = {
method: "GET",
headers: {},
};
let options2 = {
method: "GET",
headers: {},
};
let path = RNFS.DownloadDirectoryPath + "/";
let path1 = path + "1" + ".mp4";
let path2 = path + "2" + ".mp4";
const beginVideo = (res) => {
console.log("start download video file");
};
const beginAudio = (res) => {
console.log("start download audio file");
};
const progressVideo = (res) => {
let percentage = ((100 * res.bytesWritten) / res.contentLength) | 0;
console.log(percentage);
};
const progressAudio = (res) => {};
let DownloadFileOptions1 = {
fromUrl: url1,
toFile: path1,
headers: options1.headers,
background: true,
connectionTimeout: 50,
progressInterval: 1,
progressDivider: 10,
begin: beginVideo,
progress: progressVideo,
};
let DownloadFileOptions2 = {
fromUrl: url2,
toFile: path2,
headers: options2.headers,
background: true,
connectionTimeout: 50,
progressInterval: 1,
progressDivider: 10,
begin: beginAudio,
progress: progressAudio,
};
try {
await Promise.all([
RNFS.downloadFile(DownloadFileOptions1).promise,
RNFS.downloadFile(DownloadFileOptions2).promise,
]);
let titleVideo = Date.now().toString();
await getFinalVideo(path, path1, path2, titleVideo);
if (RNFS.exists(path1)) {
console.log("delete 1");
await RNFS.unlink(path1);
}
if (RNFS.exists(path2)) {
console.log("delete 2");
await RNFS.unlink(path2);
}
} catch (e) {
alert("error,please try again");
}
};
function getFinalVideo(path, path1, path2, name) {
let command =
"-i " + path1 + " -i " + path2 + " -c copy " + path + name + ".mp4";
return new Promise((resovle, reject) => {
RNFFmpeg.executeAsync(command, (completedExecution) => {
if (completedExecution.returnCode === 0) {
console.log("FFmpeg process completed successfully");
} else {
console.log(
`FFmpeg process failed with rc=${completedExecution.returnCode}.`
);
}
})
.then((executionId) => {
console.log(executionId);
Promise.resolve("success");
})
.catch((e) => {
console.log("wrong happened when doing ffmpeg" + e);
Promise.reject(e);
});
});
}
I'm so stupid. Before Deleting files, it need to wait for finishing ffmpeg work! I misunderstood something about Promise. So here is right code.
...
let titleVideo = Date.now().toString()
await getFinalVideo(path, path1, path2, titleVideo)
...
async function getFinalVideo(path, path1, path2, name) {
let command = '-i ' + path1 + ' -i ' + path2 + ' -c copy ' + path + name + '.mp4'
await RNFFmpeg.executeAsync(command, completedExecution => {
if (completedExecution.returnCode === 0) {
console.log("FFmpeg process completed successfully");
} else {
console.log(`FFmpeg process failed with rc=${completedExecution.returnCode}.`)
}
})
.then(executionId => {
console.log(executionId)
// RNFFmpeg.cancelExecution(executionId)
})
.catch(e => {
console.log('wrong happened when doing ffmpeg' + e)
})
const scarlingProvider = vscode.languages.registerCompletionItemProvider(
'javascript',
{
provideCompletionItems(document, position, token, context) {
const linePrefix = document.lineAt(position).text.substr(0, position.character);
if (!hasChinese(linePrefix)) {
return undefined;
}
const reminds = starling.match(linePrefix)
console.log('reminds: ', reminds);
return [reminds].map(val => {
try {
const item = new vscode.CompletionItem(val, vscode.CompletionItemKind.Method)
item.insertText = `$t('${val}', '${linePrefix.trim()}')`
return item
} catch(err) {
console.log('err: ', err);
}
})
}
},
' '
As above, it's a snippet of a completion extension. I want the selected text to replace the original text instead of inserting that after the original text. What should I do?
You have to specify a range with your completion item. The model can give you the position of the original text for which the provider has been invoked:
const scarlingProvider = vscode.languages.registerCompletionItemProvider(
'javascript',
{
provideCompletionItems(document, position, token, context) {
const linePrefix = document.lineAt(position).text.substr(0, position.character);
if (!hasChinese(linePrefix)) {
return undefined;
}
const info = model.getWordUntilPosition(position);
const range = {
startLineNumber: position.lineNumber,
startColumn: info.startColumn - 1,
endLineNumber: position.lineNumber,
endColumn: info.endColumn,
};
const reminds = starling.match(linePrefix)
console.log('reminds: ', reminds);
return [reminds].map(val => {
try {
return {
label: "<a label>",
kind: CompletionItemKind.Method,
range,
insertText: `$t('${val}', '${linePrefix.trim()}')`,
detail: "<a description>",
}
} catch(err) {
console.log('err: ', err);
}
})
}
},
' '
I am getting this error when I am trying pass object to axios method "value for message cannot be cast from double to string". Does any one have Idea about this.
I have added my two functions.
addNotes = (formData) => {
let noteText = ''
Object.keys(formData).map((item) => {
noteText += formData[item] !== undefined ? `${formData[item]} \n` : ``
})
let localLocation = `${this.state.localAddress.locality}, ${this.state.localAddress.subLocality}`
let { userMetaData, graphListlimit, graphListoffset, imdCode } = this.state
let obj = {
'edEmployeeCode': userMetaData.ed_employee_code,
'edName': userMetaData.ed_name,
'edRoleCode': userMetaData.ed_role_code,
'imdCode': imdCode,
'imdSegment': null,
'bnNoteText': noteText,
'location': localLocation,
'meetingType': this.state.meetingType
}
this.props.onAddNotesAction(obj)
}
export const addNotesAction = (obj) => {
let params = {
ed_employee_code: obj.empCode,
ed_role_code: obj.empRoleCode,
ed_channel: obj.empChannel,
ed_name: obj.edName,
imd_code: obj.imdCode,
imd_segment: null,
bn_note_text: obj.bnNoteText,
location: obj.location,
meeting_type: obj.meetingType
}
return dispatch => {
axios.defaults.headers.common['Authorization'] = obj.token;
axios.post(`${Config.apiRootPath}/meetings/addbranchnote`,
params,
).then(response => {
dispatch(addNotesSuccess(response));
}).catch(err => {
dispatch(addNotesFailure(err.response));
});
};
};