Skip to content

Commit

Permalink
refactor(forum): refactor AddBadge Action
Browse files Browse the repository at this point in the history
  • Loading branch information
Burial0268 committed Jul 5, 2023
1 parent 0c1590c commit 44d65cd
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions js/src/forum/ProcessData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@ export default class ProcessData {

process(errorNotice: NestedStringArray) {
const elements = {} as Data
const badgeAttrs = app.forum.attribute('BadgeOptions')
const badgeAttrs: string = app.forum.attribute('BadgeOptions')
const maxErrorCount: number = app.forum.attribute('MaxCount')

for (const [key, value] of Object.entries(this.data)) {
if (badgeAttrs == null) return false

elements[key] = value || errorNotice
}

return elements
return this.noError(badgeAttrs, maxErrorCount) && elements
}

noError(badgeAttrs: string, maxErrorCount: number): boolean {
let count = 0

if (badgeAttrs == null) return false
badgeAttrs.split('|')
.map(value => {
if (this.data[value] == null || this.data[value] == '') ++count
})
return count < maxErrorCount;

}
}

0 comments on commit 44d65cd

Please sign in to comment.