Merge pull request #76 from fawni/feat/twitch-channels-sort

Add custom sorting to the twitch channels widget
This commit is contained in:
Svilen Markov
2024-05-18 11:05:55 +01:00
committed by GitHub
5 changed files with 158 additions and 1 deletions

View File

@@ -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
}