Skip to content

Instantly share code, notes, and snippets.

@APB9785
Last active March 17, 2021 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save APB9785/8b7334cf04e6dab3fe90ce75c04ac220 to your computer and use it in GitHub Desktop.
Save APB9785/8b7334cf04e6dab3fe90ce75c04ac220 to your computer and use it in GitHub Desktop.
HTML with case statement
<div class="mx-auto w-max bg-white rounded-xl
shadow-md space-y-2 m-4 antialiased relative
bg-gray-100 font-sans max-w-full">
<div class="text-3xl text-purple-700 text-center p-4">
Welcome to the Forum!
</div>
<%= case @nav do %>
<!-- #################### POST VIEW #################### -->
<% :post -> %>
<!-- Breadcrumb -->
<div class="pl-4">
>
<a href="#"
phx-click="return_main"
class="text-purple-700 hover:underline">
Board Index
</a>
>
<a href="#"
phx-click="return_board"
class="text-purple-700 hover:underline">
<%= @active_board_name %>
</a>
</div>
<br>
<!-- Original Post -->
<div class="px-4 pb-2 border-b-2">
<div class="text-lg font-bold">
<%= @active_post.title %>
</div>
<div class="pl-2">
by <%= @user_cache[@active_post.author].username %> at
<%= @active_post.inserted_at %>
</div>
<div class="py-4">
<%= @active_post.body %>
</div>
</div>
<!-- Replies -->
<%= for reply <- @reply_list do %>
<div class="px-4 pb-2 border-b-2">
<div class="font-bold">
Re: <%= @active_post.title %>
</div>
<div class="pl-2">
by <%= @user_cache[reply.author].username %> at
<%= reply.updated_at %>
</div>
<div class="py-4">
<%= reply.body %>
</div>
</div>
<% end %>
<!-- New Reply form -->
<div>
<%= f = form_for @changeset, "#",
phx_submit: "new_reply" %>
<div class="field">
<%= textarea f, :body,
placeholder: "Reply text",
autocomplete: "off",
class: "py-2 m-2 max-w-md bg-white rounded-xl shadow-md" %>
</div>
<%= submit "Post Reply",
phx_disable_with: "Posting...",
class: "px-8 py-2 m-2 justify-center rounded-md bg-purple-700 text-white" %>
</form>
</div>
<!-- #################### MAIN VIEW #################### -->
<% :main -> %>
<div class="divide-y-2">
<%= for board <- @board_list do %>
<div class="flex">
<div class="py-4 px-4">
<div>
<a href="#"
phx-click="show_board"
phx-value-id="<%= board.id %>"
phx-value-name="<%= board.name %>"
class="text-purple-700 hover:underline">
<%= board.name %>
</a>
</div>
<div>
<%= board.description %>
</div>
</div>
<div class="p-4">
<div>
<%= board.topic_count %> topics
</div>
<div>
<%= board.post_count %> posts
</div>
</div>
<%= if board.last_post != nil do %>
<div class="p-4">
<div>
Last post by <%= @user_cache[board.last_user].username %>
</div>
<div>
in
<a href="#"
class="text-purple-700 hover:underline">
<%= Posts.get_post!(board.last_post).title %>
</a>
</div>
</div>
<% else %>
<div class="p-4">
No posts yet!
</div>
<% end %>
</div>
<% end %>
</div>
<!-- #################### BOARD VIEW #################### -->
<% :board -> %>
<!-- Breadcrumb -->
<div class="pl-4 pb-2">
>
<a href="#"
phx-click="return_main"
class="text-purple-700 hover:underline">
Board Index
</a>
</div>
<!-- Post listing -->
<%= for post <- @post_list do %>
<div class="p-4 border-b-2">
<div>
<a href="#"
phx-click="show_post"
phx-value-id="<%= post.id %>"
class="text-purple-700 hover:underline">
<%= post.title %>
</a>
</div>
<div>
Last post by <%= @user_cache[post.last_user].username %>
at <%= post.updated_at %>
</div>
</div>
<% end %>
<!-- New Post form -->
<div id="create_post">
<%= f = form_for @changeset, "#",
phx_submit: "new_post" %>
<div class="field">
<%= text_input f, :title,
placeholder: "Subject",
autocomplete: "off",
class: "py-2 m-2 max-w-sm bg-white rounded-xl shadow-md" %>
</div>
<div class="field">
<%= textarea f, :body,
placeholder: "Body",
autocomplete: "off",
class: "py-2 ml-2 max-w-sm bg-white rounded-xl shadow-md" %>
</div>
<%= submit "Create Post",
phx_disable_with: "Posting...",
class: "px-8 py-2 m-2 justify-center rounded-md bg-purple-700 text-white" %>
</form>
</div>
<% end %>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment