Skip to content

Commit

Permalink
fix: always initiate js (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasNorin authored Nov 20, 2024
1 parent 9c6482d commit e8fe57f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions source/js/like-posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import UserStorage from './front/storage/userStorage';
import LocalStorage from './front/storage/localStorage';

declare const likedPosts : {
currentUser: number,
currentUser: number|string,
likedPostsMeta: any
};

declare const wpApiSettings: WpApiSettings;

document.addEventListener('DOMContentLoaded', () => {
const localWpApiSettings = wpApiSettings;
let likeStorage = likedPosts && likedPosts.currentUser !== 0 && likedPosts.likedPostsMeta && localWpApiSettings ? new UserStorage(localWpApiSettings, likedPosts.currentUser, likedPosts.likedPostsMeta) : new LocalStorage();
let likeStorage = likedPosts && likedPosts.currentUser !== '0' && likedPosts.likedPostsMeta && localWpApiSettings ? new UserStorage(localWpApiSettings, likedPosts.currentUser as number, likedPosts.likedPostsMeta) : new LocalStorage();

initializeLikedCounter(likeStorage);
new Like(likeStorage);
Expand Down
8 changes: 3 additions & 5 deletions source/php/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ public function enqueueFrontend()

$user = wp_get_current_user();

if (!empty($user->ID)) {
$userLikedPosts = get_user_meta($user->ID, 'likedPosts', true);
$userLikedPosts = get_user_meta($user->ID, 'likedPosts', true);

wp_localize_script('like-posts-js', 'likedPosts', ['currentUser' => $user->ID, 'likedPostsMeta' => (object) $userLikedPosts]);
wp_localize_script('like-posts-js', 'likedPosts', ['currentUser' => $user->ID, 'likedPostsMeta' => (object) $userLikedPosts]);

wp_enqueue_script('like-posts-js');
}
wp_enqueue_script('like-posts-js');
}

/**
Expand Down

0 comments on commit e8fe57f

Please sign in to comment.