function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
raghu narayanaraghu narayana 

Lightning component for Modal Popup is re rendering

I have written a Lightning Component of Modal Popup to show popup in home page of public community website , it will be shown whenever user visits the website. 

My requirement is here is popup window should show only once when the user visits the website for the first time.
But the issue is , whenever the user visits to the website or other sub pages of the site and come back to the home page, again the popup appears. 
In this we want to set the modal popup should be shown only for the first time when the users visit the site , 
as in the popup we are just making sure the user is aware of Privacy policy .
Once, the user clicks on OK, everytime the Privacy policy popup should not get open when the user visits the site and home page.

code
popup.cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
    <aura:handler  name="init" value="{!this}" action="{!c.showInfoToast}"/>   
    <div>
        <lightning:button 
                          variant="brand"
                          onclick="{!c.showInfoToast}"
                          >
        </lightning:button>
        
    </div>
</aura:component>

popupcontroller.js

({
    
   
    showInfoToast : function(component, event, helper) {
        var toastEvent = $A.get("e.force:showToast");
        toastEvent.setParams({
            title : 'Info ',
            
            messageTemplate: 'This website use cookies. For details see  {1} ',
            messageTemplateData: ['Salesforce', {
                url: 'www.privacypolicy.com'',
                label: 'Privacy Policy',
            }],
            duration:' 5000',
            key: 'info_alt',
            type: 'info',
            mode: 'sticky'
        });
        toastEvent.fire();
    },
    
    doInit: function(component, event, helper) { 
 var temperorySession = localStorage.getItem('tempSession');
  if(temperorySession == '1')
        {  
      console.log('===== in If');
            component.set("v.isModalOpen", false);
  }
        else
        {
      console.log('===== in else');
      component.set("v.isModalOpen", true);
  }
   localStorage.setItem('tempSession', '1');
 }
    
    
})
 
Debbie EngelmeyerDebbie Engelmeyer
I think you will need to store the fact that the user has seen the popup in a protected object: an object only visible within the namespace of your package, or in a custom field.