浏览代码

Fix sorting function

theenglishway (time) 4 年之前
父节点
当前提交
74d4652523
共有 1 个文件被更改,包括 12 次插入10 次删除
  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