main.go

  1package main
  2
  3import (
  4	"fmt"
  5	"os"
  6	"time"
  7
  8	tea "charm.land/bubbletea/v2"
  9	"github.com/floatpane/matcha/config"
 10	"github.com/floatpane/matcha/fetcher"
 11	"github.com/floatpane/matcha/tui"
 12)
 13
 14type wrapper struct {
 15	inbox *tui.Inbox
 16}
 17
 18func (w wrapper) Init() tea.Cmd {
 19	return w.inbox.Init()
 20}
 21
 22func (w wrapper) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 23	m, cmd := w.inbox.Update(msg)
 24	if inbox, ok := m.(*tui.Inbox); ok {
 25		w.inbox = inbox
 26	}
 27	return w, cmd
 28}
 29
 30func (w wrapper) View() tea.View {
 31	v := w.inbox.View()
 32	v.AltScreen = true
 33	return v
 34}
 35
 36func main() {
 37	now := time.Now()
 38	account := config.Account{
 39		ID:         "demo-user",
 40		Name:       "Matcha Demo",
 41		Email:      "demo@floatpane.com",
 42		FetchEmail: "demo@floatpane.com",
 43	}
 44
 45	emails := []fetcher.Email{
 46		{
 47			UID:        304,
 48			From:       "Priya Shah <priya@example.com>",
 49			To:         []string{"demo@floatpane.com"},
 50			Subject:    "Re: Release checklist for 1.8",
 51			Date:       now.Add(-8 * time.Minute),
 52			MessageID:  "<release-304@example.com>",
 53			References: []string{"<release-301@example.com>", "<release-302@example.com>"},
 54			AccountID:  account.ID,
 55		},
 56		{
 57			UID:       303,
 58			From:      "Buildkite <buildkite@example.com>",
 59			To:        []string{"demo@floatpane.com"},
 60			Subject:   "main passed",
 61			Date:      now.Add(-20 * time.Minute),
 62			MessageID: "<build-303@example.com>",
 63			AccountID: account.ID,
 64			IsRead:    true,
 65		},
 66		{
 67			UID:        302,
 68			From:       "Noah Reed <noah@example.com>",
 69			To:         []string{"demo@floatpane.com"},
 70			Subject:    "Re: Release checklist for 1.8",
 71			Date:       now.Add(-33 * time.Minute),
 72			MessageID:  "<release-302@example.com>",
 73			References: []string{"<release-301@example.com>"},
 74			AccountID:  account.ID,
 75			IsRead:     true,
 76		},
 77		{
 78			UID:       301,
 79			From:      "Avery Stone <avery@example.com>",
 80			To:        []string{"demo@floatpane.com"},
 81			Subject:   "Release checklist for 1.8",
 82			Date:      now.Add(-52 * time.Minute),
 83			MessageID: "<release-301@example.com>",
 84			AccountID: account.ID,
 85			IsRead:    true,
 86		},
 87		{
 88			UID:       300,
 89			From:      "Finance <finance@example.com>",
 90			To:        []string{"demo@floatpane.com"},
 91			Subject:   "Invoice approvals",
 92			Date:      now.Add(-2 * time.Hour),
 93			MessageID: "<invoice-300@example.com>",
 94			AccountID: account.ID,
 95			IsRead:    true,
 96		},
 97	}
 98
 99	inbox := tui.NewInbox(emails, []config.Account{account})
100	inbox.SetFolderName("INBOX")
101
102	p := tea.NewProgram(wrapper{inbox: inbox})
103	if _, err := p.Run(); err != nil {
104		fmt.Fprintf(os.Stderr, "Error: %v\n", err)
105		os.Exit(1)
106	}
107}