feat: finalize academy redesign and production readiness
Align admin, community, search, library, learning and course management with the mockup. Add saved courses, download history, public community feed, instructor directory, backend search, course views, admin content tools and community moderation. Harden API and Nginx for production.
This commit is contained in:
14
lib/downloads.ts
Normal file
14
lib/downloads.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { Attachment } from '../types';
|
||||
|
||||
export type DownloadEntry = { attachment: Attachment; courseId: string; courseTitle: string; downloadedAt: string };
|
||||
const keyFor = (userId: string) => `ca-downloads:${userId}`;
|
||||
export const readDownloads = (userId?: string): DownloadEntry[] => {
|
||||
if (!userId) return [];
|
||||
try { const value = JSON.parse(localStorage.getItem(keyFor(userId)) || '[]'); return Array.isArray(value) ? value : []; }
|
||||
catch { return []; }
|
||||
};
|
||||
export const recordDownload = (userId: string, attachment: Attachment, courseId: string, courseTitle: string) => {
|
||||
const entry: DownloadEntry = { attachment, courseId, courseTitle, downloadedAt: new Date().toISOString() };
|
||||
const next = [entry, ...readDownloads(userId).filter((item) => item.attachment.id !== attachment.id)].slice(0, 100);
|
||||
try { localStorage.setItem(keyFor(userId), JSON.stringify(next)); window.dispatchEvent(new Event('ca-downloads')); } catch { /* A completed download does not depend on local history. */ }
|
||||
};
|
||||
Reference in New Issue
Block a user