File size: 1,694 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package actions

import (
	"fmt"
	"github.com/pinchtab/pinchtab/internal/cli/apiclient"
	"github.com/spf13/cobra"
	"net/http"
)

// Back navigates the current (or specified) tab back in history.
func Back(client *http.Client, base, token string, cmd *cobra.Command) {
	tabID, _ := cmd.Flags().GetString("tab")
	path := "/back"
	if tabID != "" {
		path = fmt.Sprintf("/tabs/%s/back", tabID)
	}
	apiclient.DoPost(client, base, token, path, nil)
}

// Forward navigates the current (or specified) tab forward in history.
func Forward(client *http.Client, base, token string, cmd *cobra.Command) {
	tabID, _ := cmd.Flags().GetString("tab")
	path := "/forward"
	if tabID != "" {
		path = fmt.Sprintf("/tabs/%s/forward", tabID)
	}
	apiclient.DoPost(client, base, token, path, nil)
}

// Reload reloads the current (or specified) tab.
func Reload(client *http.Client, base, token string, cmd *cobra.Command) {
	tabID, _ := cmd.Flags().GetString("tab")
	path := "/reload"
	if tabID != "" {
		path = fmt.Sprintf("/tabs/%s/reload", tabID)
	}
	apiclient.DoPost(client, base, token, path, nil)
}

func Navigate(client *http.Client, base, token string, url string, cmd *cobra.Command) {
	body := map[string]any{"url": url}
	if v, _ := cmd.Flags().GetBool("new-tab"); v {
		body["newTab"] = true
	}
	if v, _ := cmd.Flags().GetBool("block-images"); v {
		body["blockImages"] = true
	}
	if v, _ := cmd.Flags().GetBool("block-ads"); v {
		body["blockAds"] = true
	}
	tabID, _ := cmd.Flags().GetString("tab")
	path := "/navigate"
	if tabID != "" {
		path = fmt.Sprintf("/tabs/%s/navigate", tabID)
	}
	result := apiclient.DoPost(client, base, token, path, body)
	apiclient.SuggestNextAction("navigate", result)
}