Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules/
*.lock
.parcel-cache/
*.css.map
*.js.map
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v23.11.0
Binary file added assets/icons/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions assets/scripts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import Toastify from 'toastify-js';

const favoritePosts = {
init() {
if (!this.component) return;

this.addEventListeners();
},

addEventListeners() {
this.component.addEventListener('click', this.handleClick.bind(this));
},

async favoritePost() {
// @ts-ignore
fetch(wpApiSettings.root + wpApiSettings.rest_namespace + '/favorite-posts', {
method: 'POST',
body: JSON.stringify({
post_id: this.component.dataset.postId
}),
headers: {
'Content-Type': 'application/json',
// @ts-ignore
'X-WP-Nonce': wpApiSettings.nonce
}
})
.then(response => response.json())
.then(data => {
Toastify({ text: data.message }).showToast();

this.component.classList.add('is-favorite');
})
.catch(error => {
Toastify({
text: 'Failed to add favorite post',
className: 'error',
style: {
background: 'linear-gradient(to right, #ff0000, #ff4747)',
}
}).showToast();
});
},

async handleClick() {
!!this.dialogLoader && this.dialogLoader.showModal();

if (this.component.classList.contains('is-favorite')) {
await this.removeFavoritePost();
} else {
await this.favoritePost();
}

!!this.dialogLoader && this.dialogLoader.close();
},

async removeFavoritePost() {
// @ts-ignore
fetch(wpApiSettings.root + wpApiSettings.rest_namespace + '/favorite-posts', {
method: 'DELETE',
body: JSON.stringify({
post_id: this.component.dataset.postId
}),
headers: {
'Content-Type': 'application/json',
// @ts-ignore
'X-WP-Nonce': wpApiSettings.nonce
}
})
.then(response => response.json())
.then(data => {
Toastify({ text: data.message }).showToast();

this.component.classList.remove('is-favorite');
})
.catch(error => {
Toastify({
text: 'Failed to remove favorite post',
className: 'error',
style: {
background: 'linear-gradient(to right, #ff0000, #ff4747)',
}
}).showToast();
});
},

component: document.querySelector('.favorite-post-button'),
dialogLoader: document.querySelector('#dialog-loader'),
favoritePostsPopover: document.querySelector('#favorite-posts-popover'),
}

favoritePosts.init();
61 changes: 61 additions & 0 deletions assets/scss/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@import './loader.scss';

.favorite-post-button {
background: none;
border: none;
cursor: pointer;
display: block;
outline: none;
opacity: 0.5;
padding: 0;
transition: all 0.3s ease-in-out;

&:hover,
&.is-favorite {
opacity: 1;
transform: scale(2);
}

img {
height: 32px;
pointer-events: none;
}
}

#dialog-loader {
background-color: transparent;
border: none;
opacity: 0;
padding: 150px;
transform: scaleY(0);
transition: opacity 0.7s ease-out,
transform 0.7s ease-out,
overlay 0.7s ease-out allow-discrete,
display 0.7s ease-out allow-discrete;

&:open {
opacity: 1;
transform: scaleY(1);
}

/* Styles the *starting point* of the open state */
/* Must come AFTER the dialog:open rule due to equal specificity */
@starting-style {
&:open {
opacity: 0;
transform: scaleY(0);
}
}

&::backdrop {
background-color: rgba(255, 255, 255, 0);
transition: background-color 0.7s ease-out allow-discrete;
}

&:open::backdrop {
background-color: rgba(255, 255, 255, 0.5);
backdrop-filter: blur(10px);
}

.loader { width: 96px; }
}
25 changes: 25 additions & 0 deletions assets/scss/loader.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* HTML: <div class="loader"></div> */
.loader {
width: 50px;
aspect-ratio: 1;
color:#dc1818;
background:
radial-gradient(circle at 60% 65%, currentColor 62%, #0000 65%) top left,
radial-gradient(circle at 40% 65%, currentColor 62%, #0000 65%) top right,
linear-gradient(to bottom left, currentColor 42%,#0000 43%) bottom left ,
linear-gradient(to bottom right,currentColor 42%,#0000 43%) bottom right;
background-size: 50% 50%;
background-repeat: no-repeat;
position: relative;
}
.loader:after {
content: "";
position: absolute;
inset: 0;
background: inherit;
opacity: 0.4;
animation: l3 1s infinite;
}
@keyframes l3 {
to {transform:scale(1.8);opacity:0}
}
87 changes: 87 additions & 0 deletions dist/index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading