2 Commits

  1. 9
      CHANGELOG.md
  2. 32
      assets/css/app.scss
  3. 6
      lib/mirage/notes.ex
  4. 12
      lib/mirage_web/live/show_note_live.ex
  5. 30
      lib/mirage_web/live/show_note_live.html.leex
  6. 2
      mix.exs

9
CHANGELOG.md

@ -5,6 +5,15 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.24.0](https://git.inhji.de/inhji/mirage/compare/v0.23.0...v0.24.0) (2021-02-13)
### Features:
* support deleting links
## [v0.23.0](https://git.inhji.de/inhji/mirage/compare/v0.22.0...v0.23.0) (2021-02-12)

32
assets/css/app.scss

@ -250,21 +250,35 @@ kbd {
}
.backlinks, .sources {
&+form {
margin-top: 1rem;
}
h4 {
margin-bottom: 1rem;
}
.link {
display: block;
.link-wrapper {
display: flex;
padding: 1rem;
border: 1px solid $border-base;
background: $bg-content;
margin-bottom: 1rem;
text-decoration: none;
a {
text-decoration: none;
}
a.link {
display: flex;
flex: 1;
}
}
.link:last-child {
.link-wrapper:last-child {
margin-bottom: 0;
}
}
/* === Forms === */
@ -276,19 +290,27 @@ form {
border: 0;
margin-bottom: 1rem;
&:last-child {
margin-bottom: 0;
}
input[type=text],
input[type=url],
input[type=email],
input[type=password] {
background: $bg-content;
color: white;
border: 1px solid white;
border: 1px solid $border-base;
margin-bottom: 1rem;
padding: 0.5rem;
width: 100%;
border-radius: 0;
&:last-child {
margin-bottom: 0;
}
}
input.title {

6
lib/mirage/notes.ex

@ -161,12 +161,18 @@ defmodule Mirage.Notes do
Repo.transaction(multi)
end
def get_note_link!(id), do: Repo.get!(NoteLink, id)
def create_note_link(attrs \\ %{}) do
%NoteLink{}
|> NoteLink.changeset(attrs)
|> Repo.insert()
end
def delete_note_link(%NoteLink{} = note_link) do
Repo.delete(note_link)
end
@doc """
Returns the list of topics.

12
lib/mirage_web/live/show_note_live.ex

@ -21,6 +21,18 @@ defmodule MirageWeb.ShowNoteLive do
{:noreply, socket |> assign(%{note: note, link_changeset: link_changeset})}
end
def handle_event("delete_link", %{"link-id" => link_id}, socket) do
link = Notes.get_note_link!(link_id)
{:ok, _} = Notes.delete_note_link(link)
note =
socket.assigns.note.id
|> Notes.get_note!()
|> Notes.preload_note()
{:noreply, socket |> assign(%{note: note})}
end
@impl true
def handle_event("save_link", %{"note_link" => link}, socket) do
case Notes.create_note_link(link) do

30
lib/mirage_web/live/show_note_live.html.leex

@ -21,32 +21,38 @@
<h4>Backlinks</h4>
<%= for backlink <- @note.backlinks do %>
<%= live_patch backlink.title, to: Routes.live_path(@socket, MirageWeb.ShowNoteLive, backlink), class: "link bg-content" %>
<div class="link-wrapper">
<%= live_patch backlink.title, to: Routes.live_path(@socket, MirageWeb.ShowNoteLive, backlink), class: "link" %>
</div>
<% end %>
</section>
<% end %>
<%= if not Enum.empty?(@note.links) do %>
<section class="sources">
<h4>Sources</h4>
<%= if @current_user do %>
<section class="sources">
<h4>Sources</h4>
<%= for link <- @note.links do %>
<div class="link-wrapper">
<%= link link.title || link.url, to: link.url, class: "link" %>
<%= if @current_user do %>
<%= link "🗑️ DELETE", to: "#", phx_click: "delete_link", phx_value_link_id: link.id %>
<% end %>
</div>
<% end %>
</section>
<% end %>
<%= if @current_user do %>
<%= f = form_for @link_changeset, "#", [phx_submit: :save_link] %>
<fieldset>
<%= hidden_input f, :note_id %>
<%= url_input f, :url, placeholder: "Add new link and press ENTER" %>
</fieldset>
</form>
<% end %>
<%= for link <- @note.links do %>
<%= link link.title || link.url, to: link.url, class: "link bg-content" %>
<% end %>
</section>
<% end %>
<%= if @current_user do %>
<div class="buttons">
<span><%= link "Edit", to: Routes.note_path(MirageWeb.Endpoint, :edit, @note), class: "button" %></span>

2
mix.exs

@ -1,7 +1,7 @@
defmodule Mirage.MixProject do
use Mix.Project
@version "0.23.0"
@version "0.24.0"
def project do
[

Loading…
Cancel
Save