Skip to content

Commit

Permalink
almost
Browse files Browse the repository at this point in the history
  • Loading branch information
psethwick committed Feb 10, 2024
1 parent 77a6567 commit eeb14bc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
12 changes: 9 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ func (m *mainModel) Init() tea.Cmd {
panic(err)
}
}
m.openInbox()
return tea.Batch(waitForSync(m.sub), m.sync())
return tea.Sequence(tea.Batch(waitForSync(m.sub), m.sync()),
func() tea.Msg {
m.openInbox()
return nil
})
}

func (m *mainModel) resetRefresh(listId interface{}) {
Expand Down Expand Up @@ -154,7 +157,10 @@ func (m *mainModel) requestApiToken() tea.Cmd {
if clnt != nil {
m.client = clnt
}
return tea.Batch(waitForSync(m.sub), m.sync())
return tea.Sequence(tea.Batch(waitForSync(m.sub), m.sync()), func() tea.Msg {
m.openInbox()
return nil
})
})
return nil
}
Expand Down
56 changes: 32 additions & 24 deletions sync.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"context"

tea "github.com/charmbracelet/bubbletea"
"github.com/psethwick/tuidoist/client"
"github.com/psethwick/tuidoist/status"
Expand Down Expand Up @@ -232,33 +234,39 @@ func (m *mainModel) sync(cmds ...todoist.Command) tea.Cmd {
}
}
}
syncToken := m.client.Store.SyncToken
if syncToken == "" {
syncToken = "*"
}
incStore, err := m.client.IncrementalSync(m.ctx, syncToken)
if err != nil {
dbg(err)
m.statusBarModel.SetSyncStatus(status.Error)
return nil
}
m.client.Store.ApplyIncrementalSync(incStore)
m.local.ApplyIncrementalSync(incStore)
// if m.projectId == "CHANGEME" && m.local.User.InboxProjectID != "" {
// dbg("CHANGEME, doing inbox")
// m.openInbox()
// } else {
// }
err = client.WriteCache(m.client.Store, m.cmdQueue)
if err != nil {
dbg(err)
m.statusBarModel.SetSyncStatus(status.Error)
m.sub <- struct{}{}
return nil
if len(m.client.Store.Projects) == 0 {
err := m.client.Sync(context.Background())
if err != nil {
dbg(err)
}
err = client.WriteCache(m.client.Store, m.cmdQueue)
if err != nil {
dbg(err)
}
err = client.ReadCache(m.client.Store, m.local, m.cmdQueue)
if err != nil {
dbg(err)
}
} else {
syncToken := m.client.Store.SyncToken
incStore, err := m.client.IncrementalSync(m.ctx, syncToken)
if err != nil {
dbg(err)
m.statusBarModel.SetSyncStatus(status.Error)
return nil
}
m.client.Store.ApplyIncrementalSync(incStore)
m.local.ApplyIncrementalSync(incStore)
err = client.WriteCache(m.client.Store, m.cmdQueue)
if err != nil {
dbg(err)
m.statusBarModel.SetSyncStatus(status.Error)
m.sub <- struct{}{}
return nil
}
}
m.statusBarModel.SetSyncStatus(status.Synced)
m.sub <- struct{}{}
dbg("refreshing")
m.refresh()
return nil
}
Expand Down
2 changes: 0 additions & 2 deletions taskops.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,6 @@ func (tm *mainModel) OpenUrl(url string) func() tea.Msg {
}

func (m *mainModel) openInbox() {
dbg("openInbox", len(m.local.Projects))

for _, tp := range m.local.Projects {
if tp.ID == m.local.User.InboxProjectID {
p := project{tp, todoist.Section{}}
Expand Down

0 comments on commit eeb14bc

Please sign in to comment.