|
1 | 1 | defmodule LogflareWeb.Backends.Components do |
2 | 2 | use Phoenix.Component |
3 | 3 |
|
| 4 | + # TODO: Extract common parts |
| 5 | + |
| 6 | + # def text_input(assigns) do |
| 7 | + # ~H""" |
| 8 | + # <div class="form-group"> |
| 9 | + # {label(@form, @id, @label)} |
| 10 | + # {text_input(@form, @id, class: "form-control")} |
| 11 | + # <small class="form-text text-muted"> |
| 12 | + # {@description} |
| 13 | + # </small> |
| 14 | + # </div> |
| 15 | + # """ |
| 16 | + # end |
| 17 | + |
| 18 | + # def select_input(assigns) do |
| 19 | + # ~H""" |
| 20 | + # <div class="form-group"> |
| 21 | + # {label(@form, @id, @label)} |
| 22 | + # {text_input(@form, @id, class: "form-control")} |
| 23 | + # <small class="form-text text-muted"> |
| 24 | + # {@description} |
| 25 | + # </small> |
| 26 | + # </div> |
| 27 | + # """ |
| 28 | + # end |
| 29 | + |
4 | 30 | attr :status, :atom, values: [:ok, :error, :loading] |
5 | 31 |
|
6 | 32 | def status_indicator(assigns) do |
7 | | - case assigns.status do |
8 | | - :ok -> ~H|<.indicator icon="check" color="green-500" )} />| |
9 | | - :error -> ~H|<.indicator icon="times" color="red-500" )} />| |
10 | | - :loading -> ~H|<.indicator icon="spinner" color="white" animation="tw-animate-spin" )} />| |
11 | | - nil -> ~H"" |
12 | | - end |
| 33 | + ~H""" |
| 34 | + <.async_result :let={_ok} assign={@status}> |
| 35 | + <:loading><.indicator icon="spinner" color="tw-text-white" animation="tw-animate-spin" )} /></:loading> |
| 36 | + <:failed :let={{atom, reason}}> |
| 37 | + <% reason = if atom == :error, do: reason, else: "Internal error" %> |
| 38 | + <.indicator icon="times" color="tw-text-red-500" )} /> <span class="inline-block tw-mx-15">{reason}</span> |
| 39 | + </:failed> |
| 40 | + <.indicator icon="check" color="tw-text-green-500" )} /> |
| 41 | + </.async_result> |
| 42 | + """ |
13 | 43 | end |
14 | 44 |
|
15 | 45 | defp indicator(assigns) do |
16 | 46 | animation = if assigns[:animation], do: assigns.animation, else: "" |
17 | | - color = if assigns[:color], do: "tw-text-#{assigns.color}", else: "" |
18 | | - assigns = assign(assigns, color: color, animation: animation) |
| 47 | + assigns = assign(assigns, animation: animation) |
19 | 48 |
|
20 | 49 | ~H""" |
21 | 50 | <i class={"inline-block fas fa-#{@icon} #{@color} tw-align-middle tw-text-2xl #{@animation}"}></i> |
|
0 commit comments