Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(analytics): show uploads by month or week on the Videos page

spacesdrive3894c84558f9
diff --git a/docs/architecture/data-flows/ANALYTICS.md b/docs/architecture/data-flows/ANALYTICS.md
index 30f2325..8b49ed7 100644
--- a/docs/architecture/data-flows/ANALYTICS.md
+++ b/docs/architecture/data-flows/ANALYTICS.md
@@ -328,6 +328,9 @@ These rules come from the UI/UX guide (issue #132) and apply to every analytics
axis shows rounded ones. A legend appears where a chart has more than one series. Platform hues
(`PLATFORM_META.series`) mean the platform on every page; Instagram content types and categories use other
series. The big value of a metric tile rolls to its new value (`RollingNumber`) and keeps its exact value.
+ The Videos page has an Uploads card (`StackedBars`): the channel's uploads in each of the last 12 months or 13
+ weeks, split into regular videos and Shorts by the Shorts page's 60-second rule (`uploadsChart.ts`). It follows the
+ channel filter only, and counts the up to 500 newest videos the library loads per channel.
- **Libraries.** Search (debounced), filters, sort, layout and page live in the address (`useLibraryParams`), so
Back, refresh and shared links keep the view. Every library uses the same controls: `SearchField`, an account
select, `FilterChips` for ranges and types, `SortSelect` (also in grid layout), `ActiveFilters` with the result
diff --git a/docs/architecture/frontend/DESIGN_SYSTEM.md b/docs/architecture/frontend/DESIGN_SYSTEM.md
index e0e4519..a690770 100644
--- a/docs/architecture/frontend/DESIGN_SYSTEM.md
+++ b/docs/architecture/frontend/DESIGN_SYSTEM.md
@@ -50,7 +50,7 @@ Shared components live in `frontend/src/components/`. Reach for these before wri
| `ExactTooltip` | Intent's tooltip with every value in full (`tooltip={<ExactTooltip />}`); `format` for rates, `labelOf` when one series mixes kinds |
| `DonutChart` | Parts of a whole as a ring inside Intent's chart frame, with the exact tooltip and a legend |
| `MetricAreaChart` | A single-series Intent area chart with its own screen-reader name and description |
-| `StackedBars` | A card of counts per day or week broken into parts, with a view switch; not used yet, since no page receives counts per period split into parts |
+| `StackedBars` | A card of counts per period broken into parts, with a view switch (adapted from Bencho, MIT): run along the bars or use the arrow keys to read one, announced in a status line. Used for Uploads on the Videos page (videos and Shorts by month or week, `uploadsChart.ts`) |
| `RollingNumber` | A formatted number whose digits roll like an odometer when it changes; screen readers get the text. Used through `MetricBox` and the Overview metric tabs (`RollingValueContext` makes a `Num` inside a tile roll) |
| `ChoiceCard` | Large selectable cards in creation flows |
| `DetailPanel`, `FieldRow` | The settings side panel of a working surface, and label plus hint plus control plus error rows. `FieldRow` wires `hint` and `error` to its control (`aria-describedby`, `aria-invalid`), marks `optional` fields, and renders a `fieldset` with `group`. A control that is not its direct child takes the ids from `fieldHintId` and `fieldErrorId` in `lib/fieldIds.ts` |
diff --git a/frontend/src/features/analytics/videos/VideoExplorer.tsx b/frontend/src/features/analytics/videos/VideoExplorer.tsx
index 4cca480..43b4a70 100644
--- a/frontend/src/features/analytics/videos/VideoExplorer.tsx
+++ b/frontend/src/features/analytics/videos/VideoExplorer.tsx
@@ -13,9 +13,11 @@ import DataFreshness from '@/components/DataFreshness';
import ActiveFilters from '@/components/ActiveFilters';
import NoResults from '@/components/NoResults';
import FailedSourcesAlert from '@/components/FailedSourcesAlert';
+import StackedBars from '@/components/StackedBars';
import { EmptyState } from '@/components/StateViews';
import { VIEW_TIERS, pageSlice, resultCountLabel } from '@/lib/library';
import { METRIC_ICONS } from '@/lib/metricIcons';
+import { SERIES } from '@/lib/chart';
import { useChannelVideos } from './useChannelVideos';
import { useLibraryParams } from '../useLibraryParams';
import { VIDEO_SORT_OPTIONS, filterAndSortVideos, nextSort, sortFromKey, sortKeyOf, videoStatsOf, videosDescription } from './videoLibrary.ts';
@@ -24,10 +26,17 @@ import VideoFilters from './VideoFilters';
import VideoListTable from './VideoListTable';
import VideoGrid from './VideoGrid';
import type { LayoutMode } from './LayoutToggle';
+import { uploadsByPeriod } from './uploadsChart.ts';
const ITEMS_PER_PAGE = 25;
const RESULTS_ID = 'video-results';
+// a year by month and a quarter by week show the publishing rhythm without crowding the bars
+const UPLOAD_MONTHS = 12;
+const UPLOAD_WEEKS = 13;
+// both kinds are YouTube, so they share its red family and leave the other hues to the other platforms
+const UPLOAD_SERIES = [{ label: 'Videos', color: SERIES.primary }, { label: 'Shorts', color: SERIES.deep }];
+
const DEFAULTS = { q: '', channel: 'all', views: 'all', sort: 'viewCount:desc', view: 'table' };
const { videos: Videos, views: Views, likes: Likes, comments: Comments, averageViews: AverageViews } = METRIC_ICONS;
@@ -44,6 +53,14 @@ export default function VideoExplorer() {
);
const paged = pageSlice(filtered, page, ITEMS_PER_PAGE);
const stats = useMemo(() => videoStatsOf(filtered), [filtered]);
+ // the rhythm follows the channel filter only; a search or a view tier would hide uploads, not explain them
+ const uploadViews = useMemo(() => {
+ const channelVideos = values.channel === 'all' ? videos : videos.filter(video => video.channelId === values.channel);
+ return [
+ { id: 'month', label: 'Month', points: uploadsByPeriod(channelVideos, 'month', UPLOAD_MONTHS) },
+ { id: 'week', label: 'Week', points: uploadsByPeriod(channelVideos, 'week', UPLOAD_WEEKS) },
+ ];
+ }, [videos, values.channel]);
const handleSort = (field: VideoSortField) => update({ sort: sortKeyOf(nextSort(sort, field)) });
const clearFilters = () => clear(['q', 'channel', 'views']);
@@ -111,6 +128,14 @@ export default function VideoExplorer() {
<MetricBox small icon={<AverageViews />} label="Average views" value={<Num value={stats.avgViews} />} period="Per matching video" />
</div>
+ <StackedBars
+ title="Uploads"
+ subtitle={`Videos and Shorts published${channelTitle ? ` on ${channelTitle}` : ''}, newest on the right`}
+ unit="uploads"
+ series={UPLOAD_SERIES}
+ views={uploadViews}
+ />
+
<VideoFilters
channels={channels}
search={values.q}
diff --git a/frontend/src/features/analytics/videos/uploadsChart.ts b/frontend/src/features/analytics/videos/uploadsChart.ts
new file mode 100644
index 0000000..dd76fd3
--- /dev/null
+++ b/frontend/src/features/analytics/videos/uploadsChart.ts
@@ -0,0 +1,52 @@
+import { isShort } from '../shorts/shortsLibrary.ts';
+import type { StackedPoint } from '../../../lib/stackedBars.ts';
+import type { LibraryVideo } from './videoLibrary.ts';
+
+export type UploadPeriod = 'month' | 'week';
+
+const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+const DAY_MS = 86_400_000;
+
+// weeks start on Monday, in the viewer's own time zone, like the schedule pickers
+function weekStart(date: Date): Date {
+ const start = new Date(date.getFullYear(), date.getMonth(), date.getDate());
+ start.setDate(start.getDate() - ((start.getDay() + 6) % 7));
+ return start;
+}
+
+function periodStarts(period: UploadPeriod, count: number, now: Date): Date[] {
+ if (period === 'month') {
+ return Array.from({ length: count }, (_, index) => new Date(now.getFullYear(), now.getMonth() - (count - 1 - index), 1));
+ }
+ const current = weekStart(now);
+ return Array.from({ length: count }, (_, index) => {
+ const start = new Date(current);
+ start.setDate(current.getDate() - 7 * (count - 1 - index));
+ return start;
+ });
+}
+
+function labelsOf(period: UploadPeriod, start: Date): { label: string; short: string } {
+ const month = MONTHS[start.getMonth()];
+ if (period === 'month') return { label: `${month} ${start.getFullYear()}`, short: month };
+ const end = new Date(start.getTime() + 6 * DAY_MS);
+ const endText = end.getMonth() === start.getMonth() ? `${end.getDate()}` : `${MONTHS[end.getMonth()]} ${end.getDate()}`;
+ return { label: `${month} ${start.getDate()} to ${endText}`, short: `${month} ${start.getDate()}` };
+}
+
+// uploads in each of the last `count` months or weeks, the current one last, split into regular videos and Shorts
+export function uploadsByPeriod(videos: LibraryVideo[], period: UploadPeriod, count: number, now = new Date()): StackedPoint[] {
+ const starts = periodStarts(period, count, now);
+ const counts = starts.map(() => [0, 0]);
+ for (const video of videos) {
+ const published = new Date(video.publishedAt);
+ if (Number.isNaN(published.getTime())) continue;
+ let index = -1;
+ for (let candidate = starts.length - 1; candidate >= 0; candidate--) {
+ if (published >= starts[candidate]) { index = candidate; break; }
+ }
+ if (index === -1 || published > now) continue;
+ counts[index][isShort(video) ? 1 : 0] += 1;
+ }
+ return starts.map((start, index) => ({ ...labelsOf(period, start), values: counts[index] }));
+}
diff --git a/frontend/tests/features/analytics/videos/uploadsChart.test.ts b/frontend/tests/features/analytics/videos/uploadsChart.test.ts
new file mode 100644
index 0000000..d9e27ef
--- /dev/null
+++ b/frontend/tests/features/analytics/videos/uploadsChart.test.ts
@@ -0,0 +1,34 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { uploadsByPeriod } from '../../../../src/features/analytics/videos/uploadsChart.ts';
+import type { LibraryVideo } from '../../../../src/features/analytics/videos/videoLibrary.ts';
+
+const video = (publishedAt: string, durationSeconds: number) => ({ publishedAt, durationSeconds }) as LibraryVideo;
+const now = new Date(2026, 10, 5, 12);
+
+test('months run oldest first and end with the current month', () => {
+ const points = uploadsByPeriod([], 'month', 3, now);
+ assert.deepEqual(points.map(point => point.label), ['Sep 2026', 'Oct 2026', 'Nov 2026']);
+ assert.deepEqual(points.map(point => point.short), ['Sep', 'Oct', 'Nov']);
+});
+
+test('each month counts regular videos first and Shorts second', () => {
+ const points = uploadsByPeriod([
+ video(new Date(2026, 9, 3).toISOString(), 600),
+ video(new Date(2026, 9, 20).toISOString(), 45),
+ video(new Date(2026, 10, 1).toISOString(), 45),
+ ], 'month', 2, now);
+ assert.deepEqual(points.map(point => point.values), [[1, 1], [0, 1]]);
+});
+
+test('uploads older than the range are left out', () => {
+ const points = uploadsByPeriod([video(new Date(2025, 0, 1).toISOString(), 600)], 'month', 3, now);
+ assert.equal(points.reduce((sum, point) => sum + point.values[0] + point.values[1], 0), 0);
+});
+
+test('weeks start on Monday and read as a date range', () => {
+ const points = uploadsByPeriod([video(new Date(2026, 10, 2, 9).toISOString(), 30)], 'week', 2, now);
+ assert.equal(points[1].label, 'Nov 2 to 8');
+ assert.equal(points[0].label, 'Oct 26 to Nov 1');
+ assert.deepEqual(points[1].values, [0, 1]);
+});