Add custom sorting to the twitch channels widget
this allows the channels to be sorted as defined in the config while still keeping the live channels on the top. the wording could probably be improved, "custom" is too broad but i'm not sure what else to call it.
This commit is contained in:
3 files changed
+21
-1
No files matched your search
@@ -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 != "custom" {
|
||||
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 == "custom" {
|
||||
channels.SortByLive()
|
||||
}
|
||||
|
||||
widget.Channels = channels
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user