From 1102bbf98d0af563e7002eb1171a6a9b277a6c8f Mon Sep 17 00:00:00 2001 From: Dalton Williams Date: Thu, 22 Aug 2024 17:26:52 -0500 Subject: [PATCH] Cleaned up user display name showing. Version update --- README.md | 6 ++++++ cmd/aocli/aocli.go | 13 +++++++------ cmd/aocli/updater.go | 2 +- internal/resources/User.go | 14 +++++++++----- internal/resources/UserView.go | 13 +++++-------- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 5518b29..06765a3 100644 --- a/README.md +++ b/README.md @@ -60,3 +60,9 @@ If you choose to use the environment variable method, make sure to include a lin From there, you should be good to go! If you installed the CLI program, you can run `aocli health` to verify that everything loaded properly. ![aocli health](./assets/aocliHealth.png) + + +## Licensing + +© 2024 Dalton Williams +Check repository LICENSE file for licensing information. diff --git a/cmd/aocli/aocli.go b/cmd/aocli/aocli.go index 84541b7..d1a8f55 100644 --- a/cmd/aocli/aocli.go +++ b/cmd/aocli/aocli.go @@ -110,8 +110,8 @@ func main() { // run(args) case "view": View(args, user) - case "test": - test(user) + // case "test": + // test(user) case "user": User(args, user) case "clear-user": @@ -412,7 +412,8 @@ func Health() { // Test does whatever I need to test at the time :) // Command: `aocli test` -func test(user *resources.User) { - user.LoadDisplayName() - log.Info(user.DisplayName) -} +// func test(user *resources.User) { +// dispName := user.LoadDisplayName() +// log.Info(user.DisplayName) +// log.Info(dispName) +// } diff --git a/cmd/aocli/updater.go b/cmd/aocli/updater.go index 1401c88..c7e7a2b 100644 --- a/cmd/aocli/updater.go +++ b/cmd/aocli/updater.go @@ -18,7 +18,7 @@ import ( ) // Internally tracked version to compare against GitHub releases -const currentVersion = "v0.9.7" +const currentVersion = "v0.9.8" const repoURL = "https://api.github.com/repos/DaltonSW/aocGo/releases/latest" type githubRelease struct { diff --git a/internal/resources/User.go b/internal/resources/User.go index 4242262..d717a4a 100644 --- a/internal/resources/User.go +++ b/internal/resources/User.go @@ -56,10 +56,15 @@ func NewUser(token string) (*User, error) { yearMap[i] = make([]*Puzzle, 26) } - return &User{ + newUser := &User{ SessionTok: token, Years: yearMap, - }, nil + } + + name := newUser.LoadDisplayName() + newUser.DisplayName = name + + return newUser, nil } func (u *User) Display() { @@ -70,7 +75,6 @@ func (u *User) Display() { } func (u *User) LoadUser() { - u.LoadDisplayName() maxYear, _ := utils.GetCurrentMaxYearAndDay() numStars := make(map[int]int) @@ -104,7 +108,7 @@ func (u *User) LoadUser() { } } -func (u *User) LoadDisplayName() { +func (u *User) LoadDisplayName() string { resp, err := api.NewGetReq("https://adventofcode.com/", u.SessionTok) if err != nil { log.Fatal("Unable to load user's information", "err", err) @@ -124,5 +128,5 @@ func (u *User) LoadDisplayName() { // log.Info(nameClone.Text()) nameClone.Find("span").Remove() - u.DisplayName = strings.TrimSpace(nameClone.Text()) + return strings.TrimSpace(nameClone.Text()) } diff --git a/internal/resources/UserView.go b/internal/resources/UserView.go index f299de5..03e9767 100644 --- a/internal/resources/UserView.go +++ b/internal/resources/UserView.go @@ -44,15 +44,12 @@ func (u *User) NewModel() tea.Model { s.Spinner.FPS = 20 s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color(styles.UpdateSpinnerColor)) - u.LoadDisplayName() - model := LoadUserModel{ - user: u, - userName: u.DisplayName, - spinner: s, - curYear: utils.FIRST_YEAR, - curDate: 1, - status: "Starting up!", + user: u, + spinner: s, + curYear: utils.FIRST_YEAR, + curDate: 1, + status: "Starting up!", } return model