Browse Source

feat: list last edited and unlinked notes

main
Inhji Y. 8 months ago
parent
commit
a812d2205c
  1. 24
      lib/mirage/notes.ex
  2. 10
      lib/mirage_web/controllers/user_controller.ex
  3. 1
      lib/mirage_web/templates/shared/user_menu.html.eex
  4. 28
      lib/mirage_web/templates/user/index.html.eex

24
lib/mirage/notes.ex

@ -28,6 +28,30 @@ defmodule Mirage.Notes do
|> Repo.preload(@note_preloads)
end
def list_notes(:last_edited) do
Note
|> limit(3)
|> order_by(desc: :updated_at)
|> Repo.all()
|> Repo.preload(@note_preloads)
end
def list_notes(:unlinked) do
q =
from n in Note,
full_join: nn in NoteNote,
on: nn.target_id == n.id or nn.source_id == n.id,
where: not like(n.title, "@%"),
where: is_nil(nn.target_id) or is_nil(nn.source_id),
select: n,
limit: 3,
preload: ^@note_preloads
q
|> Repo.all()
|> Repo.preload(@note_preloads)
end
@doc """
Gets a single note.

10
lib/mirage_web/controllers/user_controller.ex

@ -2,6 +2,14 @@ defmodule MirageWeb.UserController do
use MirageWeb, :controller
def index(conn, _params) do
render(conn, "index.html")
last_edited = Mirage.Notes.list_notes(:last_edited)
unlinked = Mirage.Notes.list_notes(:unlinked)
render(conn, "index.html",
notes: %{
last_edited: last_edited,
unlinked: unlinked
}
)
end
end

1
lib/mirage_web/templates/shared/user_menu.html.eex

@ -1,6 +1,5 @@
<aside class="menu">
<ul>
<li><%= link "User", to: Routes.user_path(@conn, :index) %></li>
<li><%= link "Settings", to: Routes.setting_path(@conn, :index) %></li>
</ul>
</aside>

28
lib/mirage_web/templates/user/index.html.eex

@ -1,11 +1,33 @@
<%= render MirageWeb.SharedView, "user_menu.html", assigns %>
<div class="hero">
<h1>User</h1>
<h1>Hi <%= @current_user.email %></h1>
</div>
<section>
<p>hello world!</p>
<section class="bg-content width-full">
<h3>Last Edited</h3>
<div class="grid">
<%= for note <- @notes.last_edited do %>
<%= link to: Routes.live_path(@conn, MirageWeb.ShowNoteLive, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<section class="bg-content width-full">
<h3>Unlinked</h3>
<div class="grid">
<%= for note <- @notes.unlinked do %>
<%= link to: Routes.live_path(@conn, MirageWeb.ShowNoteLive, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<div class="buttons">

Loading…
Cancel
Save