Skip to content

Instantly share code, notes, and snippets.

@phil-a
Created April 29, 2020 03:23
Show Gist options
  • Select an option

  • Save phil-a/bf1f43d4a90f3abb5aac7f13a86618d4 to your computer and use it in GitHub Desktop.

Select an option

Save phil-a/bf1f43d4a90f3abb5aac7f13a86618d4 to your computer and use it in GitHub Desktop.

Revisions

  1. phil-a created this gist Apr 29, 2020.
    39 changes: 39 additions & 0 deletions index.html.leex
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    <h1>Listing Posts</h1>

    <%= if @live_action in [:new, :edit] do %>
    <%= live_modal @socket, RetroWeb.PostLive.FormComponent,
    id: @post.id || :new,
    title: @page_title,
    action: @live_action,
    post: @post,
    return_to: Routes.post_index_path(@socket, :index) %>
    <% end %>

    <table>
    <thead>
    <tr>
    <th>Username</th>
    <th>Body</th>
    <th>Likes count</th>

    <th></th>
    </tr>
    </thead>
    <tbody id="posts">
    <%= for post <- @posts do %>
    <tr id="post-<%= post.id %>">
    <td><%= post.username %></td>
    <td><%= post.body %></td>
    <td><%= post.likes_count %></td>

    <td>
    <span><%= live_redirect "Show", to: Routes.post_show_path(@socket, :show, post) %></span>
    <span><%= live_patch "Edit", to: Routes.post_index_path(@socket, :edit, post) %></span>
    <span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: post.id, data: [confirm: "Are you sure?"] %></span>
    </td>
    </tr>
    <% end %>
    </tbody>
    </table>

    <span><%= live_patch "New Post", to: Routes.post_index_path(@socket, :new) %></span>