Fix sites list when user has no sites

pull/442/head
Uku Taht 6 years ago
parent d879ef8458
commit a92bca2c86

@ -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)

@ -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 %>
@ -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>

@ -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]

Loading…
Cancel
Save