aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2024-08-07 20:52:34 +0200
committerRobin Jarry <robin@jarry.cc>2024-08-20 12:26:47 +0200
commitd0be49b932dc2d728cd7ecc4c1c22faf470d771a (patch)
treebe8028c2e07fbca27628fd9cd8eb2c7e47d08019
parent5dd579aaeba9f38a823698de54429d75e65a383a (diff)
downloadaerc-d0be49b932dc2d728cd7ecc4c1c22faf470d771a.tar.gz
account: extract configure logic
Extract a function to configure the account view from the constructor; rebuild the grid whenever the config data changed on a hot-reload. Signed-off-by: Koni Marti <koni.marti@gmail.com> Tested-by: Inwit <inwit@sindominio.net> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--app/account.go39
1 files changed, 22 insertions, 17 deletions
diff --git a/app/account.go b/app/account.go
index e13da1b6..ffc7f146 100644
--- a/app/account.go
+++ b/app/account.go
@@ -61,15 +61,6 @@ func NewAccountView(
acct: acct,
}
- view.grid = ui.NewGrid().Rows([]ui.GridSpec{
- {Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
- }).Columns([]ui.GridSpec{
- {Strategy: ui.SIZE_EXACT, Size: func() int {
- return view.UiConfig().SidebarWidth
- }},
- {Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
- })
-
worker, err := worker.NewWorker(acct.Source, acct.Name)
if err != nil {
SetError(fmt.Sprintf("%s: %s", acct.Name, err))
@@ -79,17 +70,10 @@ func NewAccountView(
view.worker = worker
view.dirlist = NewDirectoryList(acct, worker)
- if view.UiConfig().SidebarWidth > 0 {
- view.grid.AddChild(ui.NewBordered(view.dirlist, ui.BORDER_RIGHT, view.UiConfig()))
- }
view.msglist = NewMessageList(view)
- view.grid.AddChild(view.msglist).At(0, 1)
- view.dirlist.OnVirtualNode(func() {
- view.msglist.SetStore(nil)
- view.Invalidate()
- })
+ view.Configure()
go func() {
defer log.PanicHandler()
@@ -111,6 +95,27 @@ func NewAccountView(
return view, nil
}
+func (acct *AccountView) Configure() {
+ acct.dirlist.OnVirtualNode(func() {
+ acct.msglist.SetStore(nil)
+ acct.Invalidate()
+ })
+ sidebar := acct.UiConfig().SidebarWidth
+ acct.grid = ui.NewGrid().Rows([]ui.GridSpec{
+ {Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
+ }).Columns([]ui.GridSpec{
+ {Strategy: ui.SIZE_EXACT, Size: func() int {
+ return sidebar
+ }},
+ {Strategy: ui.SIZE_WEIGHT, Size: ui.Const(1)},
+ })
+ if sidebar > 0 {
+ acct.grid.AddChild(ui.NewBordered(acct.dirlist, ui.BORDER_RIGHT, acct.UiConfig()))
+ }
+ acct.grid.AddChild(acct.msglist).At(0, 1)
+ acct.setTitle()
+}
+
func (acct *AccountView) SetStatus(setters ...state.SetStateFunc) {
for _, fn := range setters {
fn(&acct.state, acct.SelectedDirectory())