Skip to content

Commit 4e53895

Browse files
authored
iframe gets deleted when tutorial exits - fixes #40 (#42)
1 parent 14251e0 commit 4e53895

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

public/content.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function searchEmailSenders(emails) {
1515
function displayTutorial() {
1616
// Create an iframe element
1717
const iframe = document.createElement("iframe");
18+
iframe.id = "inboxwhiz-tutorial";
1819
iframe.src = chrome.runtime.getURL("tutorial/index.html");
1920

2021
// Style the iframe as a modal
@@ -33,6 +34,11 @@ function displayTutorial() {
3334
document.body.appendChild(iframe);
3435
}
3536

37+
function closeTutorial() {
38+
const iframe = document.getElementById("inboxwhiz-tutorial");
39+
iframe?.remove();
40+
}
41+
3642
function getEmailAccount() {
3743
// Get the email account from the page
3844
const title = document.querySelector("title").textContent;
@@ -53,6 +59,13 @@ chrome.runtime.onMessage.addListener((message) => {
5359
}
5460
});
5561

62+
chrome.runtime.onMessage.addListener((message) => {
63+
if (message.action === "CLOSE_TUTORIAL") {
64+
console.log("Received message to close tutorial");
65+
closeTutorial();
66+
}
67+
});
68+
5669
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
5770
if (message.action === "GET_EMAIL_ACCOUNT") {
5871
const value = getEmailAccount();

src/tutorial/Tutorial.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { ActionsProvider } from "../_shared/providers/actionsContext";
1313

1414
const Tutorial = () => {
1515
const [step, setStep] = useState(0);
16-
const [isModalOpen, setIsModalOpen] = useState(true);
1716

1817
const handleNext = () => {
1918
setStep(step + 1);
@@ -22,8 +21,16 @@ const Tutorial = () => {
2221
return (
2322
<ActionsProvider>
2423
<Modal
25-
isOpen={isModalOpen}
26-
onClose={step === 5 ? () => setIsModalOpen(false) : () => {}}
24+
onClose={step === 5
25+
? () => {
26+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
27+
const tab = tabs[0];
28+
if (tab && tab.id !== undefined) {
29+
chrome.tabs.sendMessage(tab.id, { action: "CLOSE_TUTORIAL" });
30+
}
31+
});
32+
}
33+
: () => { }}
2734
>
2835
<div className="tutorial-popup">
2936
{step === 0 ? (

src/tutorial/components/modal.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@ import "./modal.css";
33

44
export const Modal = ({
55
children,
6-
isOpen,
76
onClose,
87
}: {
98
children: ReactNode;
10-
isOpen: boolean;
119
onClose: () => void;
1210
}) => {
1311
const handleBackgroundClick = (event: MouseEvent<HTMLDivElement>) => {
@@ -20,7 +18,6 @@ export const Modal = ({
2018
<div
2119
className="modal"
2220
onClick={handleBackgroundClick}
23-
style={{ display: isOpen ? "flex" : "none" }}
2421
>
2522
{children}
2623
</div>

0 commit comments

Comments
 (0)