Created
July 17, 2020 12:56
-
-
Save benvp/73b08d04f32b31a4e4a019efa097e08c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_event("select", %{"id" => id}, socket) do | |
item = Items.get_item(id) | |
selected = Enum.uniq_by([item] ++ socket.assigns.selected, & &1.id) | |
suggestions = filter_selected(socket.assigns.suggestions, selected) | |
socket = | |
assign(socket, | |
selected: selected, | |
suggestions: suggestions | |
) | |
{:noreply, socket} | |
end | |
defp filter_selected(items, selected) do | |
Enum.filter(items, fn i -> !Enum.any?(selected, fn s -> i.id == s.id end) end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment