diff --git a/CHANGELOG.md b/CHANGELOG.md index cbfb54a7c..6aa7dd21f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - Ignore consecutive pageviews on same pathname plausible/analytics#417 - Validate domain format on site creation plausible/analytics#427 - Improve settings UX and design plausible/analytics#412 +- Improve site listing UX and design plausible/analytics#438 ### Fixed - Do not error when activating an already activated account plausible/analytics#370 diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index ae7f22d41..37dfad3c9 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -762,6 +762,19 @@ defmodule Plausible.Stats.Clickhouse do end) end + def last_24h_visitors(sites) do + domains = Enum.map(sites, & &1.domain) + + ClickhouseRepo.all( + from e in "events", + group_by: e.domain, + where: fragment("? IN tuple(?)", e.domain, ^domains), + where: e.timestamp > fragment("now() - INTERVAL 24 HOUR"), + select: {e.domain, fragment("uniq(user_id)")} + ) + |> Enum.into(%{}) + end + def goal_conversions(site, %Query{filters: %{"goal" => goal}} = query) when is_binary(goal) do ClickhouseRepo.all( from e in base_query_w_sessions(site, query), diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 063428fc5..37474a3a4 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -6,8 +6,16 @@ defmodule PlausibleWeb.SiteController do plug PlausibleWeb.RequireAccountPlug def index(conn, _params) do - user = conn.assigns[:current_user] |> Repo.preload(:sites) - render(conn, "index.html", sites: user.sites) + user = conn.assigns[:current_user] + sites = Repo.all( + from s in Plausible.Site, + join: sm in Plausible.Site.Membership, on: sm.site_id == s.id, + where: sm.user_id == ^user.id, + order_by: s.domain + ) + + visitors = Plausible.Stats.Clickhouse.last_24h_visitors(sites) + render(conn, "index.html", sites: sites, visitors: visitors) end def new(conn, _params) do diff --git a/lib/plausible_web/templates/site/index.html.eex b/lib/plausible_web/templates/site/index.html.eex index 0c307a556..034cdf810 100644 --- a/lib/plausible_web/templates/site/index.html.eex +++ b/lib/plausible_web/templates/site/index.html.eex @@ -1,25 +1,37 @@ -
-
-
-

My websites

+
+
+

+ My sites +

+ Add a website
-
-
- <%= for site <- @sites do %> -
- - -

<%= site.domain %>

-
- <%= link(to: "/#{URI.encode_www_form(site.domain)}/settings", class: "flex absolute hover:bg-gray-100 transition rounded py-2 px-5", style: "top: 12px; right: 6px;") do %> -
- + +
    + <%= for site <- @sites do %> +
    + <%= link(to: "/" <> URI.encode_www_form(site.domain)) do %> +
  • +
    + +
    +

    <%= site.domain %>

    +
    -

    Settings

    - <% end %> -
  • - <% end %> -
-
+
+ + + <%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %> + visitors in last 24h + + +
+ + <% end %> + + <%= link(to: "/" <> URI.encode_www_form(site.domain) <> "/settings", class: "absolute top-0 right-0 p-4 mt-1") do %> + + <% end %> +
+ <% end %> +