File tree Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Expand file tree Collapse file tree 3 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ function searchEmailSenders(emails) {
1515function 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+
3642function 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+
5669chrome . runtime . onMessage . addListener ( ( message , sender , sendResponse ) => {
5770 if ( message . action === "GET_EMAIL_ACCOUNT" ) {
5871 const value = getEmailAccount ( ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,6 @@ import { ActionsProvider } from "../_shared/providers/actionsContext";
1313
1414const 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 ? (
Original file line number Diff line number Diff line change @@ -3,11 +3,9 @@ import "./modal.css";
33
44export 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 >
You can’t perform that action at this time.
0 commit comments