Browse Source

feat: show tagged notes

main
Inhji Y. 7 months ago
parent
commit
200c881747
  1. 2
      lib/mirage/notes.ex
  2. 6
      lib/mirage_web/controllers/topic_controller.ex
  3. 26
      lib/mirage_web/templates/note/_note.html.eex
  4. 26
      lib/mirage_web/templates/note/index.html.eex
  5. 16
      lib/mirage_web/templates/topic/show.html.eex

2
lib/mirage/notes.ex

@ -9,7 +9,7 @@ defmodule Mirage.Notes do
alias Mirage.Notes.{Note, Topic, NoteNote, NoteLink}
@note_preloads [:links, :topics, :backlinks]
@topic_preloads [:notes]
@topic_preloads [notes: @note_preloads]
@doc """
Returns the list of notes.

6
lib/mirage_web/controllers/topic_controller.ex

@ -29,7 +29,11 @@ defmodule MirageWeb.TopicController do
end
def show(conn, %{"id" => id}) do
topic = Notes.get_topic!(id)
topic =
id
|> Notes.get_topic!()
|> Notes.preload_topic()
render(conn, "show.html", topic: topic)
end

26
lib/mirage_web/templates/note/_note.html.eex

@ -0,0 +1,26 @@
<article>
<%= link to: Routes.live_path(@conn, MirageWeb.ShowNoteLive, @note) do %>
<header class="width-full bg-content">
<h2 class="title">
<span class="id"><%= "##{@note.id}" %></span> <%= @note.title %>
</h2>
</header>
<% end %>
<section>
<div class="content html width-full bg-content">
<%= raw @note.content_html %>
</div>
</section>
<footer class="width-full bg-content">
<time datetime="<%= @note.inserted_at %>"><%= Timex.from_now(@note.inserted_at) %></time>
<span class="tags">
<%= for topic <- @note.topics do %>
<span class="tag"><%= topic.text %></span>
<% end %>
</span>
</footer class="width-full bg-content">
</article>

26
lib/mirage_web/templates/note/index.html.eex

@ -4,31 +4,7 @@
<section class="notes">
<%= for note <- @notes do %>
<article>
<%= link to: Routes.live_path(@conn, MirageWeb.ShowNoteLive, note) do %>
<header class="width-full bg-content">
<h2 class="title">
<span class="id"><%= "##{note.id}" %></span> <%= note.title %>
</h2>
</header>
<% end %>
<section>
<div class="content html width-full bg-content">
<%= raw note.content_html %>
</div>
</section>
<footer class="width-full bg-content">
<time datetime="<%= note.inserted_at %>"><%= Timex.from_now(note.inserted_at) %></time>
<span class="tags">
<%= for topic <- note.topics do %>
<span class="tag"><%= topic.text %></span>
<% end %>
</span>
</footer class="width-full bg-content">
</article>
<%= render "_note.html", assigns |> Map.put(:note, note) %>
<% end %>
</section>

16
lib/mirage_web/templates/topic/show.html.eex

@ -1,7 +1,15 @@
<div class="hero">
<section class="hero">
<h1>Topic <%= @topic.text %></h1>
</div>
</section>
<section>
<% IO.inspect @topic %>
<%= for note <- @topic.notes do %>
<%= render MirageWeb.NoteView, "_note.html", assigns |> Map.put(:note, note) %>
<% end %>
</section>
<span><%= link "Edit", to: Routes.topic_path(@conn, :edit, @topic) %></span>
<span><%= link "Back", to: Routes.topic_path(@conn, :index) %></span>
<div class="buttons">
<%= link "Edit", to: Routes.topic_path(@conn, :edit, @topic), class: "button" %>
<%= link "Back", to: Routes.topic_path(@conn, :index), class: "button" %>
</div>

Loading…
Cancel
Save