-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
break ticker table out to LiveComponent
- Loading branch information
Showing
7 changed files
with
69 additions
and
80 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
defmodule BasketWeb.Components.TickerBarTable do | ||
@moduledoc """ | ||
Allows the user to search for and add a ticker to the table. Will make an HTTP call | ||
if the ticker list is not populated, otherwise it will pull the list from the cache. | ||
""" | ||
|
||
use Surface.LiveComponent | ||
|
||
import BasketWeb.CoreComponents | ||
|
||
prop rows, :list, default: [] | ||
|
||
attr :id, :string, required: true | ||
attr :class, :string, default: nil | ||
|
||
def mount(socket) do | ||
socket = assign(socket, basket: []) | ||
|
||
{:ok, socket} | ||
end | ||
|
||
def render(assigns) do | ||
~F""" | ||
<div> | ||
<.table id="ticker-list" rows={@rows}> | ||
<:col :let={ticker} key="S" label="ticker">{value_from_ticker_bar(ticker["S"])}</:col> | ||
<:col :let={ticker} key="o" label="open">{value_from_ticker_bar(ticker["o"])}</:col> | ||
<:col :let={ticker} key="h" label="high">{value_from_ticker_bar(ticker["h"])}</:col> | ||
<:col :let={ticker} key="l" label="low">{value_from_ticker_bar(ticker["l"])}</:col> | ||
<:col :let={ticker} key="c" label="close">{value_from_ticker_bar(ticker["c"])}</:col> | ||
<:col :let={ticker} key="v" label="volume">{value_from_ticker_bar(ticker["v"])}</:col> | ||
<:col :let={ticker} key="t" label="timestamp">{value_from_ticker_bar(ticker["t"])}</:col> | ||
<:col :let={ticker} label="remove"> | ||
<.button | ||
phx-click="ticker-remove" | ||
phx-value-ticker={value_from_ticker_bar(ticker["S"])} | ||
class="bg-red-600" | ||
> | ||
X | ||
</.button> | ||
</:col>" | ||
</.table> | ||
</div> | ||
""" | ||
end | ||
|
||
defp value_from_ticker_bar(ticker_bar), do: elem(ticker_bar, 0) | ||
end |
This file contains 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
This file contains 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