Up/down ranking component. Close #4

This commit is contained in:
2023-12-28 19:50:03 -07:00
parent c570c362f3
commit 57ffdb6189
2 changed files with 26 additions and 1 deletions

View File

@@ -669,4 +669,11 @@
args)))
[])
(defCommand RateUp [es (SelectedEntries 1 null) reason (Text null)]
(for e es
(addUpDownRating archive e true reason)))
(defCommand RateDown [es (SelectedEntries 1 null) reason (Text null)]
(for e es
(addUpDownRating archive e false reason)))
)

View File

@@ -172,4 +172,22 @@
(function isEntry [o]
(let [fields (Reflect.fields o)]
(and (= fields.length 3)
(apply and (for f ["id" "components" "files"] (contains fields f))))))
(apply and (for f ["id" "components" "files"] (contains fields f))))))
(function addUpDownRating [:nat.Archive archive :nat.Entry e :Bool up &opt :String reason]
(unless (hasComponent e UpDownRank)
(addComponent archive e UpDownRank (object up 0 down 0 upReasons [] downReasons [])))
(withWritableComponents archive e [rank UpDownRank]
(if up
{
(+= rank.up 1)
(when reason
(rank.upReasons.push reason))
}
{
(+= rank.down 1)
(when reason
(rank.downReasons.push reason))
}))
e)