deno and tauri work and start
todo: fix deno that it displays page in /static
This commit is contained in:
30
frontend/static/main.js
Normal file
30
frontend/static/main.js
Normal file
@@ -0,0 +1,30 @@
|
||||
// filepath: /home/smikkelbakje/Inventory/frontend/main.js
|
||||
|
||||
document.getElementById('data-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const name = document.getElementById('name').value;
|
||||
try {
|
||||
await invoke('insert_data', { name });
|
||||
console.log('Data inserted successfully'); // Debug print
|
||||
fetchData();
|
||||
} catch (error) {
|
||||
console.error('Error inserting data:', error); // Print error
|
||||
}
|
||||
});
|
||||
|
||||
async function fetchData() {
|
||||
try {
|
||||
const data = await invoke('get_data');
|
||||
const dataList = document.getElementById('data-list');
|
||||
dataList.innerHTML = '';
|
||||
data.forEach(item => {
|
||||
const li = document.createElement('li');
|
||||
li.textContent = item;
|
||||
dataList.appendChild(li);
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error); // Print error
|
||||
}
|
||||
}
|
||||
|
||||
fetchData();
|
Reference in New Issue
Block a user