@@ -8,9 +8,15 @@ import { parseUsageCsvText, type ParsedReport } from "@/lib/report";
88 * `public/preloaded-report.csv` and it is fetched on load, parsed, and locked
99 * so users cannot upload, replace, or clear it. Absent the file, the app
1010 * behaves normally. The base path keeps the URL correct under GitHub Pages.
11+ *
12+ * A second optional CSV at `public/preloaded-report-previous.csv` is loaded as
13+ * the previous-month comparison report when (and only when) the primary
14+ * preloaded report is present; it is locked the same way.
1115 */
1216const PRELOADED_REPORT_FILE = "preloaded-report.csv" ;
1317const PRELOADED_REPORT_URL = `${ process . env . NEXT_PUBLIC_BASE_PATH ?? "" } /${ PRELOADED_REPORT_FILE } ` ;
18+ const PRELOADED_COMPARISON_FILE = "preloaded-report-previous.csv" ;
19+ const PRELOADED_COMPARISON_URL = `${ process . env . NEXT_PUBLIC_BASE_PATH ?? "" } /${ PRELOADED_COMPARISON_FILE } ` ;
1420
1521interface ReportContextValue {
1622 report : ParsedReport | null ;
@@ -61,6 +67,19 @@ export function ReportProvider({ children }: { children: React.ReactNode }) {
6167 const parsed = parseUsageCsvText ( text , PRELOADED_REPORT_FILE ) ;
6268 setReport ( parsed ) ;
6369 setLocked ( true ) ;
70+
71+ // Only probe for the optional previous-month report once the primary
72+ // preloaded report is in place; a comparison without a primary report
73+ // has nothing to compare against.
74+ try {
75+ const cmp = await fetch ( PRELOADED_COMPARISON_URL , { signal : controller . signal } ) ;
76+ if ( cmp . ok && ! ( cmp . headers . get ( "content-type" ) ?? "" ) . includes ( "text/html" ) ) {
77+ const cmpText = await cmp . text ( ) ;
78+ setComparisonReport ( parseUsageCsvText ( cmpText , PRELOADED_COMPARISON_FILE ) ) ;
79+ }
80+ } catch {
81+ // No preloaded comparison, or it could not be parsed: leave it unset.
82+ }
6483 } catch {
6584 // No preloaded report, or it could not be parsed: normal upload mode.
6685 } finally {
0 commit comments