CEC-381 Install messages and update styling (#76)
* Styling * Handle install messages * Update progress * Display download and install status
This commit is contained in:
@@ -76,10 +76,20 @@ export const CarUpdatesProvider = ({ children }) => {
|
||||
};
|
||||
|
||||
const applyProgressStatus = (item, status) => {
|
||||
if (status.msg === "package_download_complete") {
|
||||
delete item.progress;
|
||||
if (
|
||||
status.msg === "package_download_start" ||
|
||||
status.msg === "download_start"
|
||||
) {
|
||||
item.progress = 1;
|
||||
item.status = "downloading";
|
||||
} else if (status.msg === "package_download_complete") {
|
||||
item.status = "downloaded";
|
||||
} else if (status.msg === "downloading" && status.package_total > 0) {
|
||||
} else if (
|
||||
status.msg === "downloading" &&
|
||||
status.package_current &&
|
||||
status.package_total &&
|
||||
status.package_total > 0
|
||||
) {
|
||||
let progress = Math.floor(
|
||||
(100 * status.package_current) / status.package_total
|
||||
);
|
||||
@@ -88,8 +98,23 @@ export const CarUpdatesProvider = ({ children }) => {
|
||||
item.status = `downloading ${progress}%`;
|
||||
} else if (status.error > 0 || status.msg === "download_error") {
|
||||
item.status = "download error";
|
||||
} else if (status.msg === "package_install_start") {
|
||||
item.progress = 1;
|
||||
item.status = "installing";
|
||||
} else if (
|
||||
status.msg === "installing" &&
|
||||
status.installed &&
|
||||
status.total_files &&
|
||||
status.total_files > 0
|
||||
) {
|
||||
let progress = Math.floor((100 * status.installed) / status.total_files);
|
||||
item.progress = progress;
|
||||
item.status = `installing ${progress}%`;
|
||||
} else if (status.msg === "package_install_complete") {
|
||||
item.status = "installed";
|
||||
} else {
|
||||
item.status = "downloading";
|
||||
delete item.progress;
|
||||
item.status = status.msg;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,8 +122,8 @@ export const CarUpdatesProvider = ({ children }) => {
|
||||
let items = JSON.parse(JSON.stringify(carUpdates));
|
||||
|
||||
statuses.forEach((status) => {
|
||||
let item = items.find((item) => status.id === item.id);
|
||||
if (!item || status.id === 0) return;
|
||||
let item = items.find((item) => status.car_update_id === item.id);
|
||||
if (!item || status.car_update_id === 0) return;
|
||||
applyProgressStatus(item, status);
|
||||
});
|
||||
|
||||
@@ -113,7 +138,7 @@ export const CarUpdatesProvider = ({ children }) => {
|
||||
try {
|
||||
setBusy(true);
|
||||
const carupdateids = carUpdates.reduce((accum, update) => {
|
||||
if (update.status !== "downloaded") accum.push(update.id);
|
||||
if (update.status !== "installed") accum.push(update.id);
|
||||
return accum;
|
||||
}, []);
|
||||
if (carupdateids.length === 0) return;
|
||||
|
||||
Reference in New Issue
Block a user