Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/cmd_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func handleMediaAdd(cmd *cobra.Command, args []string) {
err = viewmodel.HandleMediaUpdate(
viewmodel.MediaUpdateParams{
IsNewAddition: true,
MediaId: mediaId,
Status: mediaAddStatus,
MediaId: mediaId,
Status: mediaAddStatus,
},
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var mediaListCmd = &cobra.Command{
Use: "list",
Short: "List your current anime/manga list",
Aliases: []string{"ls"},
Run: handleLs,
Run: handleLs,
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_media_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ var mediaSearchCmd = &cobra.Command{
Use: "search [query...]",
Short: "Search for anime and manga",
Args: cobra.MinimumNArgs(1),
Run: handleMediaSearch,
Run: handleMediaSearch,
}

func init() {
Expand Down
55 changes: 44 additions & 11 deletions cmd/cmd_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (

// // TODO: Update progress relatively. For example "+2", "-10" etc.,
var progress string
var updateStatus string
var notes string
var scoreString string

// func handleUpdate(mediaId int) {
// CheckIfTokenExists()
Expand Down Expand Up @@ -48,15 +51,32 @@ func handleUpdate(cmd *cobra.Command, args []string) {
)
}

err = viewmodel.HandleMediaUpdate(
viewmodel.MediaUpdateParams{
IsNewAddition: false,
MediaId: id,
Progress: progress,
Status: "none",
StartDate: "none",
},
)
var scoreFloat *float64
if scoreString != "" {
rawScoreFloat, err := strconv.ParseFloat(scoreString, 32)
if err != nil {
fmt.Println(ui.ErrorText(err))
return
}
scoreFloat = &rawScoreFloat
}

params := viewmodel.MediaUpdateParams{
IsNewAddition: false,
MediaId: id,
Progress: progress,
Status: updateStatus,
StartDate: "none",
}
// TODO: add a way to differentiate between an
// empty notes value vs. an unset notes value
if notes != "\n" {
params.Notes = notes
}
if scoreFloat != nil {
params.Score = float32(*scoreFloat)
}
err = viewmodel.HandleMediaUpdate(params)

if err != nil {
fmt.Println(ui.ErrorText(err))
Expand All @@ -67,15 +87,28 @@ var mediaUpdateCmd = &cobra.Command{
Use: "update [id]",
Short: "Update a list entry",
Args: cobra.MinimumNArgs(1),
Run: handleUpdate,
Run: handleUpdate,
}

func init() {
mediaUpdateCmd.Flags().StringVarP(
&progress,
"progress",
"p",
"0",
"",
"The number of episodes/chapter to update",
)
mediaUpdateCmd.Flags().StringVarP(
&updateStatus, "status", "s", "none", "Status of the media. Can be 'watching/w or reading/r', 'planning/p', 'completed/c', 'dropped/d', 'paused/ps'",
)
mediaUpdateCmd.Flags().StringVarP(
&notes,
"notes",
"n",
"\n",
"Text notes. Note: you can add multiple lines by typing \"\\n\" and wrapping the note in double quotes",
)
mediaUpdateCmd.Flags().StringVarP(
&scoreString, "score", "r", "", "The score of the entry. If your score is in emoji, type 1 for 😞, 2 for 😐 and 3 for 😊",
)
}
2 changes: 1 addition & 1 deletion internal/api/anilist.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ func UpdateMediaEntry(params map[string]any) (*responses.MediaUpdateResponse, er
}

return &responseStruct, nil
}
}
2 changes: 1 addition & 1 deletion internal/api/mutations.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ const mediaEntryUpdateMutation = `mutation(
}
}
}
}`
}`
6 changes: 3 additions & 3 deletions internal/api/responses/media_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ type ListCollection struct {
Title struct {
UserPreferred string `json:"userPreferred"`
} `json:"title"`
Chapters *int `json:"chapters"`
Volumes *int `json:"volumes"`
Episodes *int `json:"episodes"`
Chapters *int `json:"chapters"`
Volumes *int `json:"volumes"`
Episodes *int `json:"episodes"`
MediaFormat string `json:"format"`
} `json:"media"`
} `json:"entries"`
Expand Down
4 changes: 2 additions & 2 deletions internal/api/responses/media_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ type MediaSearchList struct {
UserPreferred string `json:"userPreferred"`
} `json:"title"`
AverageScore *float64 `json:"averageScore"`
MediaType string `json:"type"`
MediaFormat string `json:"format"`
MediaType string `json:"type"`
MediaFormat string `json:"format"`
}

type MediaSearch struct {
Expand Down
4 changes: 2 additions & 2 deletions internal/api/responses/media_update_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ type MediaUpdateResponse struct {
Data struct {
SaveMediaListEntry struct {
Media struct {
Id int `json:"id"`
Id int `json:"id"`
Title struct {
UserPreferred string `json:"userPreferred"`
} `json:"title"`
} `json:"media"`
} `json:"SaveMediaListEntry"`
} `json:"data"`
}
}
12 changes: 6 additions & 6 deletions internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ package internal

// Base URL is not gonna get changed for a while.
// So, keeping it as constant is not gonna hurt anyone.
const(
API_ENDPOINT = "https://graphql.anilist.co"
AUTH_URL = "https://anilist.co/api/v2/oauth/authorize?client_id=4593&response_type=token"
const (
API_ENDPOINT = "https://graphql.anilist.co"
AUTH_URL = "https://anilist.co/api/v2/oauth/authorize?client_id=4593&response_type=token"
BOLT_BUCKET_NAME = "ChibiConfig"
BOLT_DB_NAME = "chibi_config.db"
BOLT_DB_NAME = "chibi_config.db"
)

type MediaType string
type MediaType string

const (
ANIME MediaType = "ANIME"
MANGA MediaType = "MANGA"
)
)
4 changes: 2 additions & 2 deletions internal/db/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package db

const(
const (
QUERY_CREATE_TABLE = `CREATE TABLE IF NOT EXISTS config (
id INTEGER PRIMARY KEY AUTOINCREMENT,
key TEXT NOT NULL,
Expand All @@ -12,4 +12,4 @@ const(
QUERY_INSERT_CONFIG = `INSERT INTO config (key, value) VALUES (?, ?)`

QUERY_GET_CONFIG = `SELECT value FROM config WHERE key = ?`
)
)
4 changes: 2 additions & 2 deletions internal/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CreateConfigDir() {
os.RemoveAll(configDir)
}
os.MkdirAll(configDir, 0755)
}
}

