diff --git a/lib/digistab_store/store.ex b/lib/digistab_store/store.ex index b2ee592..d82b174 100644 --- a/lib/digistab_store/store.ex +++ b/lib/digistab_store/store.ex @@ -55,8 +55,10 @@ defmodule DigistabStore.Store do end def list_products(_preload? = true) do - list_products() - |> Repo.preload([:tags, :status, :category, :photos]) + Product + |> order_by([p], p.inserted_at) + |> preload([:tags, :status, :category, :photos]) + |> Repo.all() end @doc """ @@ -110,8 +112,6 @@ defmodule DigistabStore.Store do """ @spec search_products(binary()) :: [Product.t()] def search_products(product_name) do - # Just for User Experience - :timer.sleep(1000) search_term = "%#{product_name}%" from(p in Product, @@ -179,8 +179,10 @@ defmodule DigistabStore.Store do end def get_product!(id, _preload? = true) do - get_product!(id) - |> preload_product!() + Product + |> where(id: ^id) + |> preload([:tags, :status, :category, :photos]) + |> Repo.one!() end @doc """ @@ -269,7 +271,7 @@ defmodule DigistabStore.Store do |> Product.changeset(attrs) end - def change_product_price(%Product{} = product, attrs \\ %{}) do + def change_product_price(%Product{} = product, attrs \\ %{}) do product |> Repo.preload([:status, :category]) |> Product.price_changeset(attrs) diff --git a/lib/digistab_store_web/live/products/index.ex b/lib/digistab_store_web/live/products/index.ex index 21b35b0..e2ded6e 100644 --- a/lib/digistab_store_web/live/products/index.ex +++ b/lib/digistab_store_web/live/products/index.ex @@ -86,8 +86,6 @@ defmodule DigistabStoreWeb.ProductLive.Index do end def handle_info({:handle_category, id}, socket) do - :timer.sleep(1000) - socket = socket |> assign(loading: false)