Skip to content

Commit

Permalink
Teams page optics (#45)
Browse files Browse the repository at this point in the history
* teams

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* links

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* lang set

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* 'Get listed' button at the top

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

* ci

Signed-off-by: Oliver Tale-Yazdi <[email protected]>

---------

Signed-off-by: Oliver Tale-Yazdi <[email protected]>
  • Loading branch information
ggwpez authored Feb 26, 2025
1 parent ddb259d commit 0141ac1
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/elixir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
with:
elixir-version: '1.16'
otp-version: '26.0'
env:
ImageOS: ubuntu22

- name: Restore dependencies cache
uses: actions/cache@v3
Expand Down
5 changes: 5 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
default:
mix phx.server

nix:
nix develop
13 changes: 10 additions & 3 deletions lib/phoenix_app_web/controllers/team_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ defmodule PhoenixAppWeb.TeamController do
alias PhoenixApp.Teams
alias PhoenixApp.Teams.Team

def index(conn, _params) do
def index(conn, params) do
sort_by = params["sort"] || "name"
sort_order = params["order"] || "asc"

teams = Teams.list_teams()
num = length(teams)
render(conn, "index.html", teams: teams, num_teams: num)
|> Enum.sort_by(&Map.get(&1, String.to_atom(sort_by)), &sort_compare(&1, &2, sort_order))

render(conn, "index.html", teams: teams, sort_by: sort_by, sort_order: sort_order)
end

defp sort_compare(a, b, "asc"), do: a <= b
defp sort_compare(a, b, "desc"), do: a >= b

def new(conn, _params) do
changeset = Teams.change_team(%Team{})
render(conn, "new.html", changeset: changeset)
Expand Down
94 changes: 77 additions & 17 deletions lib/phoenix_app_web/templates/team/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,85 @@
</section>
<section class="w-full py-16 bg-gray-900">
<div class="max-w-4xl mx-auto px-4">
<article class="text-center py-8">
<p class="text-gray-300 mb-6">
The following projects are currently in development:
</p>
<div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
<%= for team <- @teams do %>
<%= link to: Routes.team_path(@conn, :show, team), class: "block" do %>
<div class="bg-gray-800 shadow-lg rounded-lg overflow-hidden border border-gray-700 hover:border-blue-500 transition-all duration-300 h-full">
<div class="p-4">
<h2 class="text-lg font-semibold mb-1 text-gray-100"><%= team.name %></h2>
<p class="text-sm text-gray-400"><%= team.lang %></p>
</div>
</div>
<% end %>
<% end %>
</div>
<div class="mt-8">
<article class="text-center">
<div class="mb-8">
<%= link "Get Listed", to: "https://github.com/w3f-webops/graypaper-website/issues/new?assignees=&labels=&projects=&template=client-listing-request.md&title=Client+Listing%3A+XYZ", class: "bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded shadow-md transition duration-300 ease-in-out", target: "_blank" %>
</div>
<div class="overflow-x-auto">
<table class="min-w-full bg-gray-800 border border-gray-700 rounded-lg overflow-hidden">
<thead>
<tr>
<th class="px-6 py-3 text-center text-xs font-medium text-gray-300 uppercase tracking-wider border-b border-gray-700">
<%= link to: Routes.team_path(@conn, :index, sort: "name", order: sort_order("name", @sort_by, @sort_order)), class: "flex items-center justify-center group" do %>
<span>Team Name</span>
<span class="ml-2">
<%= if @sort_by == "name" do %>
<%= if @sort_order == "asc" do %>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path></svg>
<% else %>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
<% end %>
<% else %>
<svg class="w-4 h-4 opacity-0 group-hover:opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path></svg>
<% end %>
</span>
<% end %>
</th>
<th class="px-6 py-3 text-center text-xs font-medium text-gray-300 uppercase tracking-wider border-b border-gray-700">
<%= link to: Routes.team_path(@conn, :index, sort: "lang", order: sort_order("lang", @sort_by, @sort_order)), class: "flex items-center justify-center group" do %>
<span>Language</span>
<span class="ml-2">
<%= if @sort_by == "lang" do %>
<%= if @sort_order == "asc" do %>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path></svg>
<% else %>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
<% end %>
<% else %>
<svg class="w-4 h-4 opacity-0 group-hover:opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path></svg>
<% end %>
</span>
<% end %>
</th>
<th class="px-6 py-3 text-center text-xs font-medium text-gray-300 uppercase tracking-wider border-b border-gray-700">
<%= link to: Routes.team_path(@conn, :index, sort: "lang_set", order: sort_order("lang_set", @sort_by, @sort_order)), class: "flex items-center justify-center group" do %>
<span>Language Set</span>
<span class="ml-2">
<%= if @sort_by == "lang_set" do %>
<%= if @sort_order == "asc" do %>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path></svg>
<% else %>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
<% end %>
<% else %>
<svg class="w-4 h-4 opacity-0 group-hover:opacity-50" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path></svg>
<% end %>
</span>
<% end %>
</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-700">
<%= for team <- @teams do %>
<%= link to: Routes.team_path(@conn, :show, team), class: "block hover:bg-gray-700 transition-colors duration-200" do %>
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-100 text-center">
<%= if not is_nil(team.homepage) and team.homepage != "" do %>
<a href={team.homepage} target="_blank" rel="noopener noreferrer" class="hover:text-blue-400 transition-colors duration-200">
<%= team.name %>
</a>
<% else %>
<%= team.name %>
<% end %>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-400 text-center"><%= team.lang %></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-400 text-center"><%= team.lang_set %></td>
</tr>
<% end %>
<% end %>
</tbody>
</table>
</div>
<div class="mt-8">
<%= if PhoenixAppWeb.UserAuth.authenticated?(@conn) do %>
<%= link "New Team", to: Routes.team_path(@conn, :new), class: "bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded shadow-md transition duration-300 ease-in-out" %>
Expand Down
7 changes: 7 additions & 0 deletions lib/phoenix_app_web/views/team_view.ex
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
defmodule PhoenixAppWeb.TeamView do
use PhoenixAppWeb, :view

def sort_order(column, current_sort, current_order) do
case {column == current_sort, current_order} do
{true, "asc"} -> "desc"
_ -> "asc"
end
end
end

0 comments on commit 0141ac1

Please sign in to comment.