Skip to content

Commit

Permalink
Set click event listener on grid-item-container and debug postId
Browse files Browse the repository at this point in the history
  • Loading branch information
jstncno committed May 17, 2024
1 parent eceea1f commit bb0951d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/components/GridItem.astro
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,16 @@ const {class: className = '', postId, thumbnail} = Astro.props;
<script>
import {navigate} from 'astro:transitions/client';

class GridItemContainer extends HTMLElement {
constructor() {
super();
const inner = this.querySelector('img');
class GridItemContainer extends HTMLElement {
constructor() {
super();
const postId = this.dataset.post;
if (inner && postId) {
inner.addEventListener('click', () => open(postId));
console.debug(postId);
if (postId) {
this.addEventListener('click', () => navigate(postId));
}
}
}

function open(route: string) {
console.debug(route);
navigate(route);
}
}

customElements.define('grid-item-container', GridItemContainer);
customElements.define('grid-item-container', GridItemContainer);
</script>

0 comments on commit bb0951d

Please sign in to comment.