From c551a086417901f50629272b52890c9ad2a7df47 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Wed, 7 Jan 2026 12:38:31 -0500 Subject: [PATCH] refactor(components): extract data models into shared models package --- components/charts.templ | 29 +--- components/charts_templ.go | 41 ++---- components/sidebar.templ | 6 +- components/sidebar_templ.go | 6 +- handlers/routes.go | 79 +++------- views/authorize.templ | 69 ++------- views/authorize_templ.go | 135 +++++++---------- views/dashboard.templ | 156 ++------------------ views/dashboard_templ.go | 278 ++++++++++-------------------------- views/login.templ | 17 +-- views/login_templ.go | 29 ++-- views/register.templ | 29 +--- views/register_templ.go | 39 ++--- 13 files changed, 233 insertions(+), 680 deletions(-) diff --git a/components/charts.templ b/components/charts.templ index 7c0a0fe..28094cb 100644 --- a/components/charts.templ +++ b/components/charts.templ @@ -1,8 +1,11 @@ package components -import "encoding/json" +import ( + "encoding/json" + + "nebula/models" +) -// OHLCData represents a single candlestick data point type OHLCData struct { Date string `json:"date"` Open float64 `json:"open"` @@ -11,27 +14,11 @@ type OHLCData struct { Close float64 `json:"close"` } -// AreaSeriesData represents time series data for stacked area chart -type AreaSeriesData struct { - Date string `json:"date"` - Industry string `json:"industry"` - Value float64 `json:"value"` -} - -// BubbleData represents data for bubble/circle packing chart -type BubbleData struct { - Name string `json:"name"` - Sector string `json:"sector"` - Value float64 `json:"value"` -} - -// TimeSeriesData represents simple time series data type TimeSeriesData struct { Date string `json:"date"` Value float64 `json:"value"` } -// Helper to convert data to JSON string for JS func toJSON(v interface{}) string { b, _ := json.Marshal(v) return string(b) @@ -661,15 +648,13 @@ templ CandleChart(id string, data []OHLCData) { @initCandleChart(id, toJSON(data)) } -// StackedAreaChart component -templ StackedAreaChart(id string, data []AreaSeriesData) { +templ StackedAreaChart(id string, data []models.AreaSeriesData) {
@initRosenCharts() @initStackedAreaChart(id, toJSON(data)) } -// BubbleChart component -templ BubbleChart(id string, data []BubbleData) { +templ BubbleChart(id string, data []models.BubbleData) {
@initRosenCharts() @initBubbleChart(id, toJSON(data)) diff --git a/components/charts_templ.go b/components/charts_templ.go index fea1412..d83fdd3 100644 --- a/components/charts_templ.go +++ b/components/charts_templ.go @@ -8,9 +8,12 @@ package components import "github.com/a-h/templ" import templruntime "github.com/a-h/templ/runtime" -import "encoding/json" +import ( + "encoding/json" + + "nebula/models" +) -// OHLCData represents a single candlestick data point type OHLCData struct { Date string `json:"date"` Open float64 `json:"open"` @@ -19,27 +22,11 @@ type OHLCData struct { Close float64 `json:"close"` } -// AreaSeriesData represents time series data for stacked area chart -type AreaSeriesData struct { - Date string `json:"date"` - Industry string `json:"industry"` - Value float64 `json:"value"` -} - -// BubbleData represents data for bubble/circle packing chart -type BubbleData struct { - Name string `json:"name"` - Sector string `json:"sector"` - Value float64 `json:"value"` -} - -// TimeSeriesData represents simple time series data type TimeSeriesData struct { Date string `json:"date"` Value float64 `json:"value"` } -// Helper to convert data to JSON string for JS func toJSON(v interface{}) string { b, _ := json.Marshal(v) return string(b) @@ -721,7 +708,7 @@ func CandleChart(id string, data []OHLCData) templ.Component { var templ_7745c5c3_Var2 string templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 659, Col: 13} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 646, Col: 13} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2)) if templ_7745c5c3_Err != nil { @@ -743,8 +730,7 @@ func CandleChart(id string, data []OHLCData) templ.Component { }) } -// StackedAreaChart component -func StackedAreaChart(id string, data []AreaSeriesData) templ.Component { +func StackedAreaChart(id string, data []models.AreaSeriesData) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -772,7 +758,7 @@ func StackedAreaChart(id string, data []AreaSeriesData) templ.Component { var templ_7745c5c3_Var4 string templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 666, Col: 13} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 652, Col: 13} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) if templ_7745c5c3_Err != nil { @@ -794,8 +780,7 @@ func StackedAreaChart(id string, data []AreaSeriesData) templ.Component { }) } -// BubbleChart component -func BubbleChart(id string, data []BubbleData) templ.Component { +func BubbleChart(id string, data []models.BubbleData) templ.Component { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) { templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil { @@ -823,7 +808,7 @@ func BubbleChart(id string, data []BubbleData) templ.Component { var templ_7745c5c3_Var6 string templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 673, Col: 13} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 658, Col: 13} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) if templ_7745c5c3_Err != nil { @@ -904,7 +889,7 @@ func SemiFilledAreaChartWithColors(id string, data []TimeSeriesData, lineColor s var templ_7745c5c3_Var9 string templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(id) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 685, Col: 13} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 670, Col: 13} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) if templ_7745c5c3_Err != nil { @@ -955,7 +940,7 @@ func ChartCard(title string, subtitle string) templ.Component { var templ_7745c5c3_Var11 string templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(title) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 695, Col: 38} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 680, Col: 38} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) if templ_7745c5c3_Err != nil { @@ -973,7 +958,7 @@ func ChartCard(title string, subtitle string) templ.Component { var templ_7745c5c3_Var12 string templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(subtitle) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 697, Col: 87} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `components/charts.templ`, Line: 682, Col: 87} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) if templ_7745c5c3_Err != nil { diff --git a/components/sidebar.templ b/components/sidebar.templ index 8891fc9..aa7a4b6 100644 --- a/components/sidebar.templ +++ b/components/sidebar.templ @@ -22,9 +22,9 @@ func DefaultSidebarItems(activeTab string) []SidebarItem { } // SecondarySidebarItems returns the bottom navigation items -func SecondarySidebarItems() []SidebarItem { +func SecondarySidebarItems(activeTab string) []SidebarItem { return []SidebarItem{ - {ID: "settings", Icon: "gear", Label: "Settings", Href: "/settings", Active: false}, + {ID: "settings", Icon: "gear", Label: "Settings", Href: "/settings", Active: activeTab == "settings"}, } } @@ -48,7 +48,7 @@ templ NavigationItems(activeTab string) { }