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
|
end
|
||||||
|
|
||||||
def read(conn, _params) do
|
def read(conn, params) do
|
||||||
item = conn.assigns[:item] |> Repo.preload(:feed)
|
item = conn.assigns[:item] |> Repo.preload(:feed)
|
||||||
|
|
||||||
changeset =
|
changeset =
|
||||||
|
@ -42,10 +42,11 @@ defmodule FrenzyWeb.ItemController do
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, item} = Repo.update(changeset)
|
{: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
|
end
|
||||||
|
|
||||||
def unread(conn, _params) do
|
def unread(conn, params) do
|
||||||
item = conn.assigns[:item] |> Repo.preload(:feed)
|
item = conn.assigns[:item] |> Repo.preload(:feed)
|
||||||
|
|
||||||
changeset =
|
changeset =
|
||||||
|
@ -54,7 +55,8 @@ defmodule FrenzyWeb.ItemController do
|
||||||
read_date: nil
|
read_date: nil
|
||||||
})
|
})
|
||||||
|
|
||||||
Repo.update(changeset)
|
{: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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,6 +38,19 @@
|
||||||
<%= date %>
|
<%= date %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</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>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -29,6 +29,19 @@
|
||||||
<%= date %>
|
<%= date %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</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>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in New Issue