Skip to content

Commit

Permalink
add sanitized firehose
Browse files Browse the repository at this point in the history
  • Loading branch information
cbh123 committed Sep 28, 2023
1 parent 43a2867 commit 8a0c390
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/emoji/predictions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ defmodule Emoji.Predictions do
)
end

def list_firehose_predictions() do
def list_latest_safe_predictions(limit) do
Repo.all(
from p in Prediction,
where: not is_nil(p.no_bg_output),
where: not is_nil(p.no_bg_output) and p.moderation_score <= 5,
order_by: [desc: p.inserted_at],
limit: 100
limit: ^limit
)
end

Expand Down
7 changes: 6 additions & 1 deletion lib/emoji_web/components/components.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
defmodule EmojiWeb.Components do
import EmojiWeb.Gettext
use EmojiWeb, :html

attr :class, :string, default: nil

def emoji(assigns) do
~H"""
<div class={@class}>
<.image id={@id} prediction={@prediction} />
<.feedback id={@id} prediction={@prediction} />
</div>
"""
end

Expand All @@ -16,7 +21,7 @@ defmodule EmojiWeb.Components do

defp image(assigns) do
~H"""
<div class="group aspect-h-7 aspect-w-10 block w-full overflow-hidden rounded-lg bg-gray-100 focus-within:ring-2 focus-within:ring-black-500 focus-within:ring-offset-2 focus-within:ring-offset-gray-100">
<div class="group aspect-h-10 aspect-w-10 block overflow-hidden rounded-lg bg-gray-100 focus-within:ring-2 focus-within:ring-black-500 focus-within:ring-offset-2 focus-within:ring-offset-gray-100">
<%= if is_nil(@prediction.emoji_output) and is_nil(@prediction.no_bg_output) do %>
<div class="flex items-center justify-center h-36">
<p class="animate-pulse ">Loading...</p>
Expand Down
3 changes: 2 additions & 1 deletion lib/emoji_web/live/home_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ defmodule EmojiWeb.HomeLive do
|> assign(local_user_id: nil)
|> assign(remove_bg: true)
|> stream(:my_predictions, [])
|> stream(:featured_predictions, Predictions.list_featured_predictions())}
|> stream(:featured_predictions, Predictions.list_featured_predictions())
|> stream(:latest_predictions, Predictions.list_latest_safe_predictions(9))}
end

def handle_event("thumbs-up", %{"id" => id}, socket) do
Expand Down
11 changes: 11 additions & 0 deletions lib/emoji_web/live/home_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@
</li>
</ul>
</div>
<.header class="mt-12">Latest</.header>
<ul
id="latest-predictions"
phx-update="stream"
role="list"
class="mt-6 flex overflow-x-scroll gap-x-4 sm:gap-x-6"
>
<li :for={{id, prediction} <- @streams.latest_predictions} id={id} class="relative flex-none">
<EmojiWeb.Components.emoji id={id} class="w-52" prediction={prediction} />
</li>
</ul>

<.header class="mt-12">Featured</.header>
<ul
Expand Down

0 comments on commit 8a0c390

Please sign in to comment.