Browse Source

feat: Add Inbox Live

main
Inhji Y. 7 months ago
parent
commit
16b7514cf0
  1. 24
      lib/mirage_web/live/inbox_live.ex
  2. 67
      lib/mirage_web/live/inbox_live.html.leex
  3. 2
      lib/mirage_web/router.ex

24
lib/mirage_web/live/inbox_live.ex

@ -0,0 +1,24 @@
defmodule MirageWeb.InboxLive do
use MirageWeb, :live_view
@impl true
def mount(_params, %{"user_id" => user_id}, socket) do
current_user = user_id && Mirage.Accounts.get_user!(user_id)
settings = Mirage.Settings.list_settings_as_map()
unlinked = Mirage.Notes.list_notes(:unlinked)
untagged = Mirage.Notes.list_notes(:untagged)
at = Mirage.Notes.list_notes(:at)
today = Mirage.Notes.list_notes(:today)
{:ok,
assign(socket, %{
current_user: current_user,
notes: %{
today: today,
at: at,
untagged: untagged,
unlinked: unlinked
}
})}
end
end

67
lib/mirage_web/live/inbox_live.html.leex

@ -0,0 +1,67 @@
<%= if @current_user do %>
<%= live_render @socket, MirageWeb.GotoAnythingLive, id: "goto-anything-wrapper" %>
<% end %>
<header class="hero">
<h1>Inbox</h1>
</header>
<section class="bg-content width-full">
<h3>📆 Todays Note</h3>
<div class="cards">
<%= for note <- @notes.today do %>
<%= live_patch to: Routes.note_show_path(MirageWeb.Endpoint, :show, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<%= if not Enum.empty?(@notes.unlinked) do %>
<section class="bg-content width-full">
<h3>🔗 Unlinked</h3>
<div class="grid cards">
<%= for note <- @notes.unlinked do %>
<%= live_patch to: Routes.note_show_path(MirageWeb.Endpoint, :show, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<% end %>
<%= if not Enum.empty?(@notes.untagged) do %>
<section class="bg-content width-full">
<h3>🔖 Untagged</h3>
<div class="grid cards">
<%= for note <- @notes.untagged do %>
<%= live_patch to: Routes.note_show_path(MirageWeb.Endpoint, :show, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<% end %>
<section class="bg-content width-full">
<h3>🃏 At-Notes</h3>
<div class="grid cards">
<%= for note <- @notes.at do %>
<%= live_patch to: Routes.note_show_path(MirageWeb.Endpoint, :show, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<div class="buttons">
<%= link "Edit User", to: Routes.user_settings_path(MirageWeb.Endpoint, :edit), class: "button" %>
</div>

2
lib/mirage_web/router.ex

@ -84,7 +84,7 @@ defmodule MirageWeb.Router do
scope "/", MirageWeb do
pipe_through [:browser, :require_authenticated_user]
get "/user", UserController, :index
live "/inbox", InboxLive
resources "/user/settings", SettingController, only: [:index, :show, :edit, :update]

Loading…
Cancel
Save