- commit
- 09d20c7
- parent
- 88fbdfe
- author
- Eric Bower
- date
- 2025-04-01 09:02:35 -0400 EDT
fix(tui.analytics): allow users to enable analytics The core issue here is around focus management. When a user enters the analytics page, we fetch site stats regardless if they have analytics enabled which then applies focus to the left page. However for users witohut analytics enabled we do not focus the left pane which means all key events are lost. In vaxis if we try to focus a widget that doesn't exist we lose the key events in our page widget.
1 files changed,
+27,
-8
+27,
-8
1@@ -82,6 +82,9 @@ func (m *AnalyticsPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw
2 m.focus = "page"
3 return vxfw.FocusWidgetCmd(m), nil
4 case SitesLoaded:
5+ if findAnalyticsFeature(m.features) == nil {
6+ return vxfw.RedrawCmd{}, nil
7+ }
8 m.focus = "sites"
9 return vxfw.BatchCmd([]vxfw.Command{
10 vxfw.FocusWidgetCmd(&m.leftPane),
11@@ -125,6 +128,9 @@ func (m *AnalyticsPage) HandleEvent(ev vaxis.Event, phase vxfw.EventPhase) (vxfw
12 }
13 if msg.Matches(vaxis.KeyTab) {
14 var cmd vxfw.Widget
15+ if findAnalyticsFeature(m.features) == nil {
16+ return nil, nil
17+ }
18 if m.focus == "sites" && m.selected != "" {
19 m.focus = "details"
20 cmd = m.rightPane
21@@ -389,12 +395,7 @@ func (m *AnalyticsPage) fetchFeatures() error {
22 }
23
24 func (m *AnalyticsPage) banner(ctx vxfw.DrawContext) vxfw.Surface {
25- style := vaxis.Style{Foreground: red}
26- analytics := richtext.New([]vaxis.Segment{
27- {
28- Text: "Analytics is only available to pico+ users.\n\n",
29- Style: style,
30- },
31+ segs := []vaxis.Segment{
32 {
33 Text: "Get usage statistics on your blog, blog posts, and pages sites. For example, see unique visitors, most popular URLs, and top referers.\n\n",
34 },
35@@ -402,9 +403,27 @@ func (m *AnalyticsPage) banner(ctx vxfw.DrawContext) vxfw.Surface {
36 Text: "We do not collect usage statistic unless analytics is enabled. Further, when analytics are disabled we do not purge usage statistics.\n\n",
37 },
38 {
39- Text: "We will only store usage statistics for 1 year from when the event was created.",
40+ Text: "We will only store usage statistics for 1 year from when the event was created.\n\n",
41 },
42- })
43+ }
44+
45+ if m.shared.PlusFeatureFlag == nil {
46+ style := vaxis.Style{Foreground: red}
47+ segs = append(segs,
48+ vaxis.Segment{
49+ Text: "Analytics is only available to pico+ users.\n\n",
50+ Style: style,
51+ })
52+ } else {
53+ style := vaxis.Style{Foreground: green}
54+ segs = append(segs,
55+ vaxis.Segment{
56+ Text: "Press 't' to enable analytics\n\n",
57+ Style: style,
58+ })
59+ }
60+
61+ analytics := richtext.New(segs)
62 brd := NewBorder(analytics)
63 brd.Label = "alert"
64 surf, _ := brd.Draw(ctx)