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

Fixed popup dismiss issue with recurring visitors option #2347

Merged
merged 3 commits into from
Aug 28, 2024
Merged
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
14 changes: 9 additions & 5 deletions src/blocks/frontend/popup/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class PopupBlock {
this.happened = false;
this.storageKey = 'otter-popup-dismiss';

const { dismiss, anchor } = element.dataset;
const { dismiss = 0, anchor } = element.dataset;

if ( this.isItemDismissed() && dismiss && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) {
if ( this.isItemDismissed() && 0 <= dismiss && ! anchor && ! Boolean( window.themeisleGutenberg?.isPreview ) ) {
return;
}

Expand Down Expand Up @@ -50,11 +50,11 @@ class PopupBlock {
}

dismissModal() {
const { dismiss, anchor } = this.element.dataset;
const { dismiss = 0, anchor } = this.element.dataset;

const { id } = this.element;

if ( ! dismiss || ! id || anchor ) {
if ( 0 < dismiss || ! id || anchor ) {
return false;
}

Expand All @@ -81,14 +81,18 @@ class PopupBlock {

isItemDismissed() {
const { id } = this.element;
const { dismiss = 0 } = this.element.dataset;

const cache = JSON.parse( localStorage.getItem( this.storageKey ) ?? '[]' ) || [];
const inCache = cache.filter( ( entry: { modalID: string; }) => entry.modalID === id );

if ( 0 === inCache.length ) {
return false;
}

if ( 0 === parseInt( dismiss ) && 0 < inCache.length ) {
return true;
}

const item = inCache[ 0 ];
const now = new Date();

Expand Down
Loading