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); + } + diff --git a/assets/javascripts/discourse/components/rewind.gjs b/assets/javascripts/discourse/components/rewind.gjs index 1b4cb8d..e09772f 100644 --- a/assets/javascripts/discourse/components/rewind.gjs +++ b/assets/javascripts/discourse/components/rewind.gjs @@ -109,7 +109,7 @@ export default class Rewind extends Component {
- {{log this.rewind}} + {{#each this.rewind as |report|}}
{{#if (eq report.identifier "reactions")}} diff --git a/spec/.gitkeep b/spec/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/system/kitchen_sink_spec.rb b/spec/system/kitchen_sink_spec.rb deleted file mode 100644 index 0e03be2..0000000 --- a/spec/system/kitchen_sink_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -describe "Discourse Rewind - kitchen sink", type: :system do - fab!(:current_user) { Fabricate(:user) } - - before do - SiteSetting.discourse_reactions_enabled = true - SiteSetting.chat_enabled = true - SiteSetting.discourse_rewind_enabled = true - - sign_in(current_user) - - # reactions received - reactions = %w[open_mouth confetti_ball hugs +1 laughing heart] - Fabricate - .times(10, :post, user: current_user) - .each do |post| - DiscourseReactions::Reaction.create!( - created_at: (Date.new(2024, 1, 1) + rand(1..200).days), - post:, - reaction_value: reactions.sample, - ) - end - - # reading time - 100.times do |i| - UserVisit.create!( - user_id: current_user.id, - time_read: rand(1..200), - visited_at: (Date.new(2024, 1, 1) + i.days).strftime("%Y-%m-%d"), - ) - end - - # calendar - Fabricate.times(10, :post, user: current_user, created_at: Date.new(2024, 1, 25)) - Fabricate.times(1, :post, user: current_user, created_at: Date.new(2024, 3, 12)) - Fabricate.times(5, :post, user: current_user, created_at: Date.new(2024, 8, 19)) - Fabricate.times(1, :post, user: current_user, created_at: Date.new(2024, 10, 29)) - Fabricate.times(20, :post, user: current_user, created_at: Date.new(2024, 11, 2)) - end - - it "can visit the rewind page" do - visit("/my/activity/rewind") - - pause_test - end -end