8 Commits
Author SHA1 Message Date
Rafael Silva 4b1af6f717 cache fix 2025-01-15 12:06:06 -03:00
Rafael dos Santos Silva 19af3cb107 Merge pull request #7 from jjaffeux/category-links
UX: Match category cards with tag cards
2025-01-15 09:45:32 -03:00
Jordan Vidrine 7cc39605f5 linting 2025-01-14 19:02:34 -06:00
Jordan Vidrine fed8205a64 DEV: Add fake category data 2025-01-14 15:57:23 -06:00
Jordan Vidrine d669a39a00 UX: Make card clickable link 2025-01-14 15:55:14 -06:00
Jordan Vidrine 6a55f56b91 Merge pull request #6 from jjaffeux/reading-series 2025-01-14 15:37:39 -06:00
Jordan Vidrine 2bb1072d29 Merge pull request #5 from jjaffeux/long-words 2025-01-14 11:38:43 -06:00
Jordan Vidrine ff72e3ed37 UX: Adjust styles for long words 2025-01-14 11:30:13 -06:00
8 changed files with 76 additions and 40 deletions
@@ -7,7 +7,7 @@ module DiscourseRewind
FakeData = {
data:
(Date.new(2024, 1, 1)..Date.new(2024, 12, 31)).map do |date|
{ date:, post_count: rand(0..20), visited: false }
{ date: date.strftime("%Y-%m-%d"), post_count: rand(0..20), visited: false }
end,
identifier: "activity-calendar",
}
@@ -33,7 +33,13 @@ module DiscourseRewind
)
.group("generate_series, user_visits.id")
.order("generate_series")
.map { |row| { date: row.date, post_count: row.post_count, visited: row.visited } }
.map do |row|
{
date: row.date.strftime("%Y-%m-%d"),
post_count: row.post_count,
visited: row.visited,
}
end
{ data: calendar, identifier: "activity-calendar" }
end
@@ -3,7 +3,19 @@
# Topics visited grouped by category
module DiscourseRewind
class Rewind::Action::FavoriteCategories < Rewind::Action::BaseReport
FakeData = {
data: [
{ category_id: 1, name: "cats" },
{ category_id: 2, name: "dogs" },
{ category_id: 3, name: "countries" },
{ category_id: 4, name: "management" },
{ category_id: 5, name: "things" },
],
identifier: "favorite-categories",
}
def call
return FakeData if Rails.env.development?
favorite_categories =
TopicViewItem
.joins(:topic)
@@ -6,32 +6,32 @@ module DiscourseRewind
FakeData = {
data: {
post_received_reactions: {
"open_mouth" => 2,
"cat" => 32,
"dog" => 34,
"heart" => 45,
"grinning" => 82,
open_mouth: 2,
cat: 32,
dog: 34,
heart: 45,
grinning: 82,
},
post_used_reactions: {
"open_mouth" => 2,
"cat" => 32,
"dog" => 34,
"heart" => 45,
"grinning" => 82,
open_mouth: 2,
cat: 32,
dog: 34,
heart: 45,
grinning: 82,
},
chat_used_reactions: {
"open_mouth" => 2,
"cat" => 32,
"dog" => 34,
"heart" => 45,
"grinning" => 82,
open_mouth: 2,
cat: 32,
dog: 34,
heart: 45,
grinning: 82,
},
chat_received_reactions: {
"open_mouth" => 2,
"cat" => 32,
"dog" => 34,
"heart" => 45,
"grinning" => 82,
open_mouth: 2,
cat: 32,
dog: 34,
heart: 45,
grinning: 82,
},
},
identifier: "reactions",
@@ -7,7 +7,7 @@ module DiscourseRewind
{ word: "what", score: 100 },
{ word: "have", score: 90 },
{ word: "you", score: 80 },
{ word: "achieved", score: 70 },
{ word: "overachieved", score: 70 },
{ word: "this", score: 60 },
{ word: "week", score: 50 },
],
+12 -12
View File
@@ -51,19 +51,19 @@ module DiscourseRewind
end
def fetch_reports(date:, user:, guardian:, year:)
# key = "rewind:#{guardian.user.username}:#{year}"
# reports = Discourse.redis.get(key)
key = "rewind:#{guardian.user.id}:#{year}"
cached_reports = Discourse.redis.get(key)
# if Rails.env.development? || !reports
reports =
::DiscourseRewind::Rewind::Action::BaseReport
.descendants
.filter { _1.enabled? }
.map { |report| report.call(date:, user:, guardian:) }
# Discourse.redis.setex(key, CACHE_DURATION, MultiJson.dump(reports))
# else
# reports = MultiJson.load(reports.compact, symbolize_keys: true)
# end
if !cached_reports
reports =
::DiscourseRewind::Rewind::Action::BaseReport
.descendants
.filter { _1.enabled? }
.map { |report| report.call(date:, user:, guardian:) }
Discourse.redis.setex(key, CACHE_DURATION, reports.to_json)
else
reports = JSON.parse(cached_reports, symbolize_names: true)
end
reports
end
@@ -10,12 +10,12 @@ const FavoriteCategories = <template>
}}</h2>
<div class="rewind-report-container">
{{#each @report.data as |data|}}
<div class="rewind-card">
<a
<a href={{concat "/c/-/" data.category_id}} class="rewind-card">
<p
class="favorite-categories__category"
href={{concat "/c/-/" data.category_id}}
>{{data.name}}</a>
</div>
>{{data.name}}</p>
</a>
{{/each}}
</div>
</div>
@@ -3,6 +3,7 @@ import { on } from "@ember/modifier";
import { action } from "@ember/object";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { htmlSafe } from "@ember/template";
import concatClass from "discourse/helpers/concat-class";
import emoji from "discourse/helpers/emoji";
import discourseLater from "discourse-common/lib/later";
@@ -45,6 +46,10 @@ export default class WordCard extends Component {
};
}
get longWord() {
return this.args.word.length >= 7;
}
get cardStyle() {
return htmlSafe(`${this.randomStyle}; ${this.mysteryData.color};`);
}
@@ -72,7 +77,10 @@ export default class WordCard extends Component {
<div
{{on "click" this.handleClick}}
{{on "mouseleave" this.handleLeave}}
class="rewind-card__wrapper"
class={{concatClass
"rewind-card__wrapper"
(if this.longWord "-long-word")
}}
style={{this.cardStyle}}
{{didInsert this.registerCardContainer}}
role="button"
+10
View File
@@ -137,6 +137,16 @@
0 0 / 6px 6px,
var(--secondary-low);
}
&.-long-word .rewind-card__title {
font-size: var(--font-0);
}
&.-long-word .rewind-card {
padding: 2px;
}
.rewind-card__title {
overflow-wrap: anywhere;
hyphens: auto;
}
.rewind-card__image {
image-rendering: pixelated;
}