-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule ZoonkWeb.Components.Content.FillOptions do | ||
@moduledoc false | ||
use ZoonkWeb, :html | ||
|
||
attr :options, :list, required: true | ||
attr :selected_segments, :list, required: true | ||
|
||
def fill_options(assigns) do | ||
Check warning on line 8 in lib/content/course_live/components/fill_options.ex GitHub Actions / test
Check warning on line 8 in lib/content/course_live/components/fill_options.ex GitHub Actions / test
|
||
~H""" | ||
<div class="mt-8 flex flex-wrap gap-2"> | ||
<button | ||
:for={option <- @options} | ||
disabled={disabled?(option, @selected_segments)} | ||
type="button" | ||
phx-click="select-fill-option" | ||
phx-value-option-id={option.id} | ||
class={[ | ||
"rounded-lg bg-white p-4 text-slate-700 shadow-md hover:bg-slate-100 focus:outline-none focus:ring-2 focus:ring-slate-400", | ||
disabled?(option, @selected_segments) && "cursor-not-allowed opacity-50" | ||
]} | ||
> | ||
<%= option.title %> | ||
</button> | ||
</div> | ||
""" | ||
end | ||
|
||
def disabled?(option, selected_segments), do: Enum.member?(selected_segments, option) | ||
Check warning on line 28 in lib/content/course_live/components/fill_options.ex GitHub Actions / test
Check warning on line 28 in lib/content/course_live/components/fill_options.ex GitHub Actions / test
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
defmodule ZoonkWeb.Components.Content.FillStep do | ||
@moduledoc false | ||
use ZoonkWeb, :html | ||
|
||
attr :segments, :list, required: true | ||
attr :selected_segments, :list, required: true | ||
|
||
def fill_step(assigns) do | ||
Check warning on line 8 in lib/content/course_live/components/fill_step.ex GitHub Actions / test
Check warning on line 8 in lib/content/course_live/components/fill_step.ex GitHub Actions / test
|
||
~H""" | ||
<div id="fill-step" class="flex flex-wrap items-center gap-2"> | ||
<button | ||
:for={{segment, index} <- Enum.with_index(get_segments(@segments, @selected_segments))} | ||
type="button" | ||
disabled={!selectable?(@selected_segments, index)} | ||
phx-click="remove-segment" | ||
phx-value-index={index} | ||
class={["p-2", selectable?(@selected_segments, index) && "semibold rounded-md bg-slate-50"]} | ||
> | ||
<%= segment %> | ||
</button> | ||
</div> | ||
""" | ||
end | ||
|
||
defp get_segments(segments, selected) do | ||
segments | ||
|> Enum.with_index() | ||
|> Enum.map(fn {segment, idx} -> | ||
get_segment(segment, idx, selected) | ||
end) | ||
end | ||
|
||
defp get_segment(nil, idx, selected), do: get_segment(Enum.at(selected, idx)) | ||
defp get_segment(segment, _idx, _selected), do: segment | ||
|
||
defp get_segment(nil), do: "_ _ _ _ _ _ _ _" | ||
defp get_segment(option), do: option.title | ||
|
||
defp selectable?(segments, index), do: !is_nil(Enum.at(segments, index)) | ||
end |