defmodule FirehoseWeb.EditorDashboardLive do use FirehoseWeb, :live_view alias Blogex.Post @impl true def mount(_params, _session, socket) do all_posts = Blogex.Registry.all_posts_unfiltered() drafts = all_posts |> Enum.filter(&(Post.visibility(&1) == :draft)) |> Enum.sort_by(& &1.date, {:desc, Date}) scheduled = all_posts |> Enum.filter(&(Post.visibility(&1) == :scheduled)) |> Enum.sort_by(& &1.date, {:asc, Date}) {:ok, socket |> assign(:page_title, "Editor Dashboard") |> assign(:drafts, drafts) |> assign(:scheduled, scheduled) |> assign(:active_tab, :drafts)} end @impl true def render(assigns) do ~H"""

Dashboard

No drafts
<.link navigate={post_path(post)} class="text-base font-medium text-zinc-900 hover:underline" > {post.title}
{post.author} · {Calendar.strftime(post.date, "%b %d, %Y")} · Draft
No scheduled posts
<.link navigate={post_path(post)} class="text-base font-medium text-zinc-900 hover:underline" > {post.title}
{post.author} · {Calendar.strftime(post.date, "%b %d, %Y")} · {Post.days_until_live(post)} days until live
""" end @impl true def handle_event("switch_tab", %{"tab" => tab}, socket) do {:noreply, assign(socket, :active_tab, String.to_existing_atom(tab))} end defp post_path(post) do blog = Blogex.Registry.get_blog!(post.blog) "#{blog.base_path()}/#{post.id}" end end