@@ -89,7 +89,10 @@ export default defineComponent({
8989 return 7 * (this .cellSize + this .cellMargin );
9090 },
9191 effectiveActivityRecords(): ActivityRecord [] {
92- return this .localActivityRecords .length > 0 ? this .localActivityRecords : this .activityRecords ;
92+ const useLocal = Array .isArray (this .localActivityRecords ) && this .localActivityRecords .length > 0 ;
93+ const records = useLocal ? this .localActivityRecords : this .activityRecords || [];
94+ console .log (' Using effectiveActivityRecords, count:' , records .length , ' source:' , useLocal ? ' local' : ' prop' );
95+ return records ;
9396 },
9497 },
9598
@@ -107,12 +110,28 @@ export default defineComponent({
107110 if (this .activityRecordsGetter ) {
108111 try {
109112 this .isLoading = true ;
110- this .localActivityRecords = await this .activityRecordsGetter ();
113+ console .log (' Fetching activity records using getter...' );
114+ // Ensure the getter is called safely with proper error handling
115+ const result = await this .activityRecordsGetter ();
116+
117+ if (Array .isArray (result )) {
118+ this .localActivityRecords = result ;
119+ console .log (' Received activity records:' , this .localActivityRecords .length );
120+ // Process the loaded records
121+ this .processRecords ();
122+ this .createWeeksData ();
123+ } else {
124+ console .error (' Activity records getter did not return an array:' , result );
125+ this .localActivityRecords = [];
126+ }
111127 } catch (error ) {
112128 console .error (' Error fetching activity records:' , error );
129+ this .localActivityRecords = [];
113130 } finally {
114131 this .isLoading = false ;
115132 }
133+ } else {
134+ console .log (' No activityRecordsGetter provided, using direct activityRecords prop' );
116135 }
117136 },
118137
@@ -123,35 +142,67 @@ export default defineComponent({
123142 },
124143
125144 processRecords() {
126- const records = this .effectiveActivityRecords ;
145+ const records = this .effectiveActivityRecords || [] ;
127146 console .log (` Processing ${records .length } records ` );
128147
129148 const data: { [key : string ]: number } = {};
130149
150+ if (records .length === 0 ) {
151+ console .log (' No records to process' );
152+ this .heatmapData = data ;
153+ return ;
154+ }
155+
131156 records .forEach ((record ) => {
132- const date = moment (record .timeStamp ).format (' YYYY-MM-DD' );
133- data [date ] = (data [date ] || 0 ) + 1 ;
157+ if (! record || typeof record !== ' object' ) {
158+ console .warn (' Invalid record:' , record );
159+ return ;
160+ }
161+
162+ if (! record .timeStamp ) {
163+ console .warn (' Record missing timeStamp:' , record );
164+ return ;
165+ }
166+
167+ // Make sure timeStamp is properly handled
168+ let date;
169+ try {
170+ // Try to parse the timestamp
171+ const m = moment (record .timeStamp );
172+ if (m .isValid ()) {
173+ date = m .format (' YYYY-MM-DD' );
174+ data [date ] = (data [date ] || 0 ) + 1 ;
175+ } else {
176+ console .warn (' Invalid date from record:' , record );
177+ }
178+ } catch (e ) {
179+ console .error (' Error processing record date:' , e , record );
180+ }
134181 });
135182
183+ console .log (' Processed heatmap data:' , Object .keys (data ).length , ' unique dates' );
136184 this .heatmapData = data ;
137185 },
138186
139187 createWeeksData() {
140188 // Reset weeks and max count
141189 this .weeks = [];
142190 this .maxInRange = 0 ;
143-
191+
144192 const end = moment ();
145193 const start = end .clone ().subtract (52 , ' weeks' );
146194 const day = start .clone ().startOf (' week' );
195+
196+ console .log (' Creating weeks data from' , start .format (' YYYY-MM-DD' ), ' to' , end .format (' YYYY-MM-DD' ));
147197
148198 while (day .isSameOrBefore (end )) {
149199 const weekData: DayData [] = [];
150200 for (let i = 0 ; i < 7 ; i ++ ) {
151201 const date = day .format (' YYYY-MM-DD' );
202+ const count = this .heatmapData [date ] || 0 ;
152203 const dayData: DayData = {
153204 date ,
154- count: this . heatmapData [ date ] || 0 ,
205+ count ,
155206 };
156207 weekData .push (dayData );
157208 if (dayData .count > this .maxInRange ) {
@@ -162,6 +213,10 @@ export default defineComponent({
162213 }
163214 this .weeks .push (weekData );
164215 }
216+
217+ console .log (' Weeks data created, maxInRange:' , this .maxInRange );
218+ console .log (' First week sample:' , this .weeks [0 ]);
219+ console .log (' Last week sample:' , this .weeks [this .weeks .length - 1 ]);
165220 },
166221
167222 getColor(count : number ): string {
0 commit comments