Kaynağa Gözat

Fix sorting function

theenglishway (time) 4 yıl önce
ebeveyn
işleme
74d4652523
1 değiştirilmiş dosya ile 12 ekleme ve 10 silme
  1. 12 10
      lib/vaccins_web/live/index.ex

+ 12 - 10
lib/vaccins_web/live/index.ex

@@ -98,16 +98,18 @@ defmodule VaccinsWeb.IndexLive do
        ) do
     locations
     |> Enum.sort(fn e1, e2 ->
-      e1_has_early_spot? = e1 in with_early_slots
-      e1_has_spot? = e1 in with_slots
-      e2_has_early_spot? = e2 in with_early_slots
-      e2_has_spot? = e2 in with_slots
-
-      cond do
-        e1_has_early_spot? and not e2_has_early_spot? -> true
-        e1_has_spot? and not e2_has_early_spot? and not e2_has_spot? -> true
-        true -> false
-      end
+      e1_has_early_spot? = e1.id in with_early_slots
+      e1_has_spot? = e1.id in with_slots
+      e2_has_early_spot? = e2.id in with_early_slots
+      e2_has_spot? = e2.id in with_slots
+
+      res =
+        cond do
+          e2_has_early_spot? -> false
+          e2_has_spot? and not e1_has_early_spot? -> false
+          e2_has_spot? and e1_has_spot? -> false
+          true -> true
+        end
     end)
   end
 end