Skip to content

Commit

Permalink
chore: on click on product to show it, it scrolls to the top of the page
Browse files Browse the repository at this point in the history
  • Loading branch information
ali1ariel committed Dec 1, 2024
1 parent e00946e commit 507f077
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ import Uploaders from "./uploaders";
window.Alpine = Alpine;
Alpine.start()

window.addEventListener("scroll-top", () => {
window.scrollTo({
top: 0,
behavior: "smooth"
});
});


let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
let liveSocket = new LiveSocket("/live", Socket, {
longPollFallbackMs: 2500,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ defmodule DigistabStoreWeb.Components.ProductCard do
<div class="relative">
<div class="aspect-w-16 aspect-h-9">
<%= if @product.photos && Enum.any?(@product.photos) do %>
<.link patch={~p"/products/#{@product.id}"}>
<div
phx-click={JS.patch(~p"/products/#{@product.id}") |> JS.dispatch("scroll-top")}
class="cursor-pointer"
>
<img
src={List.first(@product.photos).url}
alt={@product.name}
class="w-full h-48 object-cover object-center rounded-lg transition-all duration-300 hover:scale-105"
loading="lazy"
/>
</.link>
</div>
<% else %>
<div class="flex items-center justify-center w-full h-48 bg-gradient-to-br from-gray-100 to-gray-200 rounded-lg animate-pulse">
<.icon name="hero-photo" class="w-12 h-12 text-gray-400" />
Expand Down

0 comments on commit 507f077

Please sign in to comment.