mirror of
https://github.com/bookorbit/bookorbit.git
synced 2026-11-03 00:11:37 -06:00
fix(kobo): use server reading streak on plugin dashboard
Prefer the server account reading streak when provided by the dashboard endpoint, falling back to local KOReader statistics database data when offline or absent. This aligns the KOReader plugin day streak display with the web app. Closes #711
This commit is contained in:
@@ -36,6 +36,7 @@ local BookOrbitStatsReader = require("bookorbit_stats_reader")
|
||||
|
||||
local formatDuration = CatalogUtil.formatDuration
|
||||
local formatProgress = CatalogUtil.formatProgress
|
||||
local readingStreakDays = CatalogUtil.readingStreakDays
|
||||
|
||||
local BookOrbitDashboardCoverCard = CatalogWidgets.DashboardCoverCard
|
||||
local BookOrbitDashboardHeroCard = CatalogWidgets.DashboardHeroCard
|
||||
@@ -455,8 +456,8 @@ function CatalogDashboard:addDashboardEmptyState(text, button_text, callback)
|
||||
end
|
||||
|
||||
-- Local reading activity from statistics.sqlite3, cached briefly so row page
|
||||
-- turns do not reopen the database. Returns nil when there is nothing to
|
||||
-- show (no stats database, or no recorded reading at all).
|
||||
-- turns do not reopen the database. The local streak is retained as a fallback
|
||||
-- for cached responses from servers that do not provide the account streak.
|
||||
function CatalogDashboard:dashboardStatsSummary()
|
||||
local cache = self._dash_stats_cache
|
||||
if not cache or os.time() - cache.at >= STATS_CACHE_TTL then
|
||||
@@ -477,10 +478,11 @@ end
|
||||
function CatalogDashboard:buildDashboardStatsStrip(summary, dashboard, height)
|
||||
local sep_w = Size.line.thin
|
||||
local today_seconds = summary.today_seconds or 0
|
||||
local streak_days = readingStreakDays(dashboard, summary.streak_days)
|
||||
local blocks = {
|
||||
{ value = today_seconds > 0 and formatDuration(today_seconds) or _("Not yet"), label = _("Today") },
|
||||
{ value = formatDuration(summary.week_seconds or 0), label = _("Past 7 days") },
|
||||
{ value = tostring(summary.streak_days or 0), label = _("Day streak") },
|
||||
{ value = tostring(streak_days), label = _("Day streak") },
|
||||
}
|
||||
local total = dashboard and tonumber(dashboard.totalBooks or dashboard.bookCount)
|
||||
if total then
|
||||
|
||||
@@ -136,6 +136,13 @@ function CatalogUtil.formatProgress(value)
|
||||
return tostring(math.floor(value + 0.5)) .. "%"
|
||||
end
|
||||
|
||||
function CatalogUtil.readingStreakDays(dashboard, fallback)
|
||||
local reading_streak = dashboard and dashboard.readingStreak
|
||||
local current_streak = reading_streak and tonumber(reading_streak.currentStreak)
|
||||
if current_streak then return current_streak end
|
||||
return tonumber(fallback) or 0
|
||||
end
|
||||
|
||||
function CatalogUtil.formatRating(value)
|
||||
if not value then return nil end
|
||||
if value == math.floor(value) then
|
||||
|
||||
Reference in New Issue
Block a user