Reputation: 318
I have a problem with my electron app. I navigate throw pages by using window.loadUrl()
. On some pages, the user needs to enter some data to be saved. The problem is that when the user moves to another page (after he added some data to inputs and etc) and after goes back no changes are detected and electron just loads HTML file with no user data. How it's possible to store this data and give user page with his previously added data? Thanks
Upvotes: 0
Views: 1174
Reputation: 36309
For a local solution, you can store the data within a few data types:
From there you can load data as you load/unload pages.
// Save the data
localStorage.setItem('userData', JSON.stringify(data));
// Load the data
let data = JSON.parse(localStorage.getItem('userData') || {});
Note: This only works in the rendering process and not the main process.
For a remote solution, you will need to send the data to a web server where it will process and save the data to in a remote location. An API is a good way to send this data.
Send/Request the data with a unique identifier, such as a userid.
// Save the data
fetch('http://my-website.com/save/123456', { // 123456 = userid
method: 'post',
body: JSON.stringify(data)
})
// Get the data
fetch('http://my-website.com/load/123456')
.then(resp => resp.json())
.then(json => { data = json })
Upvotes: 1