sgobotta / ex_commerce

Elixir E-Commerce prototype project
GNU Affero General Public License v3.0
4 stars 0 forks source link

Fix avatar and banner uploads for the shop liveview #49

Open sgobotta opened 1 year ago

sgobotta commented 1 year ago

Describe the bug:

A clear and concise description of what the bug is.

To Reproduce:

Steps to reproduce the behavior:

  1. Go to the shop edit form, either from the shop list liveview or the show shop liveview
  2. Choose a file for the avatar and a file for the banner
  3. Click Save
  4. An error appears in the console:
    [error] GenServer #PID<0.797.0> terminating
    ** (stop) exited in: GenServer.call(#PID<0.820.0>, :consume_start, :infinity)
      ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
      (elixir 1.12.3) lib/gen_server.ex:1024: GenServer.call/3
      (phoenix_live_view 0.18.11) lib/phoenix_live_view/upload_channel.ex:15: Phoenix.LiveView.UploadChannel.consume/3
      (elixir 1.12.3) lib/enum.ex:1582: Enum."-map/2-lists^map/1-0-"/2
      (ex_commerce 0.1.0) lib/ex_commerce_web/live/live_form_helpers.ex:163: ExCommerceWeb.LiveFormHelpers.consume_uploads/5
      (ex_commerce 0.1.0) lib/ex_commerce_web/live/shop_live/form_component.ex:236: ExCommerceWeb.ShopLive.FormComponent.consume_media_files/2
      (ex_commerce 0.1.0) lib/ex_commerce/marketplaces.ex:164: ExCommerce.Marketplaces.after_save/2
      (ex_commerce 0.1.0) lib/ex_commerce_web/live/shop_live/form_component.ex:103: ExCommerceWeb.ShopLive.FormComponent.save_shop/3
      (phoenix_live_view 0.18.11) lib/phoenix_live_view/channel.ex:618: anonymous fn/4 in Phoenix.LiveView.Channel.inner_component_handle_event/4
      (telemetry 0.4.3) /home/sann/Documents/proyectos/ex_commerce/repos/ex_commerce/deps/telemetry/src/telemetry.erl:272: :telemetry.span/3
      (phoenix_live_view 0.18.11) lib/phoenix_live_view/diff.ex:206: Phoenix.LiveView.Diff.write_component/4
      (phoenix_live_view 0.18.11) lib/phoenix_live_view/channel.ex:541: Phoenix.LiveView.Channel.component_handle_event/6
      (stdlib 3.14.2) gen_server.erl:689: :gen_server.try_dispatch/4
      (stdlib 3.14.2) gen_server.erl:765: :gen_server.handle_msg/6
      (stdlib 3.14.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
    Last message: %Phoenix.Socket.Message{event: "event", join_ref: "17", payload: %{"cid" => 3, "event" => "save", "type" => "form", "value" => "_method=put&_csrf_token=Oz0iEVQDDRw3EHJdBw8IAAAgeh4CPjdqVNNP1gyHYiK2vEcaLPKp0JCG&shop%5Bname%5D=Let+it+beer+Palermo&shop%5Bslug%5D=let-it-beer-palermo&shop%5Bdescription%5D=A+beer+in+the+life%3A+craft+beer&shop%5Btelephone%5D=%2B54+9+11+2345+6789&shop%5Bbanner_message%5D=We+deliver+fresh+products+from+Mondays+to+Sundays+between+9%3A00+a.m.+and+11%3A00+p.m.&shop%5Baddress%5D=Rep%C3%BAblica+de+Eslovenia+1831%2C+C1426CZE+CABA"}, ref: "43", topic: "lv:phx-FzyrmboYBOHOTgFC"}
  5. Refresh the browser and the avatar should have a picture but the banner doesn't. The avatar is uploaded to cloudinary while the banner is not. The state for the banner is null

Expected behavior:

A clear and concise description of what you expected to happen.

Both photos should be uploaded. If cloudinary is not available then at least both photos should remain saved in uploads and shown in the page after the Save button is clicked.

System information (please complete the following information):

Run: elixir --version to get the Elixir and Erlang/OTP version.

sgobotta commented 1 year ago

The watcher for media files (png, jpg, jpeg) in the Endpoint reloaded once the first image was uploaded, thus the thread that was supposed to consume the second file raised. It's fixed.