summaryrefslogtreecommitdiff
path: root/internal/client
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-07-01 10:50:23 +0300
committerPaul Buetow <paul@buetow.org>2024-07-01 10:50:23 +0300
commitecc323b3b45e666a3376d7983424837d58336198 (patch)
tree87b26520609f8cc4b34e4f22f20ed1c2091e8103 /internal/client
parent2a7f70715de89e2aaf9e5f3bf9a22c6ab7426358 (diff)
initial submit
Diffstat (limited to 'internal/client')
-rw-r--r--internal/client/tui/compose.go29
-rw-r--r--internal/client/tui/finishedmsg.go10
-rw-r--r--internal/client/tui/submit.go32
-rw-r--r--internal/client/tui/tui.go13
4 files changed, 66 insertions, 18 deletions
diff --git a/internal/client/tui/compose.go b/internal/client/tui/compose.go
index 7bdfbf3..3ba53ec 100644
--- a/internal/client/tui/compose.go
+++ b/internal/client/tui/compose.go
@@ -6,30 +6,33 @@ import (
"os/exec"
"time"
+ config "codeberg.org/snonux/gos/internal/config/client"
tea "github.com/charmbracelet/bubbletea"
)
-type composeFinishedMsg struct {
- callback func() error
- err error
-}
-
-func composeAction(editor, dataDir string) tea.Cmd {
- // Maybe handle the error explicitly? Should be obvious anyway
- // when the editor can't open the file because directory isn't there
- _ = ensureDirectoryExists(dataDir)
- composeFile := fmt.Sprintf("%s/compose.txt", dataDir)
+func composeAction(conf config.ClientConfig, queue bool) tea.Cmd {
+ err := ensureDirectoryExists(conf.DataDir)
+ composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile)
- return openEditor(editor, composeFile, func() error {
+ return openEditor(conf.Editor, composeFile, func() error {
+ if err != nil {
+ return err
+ }
+ if !queue {
+ return nil
+ }
timestamp := time.Now().Format("20060102-150405")
- queuedFile := fmt.Sprintf("%s/queued-%s.txt", dataDir, timestamp)
+ queuedFile := fmt.Sprintf("%s/queued-%s.txt", conf.DataDir, timestamp)
return os.Rename(composeFile, queuedFile)
})
}
func openEditor(editor, filePath string, callback func() error) tea.Cmd {
return tea.ExecProcess(exec.Command(editor, filePath), func(err error) tea.Msg {
- return composeFinishedMsg{callback, err}
+ return finishedMsg{
+ callback: callback,
+ err: err,
+ }
})
}
diff --git a/internal/client/tui/finishedmsg.go b/internal/client/tui/finishedmsg.go
new file mode 100644
index 0000000..9609b93
--- /dev/null
+++ b/internal/client/tui/finishedmsg.go
@@ -0,0 +1,10 @@
+package tui
+
+type finishedMsg struct {
+ callback func() error
+ err error
+}
+
+func (f finishedMsg) Error() string {
+ return f.err.Error()
+}
diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go
new file mode 100644
index 0000000..15b7826
--- /dev/null
+++ b/internal/client/tui/submit.go
@@ -0,0 +1,32 @@
+package tui
+
+import (
+ "fmt"
+
+ config "codeberg.org/snonux/gos/internal/config/client"
+ tea "github.com/charmbracelet/bubbletea"
+)
+
+func submitAction(conf config.ClientConfig) tea.Cmd {
+ // The composed file is now the file to be submitted.
+ //submitFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile)
+
+ /*
+ c := &http.Client{
+ Timeout: 10 * time.Second,
+ }
+ res, err := c.Get(url)
+ if err != nil {
+ return sub{err}
+ }
+ defer res.Body.Close()
+ */
+
+ return func() tea.Msg {
+ err := fmt.Errorf("this is a test errorrrrrr!")
+ return finishedMsg{
+ err: err,
+ }
+ }
+
+}
diff --git a/internal/client/tui/tui.go b/internal/client/tui/tui.go
index 7584ef2..38085f7 100644
--- a/internal/client/tui/tui.go
+++ b/internal/client/tui/tui.go
@@ -31,12 +31,13 @@ type model struct {
}
const (
- composePostCursorPos = 0
+ composeNewPostCursor = iota
+ submitPostCursor
)
func initModel(conf config.ClientConfig) model {
return model{
- choices: []string{"Compose post", "Schedule post"},
+ choices: []string{"Compose post", "Submit post"},
conf: conf,
}
}
@@ -59,8 +60,10 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
case "enter":
switch m.cursor {
- case composePostCursorPos:
- return m, composeAction(m.conf.Editor, m.conf.DataDir)
+ case composeNewPostCursor:
+ return m, composeAction(m.conf, false)
+ case submitPostCursor:
+ return m, submitAction(m.conf)
}
case "a":
@@ -73,7 +76,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case "ctrl+c", "q":
return m, tea.Quit
}
- case composeFinishedMsg:
+ case finishedMsg:
if msg.err != nil {
m.err = msg.err
return m, tea.Quit