Skip to content

Commit

Permalink
Do not redirect to download page if no generated mockup
Browse files Browse the repository at this point in the history
  • Loading branch information
YayunHuang committed Sep 2, 2024
1 parent e31891f commit f0d7d74
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/pages/download/_downloadPythonPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,6 @@ function handlePartialSuccess(failedImages) {
});
}

function handleNoGeneratedMockup() {
const description = `
<div>Try a different image/device. <br> If the issue persists, please report it on <a href='https://github.com/oursky/mockuphone.com/issues'>Github</a></div>
`;
showToast({
title: "No generated mockup",
description: description,
avatar: "/images/upload-error.svg",
});
}

function downloadGeneratedMockup(deviceId, images) {
var zip = new JSZip();
var count = 0;
Expand Down Expand Up @@ -112,8 +101,4 @@ export async function generateZIP(deviceId) {
if (failedImages.length > 0 && images.size > 0) {
handlePartialSuccess(failedImages);
}

if (images.size === 0) {
handleNoGeneratedMockup();
}
}
24 changes: 22 additions & 2 deletions src/pages/model/_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import localforage from "localforage";
import { ImageUpload, ImageUploadState } from "./models/_image-upload";
import { isSameAspectRatio } from "./utils/_images";
import { scrollToElementTop } from "./utils/_scroll";
import { showToast } from "../../scripts/utils/toast/toast";

let dragZoneCounter = 0; // https://stackoverflow.com/a/21002544/19287186
const MAX_FILE_SIZE_BYTE = 104857600;
Expand Down Expand Up @@ -719,14 +720,33 @@ function main() {
e.target.value = "";
};

function handleNoGeneratedMockup() {
const description = `
<div>Try a different image/device. <br> If the issue persists, please report it on <a href='https://github.com/oursky/mockuphone.com/issues'>Github</a></div>
`;
showToast({
title: "No generated mockup",
description: description,
avatar: "/images/upload-error.svg",
});
}

const navigateToDownloadPage = () => {
window.location.href = "/download/?deviceId=" + window.workerDeviceId;
};

const onAllMockupGenerated = async (allGeneratedMockups) => {
localforage.setItem("generatedMockups", allGeneratedMockups).then(() => {
navigateToDownloadPage();
const haveGeneratedMockup = allGeneratedMockups.some((mockup) => {
return mockup.status === "success";
});
if (haveGeneratedMockup) {
localforage.setItem("generatedMockups", allGeneratedMockups).then(() => {
navigateToDownloadPage();
});
} else {
window.viewModel.cancelMockup();
handleNoGeneratedMockup();
}
};

// observe fileListViewModel: isProcessing
Expand Down

0 comments on commit f0d7d74

Please sign in to comment.