- commit
- 5b57de3
- parent
- 0759d85
- author
- Eric Bower
- date
- 2023-11-16 20:12:40 +0000 UTC
chore: add tokens view to pgs cms (#60)
3 files changed,
+30,
-6
+29,
-0
1@@ -20,6 +20,7 @@ import (
2 "github.com/picosh/pico/wish/cms/ui/common"
3 "github.com/picosh/pico/wish/cms/ui/info"
4 "github.com/picosh/pico/wish/cms/ui/keys"
5+ "github.com/picosh/pico/wish/cms/ui/tokens"
6 "github.com/picosh/pico/wish/cms/ui/username"
7 "github.com/picosh/pico/wish/cms/util"
8 )
9@@ -31,6 +32,7 @@ const (
10 statusReady
11 statusNoAccount
12 statusBrowsingKeys
13+ statusBrowsingTokens
14 statusSettingUsername
15 statusQuitting
16 )
17@@ -53,6 +55,7 @@ type menuChoice int
18 const (
19 setUserChoice menuChoice = iota
20 keysChoice
21+ tokensChoice
22 exitChoice
23 unsetChoice // set when no choice has been made
24 )
25@@ -61,6 +64,7 @@ const (
26 var menuChoices = map[menuChoice]string{
27 setUserChoice: "Set username",
28 keysChoice: "Manage keys",
29+ tokensChoice: "Manage tokens",
30 exitChoice: "Exit",
31 }
32
33@@ -153,6 +157,7 @@ type model struct {
34 spinner spinner.Model
35 username username.Model
36 keys keys.Model
37+ tokens tokens.Model
38 createAccount account.CreateModel
39 terminalSize tea.WindowSizeMsg
40 }
41@@ -239,6 +244,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
42 m.username = username.NewModel(m.dbpool, m.user, m.sshUser)
43 m.info = info.NewModel(m.cfg, m.urls, m.user)
44 m.keys = keys.NewModel(m.cfg, m.dbpool, m.user)
45+ m.tokens = tokens.NewModel(m.cfg, m.dbpool, m.user)
46 m.createAccount = account.NewCreateModel(m.cfg, m.dbpool, m.publicKey)
47 }
48
49@@ -247,6 +253,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
50 m.username = username.NewModel(m.dbpool, m.user, m.sshUser)
51 m.info = info.NewModel(m.cfg, m.urls, m.user)
52 m.keys = keys.NewModel(m.cfg, m.dbpool, m.user)
53+ m.tokens = tokens.NewModel(m.cfg, m.dbpool, m.user)
54 m.createAccount = account.NewCreateModel(m.cfg, m.dbpool, m.publicKey)
55 if m.user == nil {
56 m.status = statusNoAccount
57@@ -283,6 +290,22 @@ func updateChildren(msg tea.Msg, m model) (model, tea.Cmd) {
58 m.status = statusQuitting
59 return m, tea.Quit
60 }
61+ case statusBrowsingTokens:
62+ newModel, newCmd := m.tokens.Update(msg)
63+ tokensModel, ok := newModel.(tokens.Model)
64+ if !ok {
65+ panic("could not perform assertion on posts model")
66+ }
67+ m.tokens = tokensModel
68+ cmd = newCmd
69+
70+ if m.tokens.Exit {
71+ m.tokens = tokens.NewModel(m.cfg, m.dbpool, m.user)
72+ m.status = statusReady
73+ } else if m.tokens.Quit {
74+ m.status = statusQuitting
75+ return m, tea.Quit
76+ }
77 case statusSettingUsername:
78 m.username, cmd = username.Update(msg, m.username)
79 if m.username.Done {
80@@ -313,6 +336,10 @@ func updateChildren(msg tea.Msg, m model) (model, tea.Cmd) {
81 m.status = statusBrowsingKeys
82 m.menuChoice = unsetChoice
83 cmd = keys.LoadKeys(m.keys)
84+ case tokensChoice:
85+ m.status = statusBrowsingTokens
86+ m.menuChoice = unsetChoice
87+ cmd = tokens.LoadKeys(m.tokens)
88 case exitChoice:
89 m.status = statusQuitting
90 m.dbpool.Close()
91@@ -370,6 +397,8 @@ func (m model) View() string {
92 s += username.View(m.username)
93 case statusBrowsingKeys:
94 s += m.keys.View()
95+ case statusBrowsingTokens:
96+ s += m.tokens.View()
97 }
98 return m.styles.App.Render(wrap.String(wordwrap.String(s, w), w))
99 }
+0,
-2
1@@ -122,7 +122,6 @@ func (m Model) Init() tea.Cmd {
2
3 // Update is the Bubble Tea update loop.
4 func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5- fmt.Println(msg)
6 switch msg := msg.(type) {
7 case tea.KeyMsg:
8 switch msg.Type {
9@@ -197,7 +196,6 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
10 }
11
12 case TokenSetMsg:
13- fmt.Println("TOKEN SET")
14 m.state = submitted
15 m.token = msg.token
16 return m, nil
+1,
-4
1@@ -271,10 +271,7 @@ func (m Model) View() string {
2 s = m.createKey.View()
3 default:
4 s = "Here are the tokens linked to your account.\n\n"
5- s += "A token can be used for connecting to our IRC bouncer from your client.\n"
6- s += "Authenticating to our bouncer is simple:\n"
7- s += " `username` is your pico user, and \n"
8- s += " `password` are the tokens listed here.\n\n"
9+ s += "A token can be used for connecting to our IRC bouncer from your client.\n\n"
10
11 // Keys
12 s += keysView(m)