diff --git a/package.json b/package.json index 11daec5..3c005e9 100644 --- a/package.json +++ b/package.json @@ -67,7 +67,7 @@ "coverageThreshold": { "global": { "branches": 39, - "functions": 45.5, + "functions": 45, "lines": 50, "statements": 49 } diff --git a/src/components/Contexts/CarUpdatesContext.jsx b/src/components/Contexts/CarUpdatesContext.jsx index 3e37bd8..a16bed2 100644 --- a/src/components/Contexts/CarUpdatesContext.jsx +++ b/src/components/Contexts/CarUpdatesContext.jsx @@ -76,11 +76,10 @@ export const CarUpdatesProvider = ({ children }) => { result = await api.getCarUpdates(search, token); if (result.error) throw new Error(`Get car updates error. ${result.message}`); - result.data.forEach((item, i) => { - item.msg = item.status; + result.data.forEach((item) => { item.progress = 0; - applyProgressStatus(item); - result.data[i] = Object.assign(result.data[i], item); + item.msg = item.status; + applyProgressStatus(item, item); }); setCarUpdates(result.data); if (search && search.offset === 0 && result.total) { @@ -120,27 +119,28 @@ export const CarUpdatesProvider = ({ children }) => { return 0; }; - const applyProgressStatus = (item) => { - if (validateStatusMessage(item)) { - if (item.msg === "downloading") { - item.progress = getDownloadProgress(item); + const applyProgressStatus = (item, status) => { + if (validateStatusMessage(status)) { + if (status.msg === "downloading") { + item.progress = getDownloadProgress(status); item.status = `${item.ecu || ""} downloading ${item.progress}%`.trim(); return; - } else if (item.msg === "package_download_complete") { + } else if (status.msg === "package_download_complete") { item.progress = 100; - item.status = `${item.ecu || ""} download complete`.trim(); + item.status = "download complete"; return; - } else if (item.msg === "installing") { - item.progress = getInstallProgress(item); + } else if (status.msg === "installing") { + item.progress = getInstallProgress(status); item.status = `${item.ecu || ""} installing ${item.progress}%`.trim(); return; - } else if (item.msg === "package_install_complete") { + } else if (status.msg === "package_install_complete") { item.progress = 100; - item.status = `${item.ecu || ""} install complete`.trim(); + item.status = "install complete"; return; } } delete item.progress; + item.status = status.msg; }; const applyProgressStatuses = (statuses) => { @@ -222,28 +222,12 @@ export const CarUpdatesProvider = ({ children }) => { return result; }; - const cancelUpdate = async (id, token) => { - let result; - - try { - setBusy(true); - result = await api.cancelCarUpdate(id, token); - if (result.error) - throw new Error(`Cancel car update error. ${result.message}`); - } finally { - setBusy(false); - } - - return result; - }; - return (