@@ -160,13 +160,12 @@ const AssignmentCodeDescription = {
160160 competitor : 'Competing in:' ,
161161} ;
162162
163- export const generateIcs = ( assignments , fileName ) => {
163+ export const generateIcs = ( assignments , wcif , fileName : string ) => {
164164 if ( ! assignments ) {
165+ //Check if assignments is empty
165166 return ;
166167 }
167168
168- console . log ( assignments ) ;
169-
170169 let events : {
171170 title : string ;
172171 description : string ;
@@ -176,15 +175,15 @@ export const generateIcs = (assignments, fileName) => {
176175 } [ ] = [ ] ;
177176
178177 assignments . forEach ( ( item ) => {
179- const titleFormatted = `${ AssignmentCodeDescription [ item . assignmentCode ] } for ${
178+ const titleFormatted = `${ AssignmentCodeDescription [ item . assignmentCode ] } ${
180179 item . activity . name
181180 } `;
182181 const startDate = new Date ( item . activity . startTime ) ;
183182 const endDate = new Date ( item . activity . endTime ) ;
184183
185184 const startDateArray : ics . DateArray = [
186185 startDate . getFullYear ( ) ,
187- startDate . getMonth ( ) + 1 , // Months are 1-based in ics format
186+ startDate . getMonth ( ) + 1 , // Months are 1-indexed in ics format
188187 startDate . getDate ( ) ,
189188 startDate . getHours ( ) ,
190189 startDate . getMinutes ( ) ,
@@ -197,12 +196,17 @@ export const generateIcs = (assignments, fileName) => {
197196 endDate . getHours ( ) ,
198197 endDate . getMinutes ( ) ,
199198 ] ;
200- endDate ;
199+
200+ const location = {
201+ lat : wcif . schedule . venues [ 0 ] . latitudeMicrodegrees / 100 ,
202+ lon : wcif . schedule . venues [ 0 ] . longitudeMicrodegrees / 100 ,
203+ } ;
201204
202205 const icalEvent = {
203206 title : titleFormatted ,
204207 description : item . activity . name ,
205208 location : item . activity . parent . room . name ,
209+ ...( wcif . schedule . venues . length > 1 ? { } : { geo : location } ) ,
206210 start : startDateArray ,
207211 end : endDateArray ,
208212 } ;
@@ -212,19 +216,14 @@ export const generateIcs = (assignments, fileName) => {
212216
213217 const { error, value } = ics . createEvents ( events ) ;
214218
215- if ( error ) {
216- console . log ( error ) ;
217- return ;
218- }
219-
220- if ( ! value ) {
221- return ;
219+ if ( error || ! value ) {
220+ throw new Error ( 'Failed to create ICS events' ) ;
222221 }
223222
224223 const blob = new Blob ( [ value ] , { type : 'text/calendar' } ) ;
225224 const a = document . createElement ( 'a' ) ;
226225 a . href = URL . createObjectURL ( blob ) ;
227- a . download = ` fileName` ;
226+ a . download = fileName ;
228227 a . style . display = 'none' ;
229228
230229 document . body . appendChild ( a ) ;
0 commit comments