Skip to content

Commit a2f2383

Browse files
committed
refactor: streamline achievement assignment logic in user dashboard
- Simplified the achievement processing logic by consolidating the Enum.reduce_while function. - Updated the assignment of achievements to exclude completed ones, enhancing the clarity of the dashboard state. - Improved code readability and maintainability through refactoring.
1 parent d23d291 commit a2f2383

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lib/algora_web/live/user/dashboard_live.ex

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,21 @@ defmodule AlgoraWeb.User.DashboardLive do
290290
]
291291

292292
{achievements, _} =
293-
Enum.reduce_while(achievements, {[], false}, fn
294-
{status_fn, name, path}, {acc, found_current} ->
295-
id = Function.info(status_fn)[:name]
296-
status = status_fn.(socket)
297-
298-
result =
299-
cond do
300-
found_current -> {acc ++ [%{id: id, status: :upcoming, name: name, path: path}], found_current}
301-
status == :completed -> {acc ++ [%{id: id, status: status, name: name, path: path}], false}
302-
true -> {acc ++ [%{id: id, status: :current, name: name, path: path}], true}
303-
end
304-
305-
{:cont, result}
293+
Enum.reduce_while(achievements, {[], false}, fn {status_fn, name, path}, {acc, found_current} ->
294+
id = Function.info(status_fn)[:name]
295+
status = status_fn.(socket)
296+
297+
result =
298+
cond do
299+
found_current -> {acc ++ [%{id: id, status: :upcoming, name: name, path: path}], found_current}
300+
status == :completed -> {acc ++ [%{id: id, status: status, name: name, path: path}], false}
301+
true -> {acc ++ [%{id: id, status: :current, name: name, path: path}], true}
302+
end
303+
304+
{:cont, result}
306305
end)
307306

308-
assign(socket, :achievements, achievements)
307+
assign(socket, :achievements, Enum.reject(achievements, &(&1.status == :completed)))
309308
end
310309

311310
defp incomplete?(achievements, id) do

0 commit comments

Comments
 (0)