mirror of
https://github.com/Xevion/glance.git
synced 2025-12-09 18:07:15 -06:00
Merge pull request #76 from fawni/feat/twitch-channels-sort
Add custom sorting to the twitch channels widget
This commit is contained in:
@@ -14,6 +14,7 @@ type TwitchChannels struct {
|
||||
ChannelsRequest []string `yaml:"channels"`
|
||||
Channels []feed.TwitchChannel `yaml:"-"`
|
||||
CollapseAfter int `yaml:"collapse-after"`
|
||||
SortBy string `yaml:"sort-by"`
|
||||
}
|
||||
|
||||
func (widget *TwitchChannels) Initialize() error {
|
||||
@@ -23,6 +24,10 @@ func (widget *TwitchChannels) Initialize() error {
|
||||
widget.CollapseAfter = 5
|
||||
}
|
||||
|
||||
if widget.SortBy != "viewers" && widget.SortBy != "live" {
|
||||
widget.SortBy = "viewers"
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -33,7 +38,12 @@ func (widget *TwitchChannels) Update(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
channels.SortByViewers()
|
||||
if widget.SortBy == "viewers" {
|
||||
channels.SortByViewers()
|
||||
} else if widget.SortBy == "live" {
|
||||
channels.SortByLive()
|
||||
}
|
||||
|
||||
widget.Channels = channels
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user