Skip to content

Commit

Permalink
Merge pull request #45 from dwarvesf/fix/update-memo-list-layout
Browse files Browse the repository at this point in the history
fix: update memo list layout
  • Loading branch information
baenv authored Jun 28, 2024
2 parents a621b5e + 25e2034 commit 3133722
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions pkg/discord/view/memo/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import (
"github.com/dwarvesf/fortress-discord/pkg/model"
)

var (
memoCategoryList = []string{memoCategoryFleeting, memoCategoryLiterature, memoCategoryOthers}
)

const (
memoCategoryFleeting = "00_fleeting"
memoCategoryLiterature = "01_literature"
memoCategoryOthers = "others"
)

func (v *Memo) List(original *model.DiscordMessage, memos []*model.Memo) error {
var content string
for i := range memos {
Expand All @@ -29,17 +39,30 @@ func (v *Memo) List(original *model.DiscordMessage, memos []*model.Memo) error {
func (v *Memo) ListMemoLogs(original *model.DiscordMessage, memos []model.MemoLog, timeAmount int, timeUnit string) error {
var content string

memosByCategory := make(map[string][]model.MemoLog)
//Group by category
memosByCategory := map[string][]model.MemoLog{
memoCategoryFleeting: make([]model.MemoLog, 0),
memoCategoryLiterature: make([]model.MemoLog, 0),
memoCategoryOthers: make([]model.MemoLog, 0),
}

for _, mem := range memos {
if len(mem.Category) > 0 {
memosByCategory[mem.Category[len(mem.Category)-1]] = append(memosByCategory[mem.Category[len(mem.Category)-1]], mem)
continue
isMapped := false
for _, category := range mem.Category {
if strings.EqualFold(category, memoCategoryFleeting) || strings.EqualFold(category, memoCategoryLiterature) {
memosByCategory[category] = append(memosByCategory[category], mem)
isMapped = true
break
}
}

memosByCategory["others"] = append(memosByCategory["others"], mem)
if !isMapped {
memosByCategory[memoCategoryOthers] = append(memosByCategory[memoCategoryOthers], mem)
}
}

for category, memos := range memosByCategory {
for _, category := range memoCategoryList {
memos := memosByCategory[category]
content += fmt.Sprintf("🔹 **%s** - %v posts\n", strings.ToUpper(category), len(memos))

tooLarge := false
Expand Down

0 comments on commit 3133722

Please sign in to comment.