Skip to content

Commit

Permalink
Fix sites list when user has no sites
Browse files Browse the repository at this point in the history
  • Loading branch information
ukutaht committed Nov 27, 2020
1 parent d879ef8 commit a92bca2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/plausible/stats/clickhouse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ defmodule Plausible.Stats.Clickhouse do
end)
end

def last_24h_visitors([]), do: %{}
def last_24h_visitors(sites) do
domains = Enum.map(sites, & &1.domain)

Expand Down
7 changes: 5 additions & 2 deletions lib/plausible_web/templates/site/index.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
</div>

<ul class="my-6 grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
<%= if Enum.empty?(@sites) do %>
<p>You don't have any sites yet</p>
<% end %>

<%= for site <- @sites do %>
<div class="relative group">
<%= link(to: "/" <> URI.encode_www_form(site.domain)) do %>
Expand All @@ -20,8 +24,7 @@
<div class="pl-8 mt-2 flex items-center justify-between">
<span class="text-gray-600 text-sm truncate">
<span class="text-gray-800">
<b><%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %></b>
visitors in last 24h
<b><%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %></b> visitors in last 24h
</span>
</span>
</div>
Expand Down
17 changes: 17 additions & 0 deletions test/plausible_web/controllers/site_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ defmodule PlausibleWeb.SiteControllerTest do
end
end

describe "GET /sites" do
setup [:create_user, :log_in]

test "shows empty screen if no sites", %{conn: conn} do
conn = get(conn, "/sites")
assert html_response(conn, 200) =~ "You don't have any sites yet"
end

test "lists all of your sites with last 24h visitors", %{conn: conn, user: user} do
insert(:site, members: [user], domain: "test-site.com")
conn = get(conn, "/sites")

assert html_response(conn, 200) =~ "test-site.com"
assert html_response(conn, 200) =~ "<b>3</b> visitors in last 24h"
end
end

describe "POST /sites" do
setup [:create_user, :log_in]

Expand Down

0 comments on commit a92bca2

Please sign in to comment.