Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update toast style #127

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/images/close.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
27 changes: 23 additions & 4 deletions src/scripts/utils/toast/toast.css
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
@import url("toastify-js/src/toastify.css");

.toast-close {
color: black !important;
opacity: 1;
padding: 0;
margin-left: 20px;
}

.toast-header {
display: flex;
gap: 12px;
margin-bottom: 8px;
gap: 10px;
margin-bottom: 16px;
font-size: 20px;
font-weight: bold;
font-weight: 700;
color: black;
align-items: center;
}

.toast-content {
font-size: 12px;
font-weight: 400;

ul {
margin-bottom: 16px;
}

a:hover,
a:link,
a:visited {
color: black;
text-decoration: underline;
}
}
13 changes: 13 additions & 0 deletions src/scripts/utils/toast/toast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ interface ToastOptions extends StartToastifyInstance.Options {
title?: string;
}

function updateCloseButton() {
const closeButtonNode = document.querySelector(".toast-close");
if (closeButtonNode) {
closeButtonNode.innerHTML = "<img src='/images/close.svg' >";
}
}

export function showToast(options: ToastOptions) {
const { description, avatar, title } = options;
const toastNode = document.createElement("div");
Expand All @@ -18,6 +25,7 @@ export function showToast(options: ToastOptions) {
title ?? ""
}</span>`;

toastMessage.classList.add("toast-content");
toastMessage.innerHTML = description;
toastNode.appendChild(toastHeader);
toastNode.appendChild(toastMessage);
Expand All @@ -30,6 +38,9 @@ export function showToast(options: ToastOptions) {
color: "black",
alignItems: "start",
justifyContent: "start",
boxShadow: "0px 4px 20px 0px rgba(0, 0, 0, 0.3)",
borderRadius: "10px",
padding: "20px",
},
onClick: function () {},
duration: 3000,
Expand All @@ -39,4 +50,6 @@ export function showToast(options: ToastOptions) {
stopOnFocus: true,
...options,
}).showToast();

updateCloseButton();
}
Loading