Add Read/Unread buttons to item tables

This commit is contained in:
Shadowfacts 2021-03-31 20:00:44 -04:00
parent 0593fcdb9a
commit 25ed3f53d3
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
3 changed files with 33 additions and 5 deletions

View File

@ -32,7 +32,7 @@ defmodule FrenzyWeb.ItemController do
})
end
def read(conn, _params) do
def read(conn, params) do
item = conn.assigns[:item] |> Repo.preload(:feed)
changeset =
@ -42,10 +42,11 @@ defmodule FrenzyWeb.ItemController do
})
{:ok, item} = Repo.update(changeset)
redirect(conn, to: Routes.item_path(Endpoint, :show, item.id))
path = Map.get(params, "redirect") || Routes.item_path(Endpoint, :show, item.id)
redirect(conn, to: path)
end
def unread(conn, _params) do
def unread(conn, params) do
item = conn.assigns[:item] |> Repo.preload(:feed)
changeset =
@ -54,7 +55,8 @@ defmodule FrenzyWeb.ItemController do
read_date: nil
})
Repo.update(changeset)
redirect(conn, to: Routes.item_path(Endpoint, :show, item.id))
{:ok, item} = Repo.update(changeset)
path = Map.get(params, "redirect") || Routes.item_path(Endpoint, :show, item.id)
redirect(conn, to: path)
end
end

View File

@ -38,6 +38,19 @@
<%= date %>
<% end %>
</td>
<td class="py-0 align-middle">
<%= if item.read do %>
<%= form_tag Routes.item_path(@conn, :unread, item.id), method: :post do %>
<input type="hidden" name="redirect" value="<%=Routes.feed_path(@conn, :show, @feed.id) %>">
<%= submit "Unread", class: "btn btn-sm btn-secondary" %>
<% end %>
<% else %>
<%= form_tag Routes.item_path(@conn, :read, item.id), method: :post do %>
<input type="hidden" name="redirect" value="<%=Routes.feed_path(@conn, :show, @feed.id) %>">
<%= submit "Read", class: "btn btn-sm btn-secondary" %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>

View File

@ -29,6 +29,19 @@
<%= date %>
<% end %>
</td>
<td class="py-0 align-middle">
<%= if item.read do %>
<%= form_tag Routes.item_path(@conn, :unread, item.id), method: :post do %>
<input type="hidden" name="redirect" value="<%=Routes.group_path(@conn, :read, @group.id) %>">
<%= submit "Unread", class: "btn btn-sm btn-secondary" %>
<% end %>
<% else %>
<%= form_tag Routes.item_path(@conn, :read, item.id), method: :post do %>
<input type="hidden" name="redirect" value="<%=Routes.group_path(@conn, :read, @group.id) %>">
<%= submit "Read", class: "btn btn-sm btn-secondary" %>
<% end %>
<% end %>
</td>
</tr>
<% end %>
</tbody>