diff --git a/app/services/discourse_rewind/rewind/action/reactions.rb b/app/services/discourse_rewind/rewind/action/reactions.rb
index ad70308..7ab2554 100644
--- a/app/services/discourse_rewind/rewind/action/reactions.rb
+++ b/app/services/discourse_rewind/rewind/action/reactions.rb
@@ -3,9 +3,22 @@
# For a most user / received reactions cards
module DiscourseRewind
class Rewind::Action::Reactions < Rewind::Action::BaseReport
- def call
- data = {}
+ FakeData = {
+ data: {
+ post_received_reactions: {
+ "open_mouth" => 10,
+ },
+ post_used_reactions: {
+ "open_mouth" => 10,
+ },
+ },
+ identifier: "reactions",
+ }
+ def call
+ return FakeData if Rails.env.development?
+
+ data = {}
if defined?(DiscourseReactions::Reaction)
# This is missing heart reactions (default like)
data[:post_used_reactions] = DiscourseReactions::Reaction
diff --git a/app/services/discourse_rewind/rewind/action/word_cloud.rb b/app/services/discourse_rewind/rewind/action/word_cloud.rb
index 311ad5f..638c1dd 100644
--- a/app/services/discourse_rewind/rewind/action/word_cloud.rb
+++ b/app/services/discourse_rewind/rewind/action/word_cloud.rb
@@ -3,7 +3,21 @@
# User Word Cloud
module DiscourseRewind
class Rewind::Action::WordCloud < Rewind::Action::BaseReport
+ FakeData = {
+ data: [
+ { word: "what", score: 100 },
+ { word: "have", score: 90 },
+ { word: "you", score: 80 },
+ { word: "achieved", score: 70 },
+ { word: "this", score: 60 },
+ { word: "week", score: 50 },
+ ],
+ identifier: "word-cloud",
+ }
+
def call
+ return FakeData if Rails.env.development?
+
words = DB.query(<<~SQL, user_id: user.id, date_start: date.first, date_end: date.last)
WITH popular_words AS (
SELECT
@@ -27,7 +41,7 @@ module DiscourseRewind
ndoc DESC,
word
LIMIT
- 5
+ 100
), lex AS (
SELECT
DISTINCT ON (lexeme) to_tsvector('english', word) as lexeme,
@@ -65,7 +79,7 @@ module DiscourseRewind
LIMIT 100
SQL
- word_score = words.map { [_1.original_word, _1.ndoc + _1.nentry] }.to_h
+ word_score = words.map { { word: _1.original_word, score: _1.ndoc + _1.nentry } }
{ data: word_score, identifier: "word-cloud" }
end
diff --git a/assets/javascripts/discourse/components/reports/word-card.gjs b/assets/javascripts/discourse/components/reports/word-card.gjs
index f2f32b1..dd4c5b0 100644
--- a/assets/javascripts/discourse/components/reports/word-card.gjs
+++ b/assets/javascripts/discourse/components/reports/word-card.gjs
@@ -1,53 +1,35 @@
import Component from "@glimmer/component";
-import { fn } from "@ember/helper";
-import { concat } from "@ember/helper";
+import { concat, fn } from "@ember/helper";
import { on } from "@ember/modifier";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import emoji from "discourse/helpers/emoji";
+const MYSTERY_EMOJIS = [
+ "mag", // 🔍
+ "question", // ❓
+ "8ball", // 🎱
+ "crystal_ball", // 🔮
+ "crescent_moon", // 🌙
+];
+
+const BACKGROUND_COLORS = [
+ "#FBF5AF",
+ "#28ABE2",
+ "#F0794A",
+ "#E84A51",
+ "#FBF5AF",
+];
+
export default class WordCard extends Component {
- // const mysteryEmojis = [
- // "mag", // 🔍
- // "question", // ❓
- // "8ball", // 🎱
- // "crystal_ball", // 🔮
- // "crescent_moon", // 🌙
- // ];
-
- // const backgroundColors = [
- // "#FBF5AF",
- // "#28ABE2",
- // "#F0794A",
- // "#E84A51",
- // "#FBF5AF",
- // ];
-
get randomStyle() {
return `--rand: ${Math.random()}`;
}
get mysteryData() {
- const mysteryEmojis = [
- "mag", // 🔍
- "question", // ❓
- "8ball", // 🎱
- "crystal_ball", // 🔮
- "crescent_moon", // 🌙
- ];
-
- const backgroundColors = [
- "#FBF5AF",
- "#28ABE2",
- "#F0794A",
- "#E84A51",
- "#FBF5AF",
- ];
-
- const randomIndex = Math.floor(Math.random() * mysteryEmojis.length);
return {
- emoji: mysteryEmojis[randomIndex],
- color: `--mystery-color: ${backgroundColors[randomIndex]}`,
+ emoji: MYSTERY_EMOJIS[this.args.index],
+ color: `--mystery-color: ${BACKGROUND_COLORS[this.args.index]}`,
};
}
diff --git a/assets/javascripts/discourse/components/reports/word-cards.gjs b/assets/javascripts/discourse/components/reports/word-cards.gjs
index 532a163..680c42d 100644
--- a/assets/javascripts/discourse/components/reports/word-cards.gjs
+++ b/assets/javascripts/discourse/components/reports/word-cards.gjs
@@ -1,16 +1,22 @@
import Component from "@glimmer/component";
import WordCard from "discourse/plugins/discourse-rewind/discourse/components/reports/word-card";
-// eslint-disable-next-line ember/no-empty-glimmer-component-classes
export default class WordCards extends Component {
+ get topWords() {
+ return this.args.report.data.sort((a, b) => b.score - a.score).slice(0, 5);
+ }
+
Word Usage