// maps "type" command line argument string to valid
// MediaType enum required by AniList API
Expand Down Expand Up @@ -74,4 +74,4 @@ func MediaFormatFormatter(mediaFormat string) string {
default:
return "?"
}
}
}
10 changes: 5 additions & 5 deletions internal/ui/media_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"
"strconv"

"github.com/CosmicPredator/chibi/internal"
"github.com/CosmicPredator/chibi/internal/api/responses"
"github.com/charmbracelet/lipgloss"
Expand Down Expand Up @@ -40,7 +40,7 @@ func (l *MediaListUI) renderTable(rows ...[]string) (*table.Table, error) {
Align(lipgloss.Center)
}

if row % 2 == 0 && (col == 0 || col == 2 || col == 3) {
if row%2 == 0 && (col == 0 || col == 2 || col == 3) {
return lipgloss.NewStyle().Align(lipgloss.Center).Faint(true)
}

Expand All @@ -52,7 +52,7 @@ func (l *MediaListUI) renderTable(rows ...[]string) (*table.Table, error) {
PaddingLeft(1).
PaddingRight(1).
Width((tw - 6) / 3).Inline(true)
if row % 2 == 0 {
if row%2 == 0 {
colStyle = colStyle.Faint(true)
}
return colStyle
Expand Down Expand Up @@ -103,7 +103,7 @@ func (l *MediaListUI) Render() error {
if list.Status == "REPEATING" {
entry.Media.Title.UserPreferred = "(R) " + entry.Media.Title.UserPreferred
}

rows = append(rows, []string{
strconv.Itoa(entry.Media.Id),
entry.Media.Title.UserPreferred,
Expand All @@ -121,4 +121,4 @@ func (l *MediaListUI) Render() error {
fmt.Println(table)

return nil
}
}
16 changes: 8 additions & 8 deletions internal/ui/media_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ func (ms *MediaSearchUI) renderTable(rows ...[]string) (*table.Table, error) {
// style for table header row
if row == -1 {
return lipgloss.
NewStyle().
Foreground(lipgloss.Color("#FF79C6")).
Bold(true).
Align(lipgloss.Center)
NewStyle().
Foreground(lipgloss.Color("#FF79C6")).
Bold(true).
Align(lipgloss.Center)
}

if row % 2 == 0 && (col == 0 || col == 2 || col == 3) {
if row%2 == 0 && (col == 0 || col == 2 || col == 3) {
return lipgloss.NewStyle().Align(lipgloss.Center).Faint(true)
}

Expand All @@ -50,7 +50,7 @@ func (ms *MediaSearchUI) renderTable(rows ...[]string) (*table.Table, error) {
PaddingLeft(2).
PaddingRight(2).
Width((tw - 6) / 3).Inline(true)
if row % 2 == 0 {
if row%2 == 0 {
colStyle = colStyle.Faint(true)
}
return colStyle
Expand All @@ -64,7 +64,7 @@ func (ms *MediaSearchUI) renderTable(rows ...[]string) (*table.Table, error) {
}).
Headers("ID", "TITLE", "FORMAT", "SCORE").
Rows(rows...).Width(tw)

return table, nil
}

Expand Down Expand Up @@ -95,4 +95,4 @@ func (ms *MediaSearchUI) Render() error {

fmt.Println(table)
return nil
}
}
2 changes: 1 addition & 1 deletion internal/ui/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *ProfileUI) Render() error {
valueStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("#8BE9FD"))

var sb strings.Builder

// iterating over dataSlice and adding the KV pairs to String Builder
// with appropriate padding
for _, kv := range dataSlice {
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ func ActionSpinner(title string, action func(context.Context) error) error {
Title(title).
ActionWithErr(action).
Run()
}
}
2 changes: 1 addition & 1 deletion internal/viewmodel/login_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func HandleLogin() error {
return err
}

// gets user profile details from api and saves
// gets user profile details from api and saves
// the username and ID to db
var profile *responses.Profile
err = ui.ActionSpinner("Logging In...", func(ctx context.Context) error {
Expand Down
8 changes: 4 additions & 4 deletions internal/viewmodel/media_list_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ func HandleMediaList(mediaType, mediaStatus string) error {
// current and repeating
var mediaStatuIn []string
if mediaStatus == "CURRENT" {
mediaStatuIn = []string{ mediaStatus, "REPEATING" }
mediaStatuIn = []string{mediaStatus, "REPEATING"}
} else {
mediaStatuIn = []string{ mediaStatus }
mediaStatuIn = []string{mediaStatus}
}

// perform media list API request
Expand All @@ -57,7 +57,7 @@ func HandleMediaList(mediaType, mediaStatus string) error {
MediaType: mediaType,
MediaList: mediaList,
}

err = mediaListUI.Render()
return err
}
}
2 changes: 1 addition & 1 deletion internal/viewmodel/media_search_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ func HandleMediaSearch(searchQuery string, mediaType string, perPage int) error
}
err = mediaSearchUI.Render()
return err
}
}
Loading