From 391c754a423ecbe5dfc42c8b0bc44decb4c3fa04 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 19 Dec 2019 01:51:21 -0500 Subject: [PATCH] fix lingering galleries bugs --- assets/css/common/layout.scss | 2 +- lib/philomena/galleries.ex | 12 ++++++++---- .../image/subscription/_subscription.html.slime | 9 +++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/assets/css/common/layout.scss b/assets/css/common/layout.scss index 974d266f..410b7d7a 100644 --- a/assets/css/common/layout.scss +++ b/assets/css/common/layout.scss @@ -241,7 +241,7 @@ nav { width: 100%; /* Do not use a descendant selector here as it affects dropdowns */ - > a { + > a, span { text-align: center; flex: 1 1 auto; padding: 0 1vw; /* Having smaller padding makes it harder to click the right link on small mobile screens */ diff --git a/lib/philomena/galleries.ex b/lib/philomena/galleries.ex index f1cc04e0..f2b0d075 100644 --- a/lib/philomena/galleries.ex +++ b/lib/philomena/galleries.ex @@ -155,16 +155,20 @@ defmodule Philomena.Galleries do def remove_image_from_gallery(gallery, image) do Multi.new() |> Multi.run(:interaction, fn repo, %{} -> - %Interaction{gallery_id: gallery.id, image_id: image.id} - |> repo.delete() + {count, nil} = + Interaction + |> where(gallery_id: ^gallery.id, image_id: ^image.id) + |> repo.delete_all() + + {:ok, count} end) - |> Multi.run(:gallery, fn repo, %{} -> + |> Multi.run(:gallery, fn repo, %{interaction: interaction_count} -> now = DateTime.utc_now() {count, nil} = Gallery |> where(id: ^gallery.id) - |> repo.update_all(inc: [image_count: -1], set: [updated_at: now]) + |> repo.update_all(inc: [image_count: -interaction_count], set: [updated_at: now]) {:ok, count} end) diff --git a/lib/philomena_web/templates/image/subscription/_subscription.html.slime b/lib/philomena_web/templates/image/subscription/_subscription.html.slime index bd5b832d..4f62481c 100644 --- a/lib/philomena_web/templates/image/subscription/_subscription.html.slime +++ b/lib/philomena_web/templates/image/subscription/_subscription.html.slime @@ -9,15 +9,12 @@ elixir: span#js-subscription-target a.js-subscription-link href=watch_path class=watch_class data-remote="true" data-method="post" i.fa.fa-bell> - span.hide-mobile - ' Subscribe + ' Subscribe a.js-subscription-link href=unwatch_path class=unwatch_class data-remote="true" data-method="delete" i.fa.fa-bell-slash> - span.hide-mobile - ' Unsubscribe + ' Unsubscribe - else a href=Routes.pow_session_path(@conn, :new) i.fa.fa-bell> - span.hide-mobile - ' Subscribe \ No newline at end of file + ' Subscribe