Skip to content

Commit

Permalink
handlenett-frontend: fixed bug with deleted item not being removed
Browse files Browse the repository at this point in the history
from frontend after deleted. Was removed from backend, but still
visible in the app (before reload)
  • Loading branch information
maads committed Oct 31, 2024
1 parent d1df6cd commit 4d8059e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions handlenett-frontend/composables/useHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ export default async function (url: string, method: string, data = {}) {
mode: "cors",
body: !!data && method != "GET" ? JSON.stringify(data) : null,
});
return response.json();

const responseText = await response.text();
try {
const responseJson = JSON.parse(responseText);
return responseJson;
} catch (e) {
// return without parsing.
// might be empty
return responseText;
}
} catch (error) {
console.info(error);
console.error("useHttp catch error", error);
return Promise.reject(error);
}
}
2 changes: 1 addition & 1 deletion handlenett-frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const newItem = (newItem) => {
}
const deleteItem = (deleteItem) => {
useHttp(`Item/${deleteItem.id}`, 'DELETE').then(data => {
useHttp(`Item/${deleteItem.id}`, 'DELETE').then(() => {
let i = items.value.find(i => i.id === deleteItem.id)
const idx = items.value.indexOf(i)
items.value.splice(idx, 1)
Expand Down

0 comments on commit 4d8059e

Please sign in to comment.