Skip to content

Commit

Permalink
Fix small issue
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Aug 10, 2023
1 parent 9531d16 commit 8d10587
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/atomic_web/live/board_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule AtomicWeb.BoardLive.Index do

alias Atomic.Board
alias Atomic.Organizations
import AtomicWeb.ViewUtils

@impl true
def mount(_params, _session, socket) do
Expand All @@ -12,11 +13,9 @@ defmodule AtomicWeb.BoardLive.Index do
@impl true
def handle_params(%{"organization_id" => id}, _, socket) do
board = Board.get_organization_board_by_year("2023/2024", id)
board_departments = []

if board do
^board_departments = Board.get_board_departments_by_board_id(board.id)
end
board_departments =
append_if([], board != nil, Board.get_board_departments_by_board_id(board.id))

organization = Organizations.get_organization!(id)
role = Organizations.get_role(socket.assigns.current_user.id, id)
Expand Down
2 changes: 1 addition & 1 deletion lib/atomic_web/live/board_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<ol class="z-100 flex flex-col items-center justify-center">
<img class="mx-auto h-24 w-24 rounded-full" src="https://images.unsplash.com/photo-1519244703995-f4e0f30006d5?ixlib=rb-=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=1024&h=1024&q=80" alt="" />
<h3 class="mt-6 text-base font-semibold leading-7 tracking-tight text-gray-900"><%= user_organization.user.name %></h3>
<p class="text-sm leading-6 text-gray-600"><%= user_organization.title %></p>
<p class="text-sm leading-6 text-gray-600"><%= user_organization.role %></p>
</ol>
<% end %>
</div>
Expand Down
25 changes: 25 additions & 0 deletions lib/atomic_web/views/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,31 @@ defmodule AtomicWeb.ViewUtils do
|> URI.to_string()
end

@doc ~S"""
Appends an item to a list when a condition is true
## Examples
iex> append_if([1, 2, 3], true, [4])
[1, 2, 3, 4]
iex> append_if([1, 2, 3], false, [4])
[1, 2, 3]
iex> append_if([1, 2, 3], false, [4])
[1, 2, 3]
iex> append_if([1, 2, 3], true, [4, 5, 6])
[1, 2, 3, 4, 5, 6]
"""
def append_if(list, condition, item) when is_list(item) do
if condition do
list ++ item
else
list
end
end

@doc ~S"""
Returns an error message for a given error
Expand Down

0 comments on commit 8d10587

Please sign in to comment.