Add Read/Unread buttons to item tables
This commit is contained in:
parent
0593fcdb9a
commit
25ed3f53d3
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue