Skip to content

Commit

Permalink
Update the twitter handles approval dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff committed Nov 3, 2023
1 parent fc42d03 commit 571170c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
13 changes: 10 additions & 3 deletions lib/sanbase/monitored_twitter_handle/monitored_twitter_handle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Sanbase.MonitoredTwitterHandle do
end

def is_handle_monitored(handle) do
handle = String.downcase(handle)
handle = normalize_handle(handle)
query = from(m in __MODULE__, where: m.handle == ^handle)

{:ok, Repo.exists?(query)}
Expand All @@ -48,7 +48,7 @@ defmodule Sanbase.MonitoredTwitterHandle do
{:ok, Sanbase.MonitoredTwitterHandle.t()} | {:error, String.t()}
def add_new(handle, user_id, origin, notes) do
%__MODULE__{}
|> change(%{handle: String.downcase(handle), user_id: user_id, origin: origin, notes: notes})
|> change(%{handle: normalize_handle(handle), user_id: user_id, origin: origin, notes: notes})
|> validate_required([:handle, :user_id, :origin])
|> unique_constraint(:handle)
|> Repo.insert()
Expand Down Expand Up @@ -85,13 +85,20 @@ defmodule Sanbase.MonitoredTwitterHandle do
end

def list_all_submissions() do
query = from(m in __MODULE__, where: m.origin == "graphql_api")
query = from(m in __MODULE__, where: m.origin == "graphql_api", preload: [:user])

Repo.all(query)
end

# Private functions

defp normalize_handle(handle) do
handle
|> String.downcase()
|> String.trim()
|> String.trim_leading("@")
end

defp count_user_approved_submissions(user_id) do
query = from(m in __MODULE__, where: m.user_id == ^user_id and m.status == "approved")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ defmodule SanbaseWeb.MonitoredTwitterHandleLive do
<div>
<div class="flex-1 p:2 sm:p-6 justify-between flex flex-col-reverse scrolling-auto">
<.table id="monitored_twitter_handles" rows={@handles}>
<:col :let={row} label="Twitter Handle"><%= row.handle %></:col>
<:col :let={row} label="Status"><%= row.status %></:col>
<:col :let={row} label="Status"><p class={row.status_color}-600><%= row.status |> String.replace("_", " ") |> String.upcase() %></p></:col>
<:col :let={row} label="Twitter Handle (Clickable link)"><.link class="underline text-blue-600" href={"https://x.com/#{row.handle}"}><%= row.handle %></.link></:col>
<:col :let={row} label="Notes"><%= row.notes %></:col>
<:col :let={row} label="User ID"><%= row.user_id %></:col>
<:col :let={row} label="Username"><%= row.user_username %></:col>
<:col :let={row} label="Email"><%= row.user_email %></:col>
<:col :let={row} label="Moderator comment"><%= row.comment %></:col>
<:action :let={row}>
<.form for={@form} phx-submit="update_status">
Expand Down Expand Up @@ -75,12 +78,20 @@ defmodule SanbaseWeb.MonitoredTwitterHandleLive do
handle: struct.handle,
notes: struct.notes,
comment: struct.comment,
inserted_at: struct.inserted_at
inserted_at: struct.inserted_at,
status_color: status_to_color(struct.status),
user_id: struct.user.id,
user_username: struct.user.username,
user_email: struct.user.email
}
end)
|> order_records()
end

defp status_to_color("approved"), do: "text-green-600"
defp status_to_color("declined"), do: "text-red-600"
defp status_to_color("pending_approval"), do: "text-yellow-600"

defp order_records(handles) do
handles
|> Enum.sort_by(
Expand Down

0 comments on commit 571170c

Please sign in to comment.