Skip to content

Commit

Permalink
Merge pull request #43 from dddwa/yearbook
Browse files Browse the repository at this point in the history
Add yearbook message
  • Loading branch information
JakeGinnivan authored Nov 16, 2024
2 parents b116179 + cd4920c commit 8b3454b
Showing 1 changed file with 46 additions and 33 deletions.
79 changes: 46 additions & 33 deletions website/app/routes/app-announcements.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { trace } from '@opentelemetry/api'
import { json } from '@remix-run/server-runtime'
import { CACHE_CONTROL } from '~/lib/http.server'
import { resolveError } from '~/lib/resolve-error'

export type GoogleFormUpdates = {
Timestamp: string
Expand All @@ -10,45 +8,60 @@ export type GoogleFormUpdates = {

/** This route is used by the app for on the day announcements */
export async function loader() {
const apiKey = process.env.GOOGLE_FORMS_API_KEY
const fileId = process.env.GOOGLE_FORMS_FILE_ID
if (!apiKey || !fileId) {
return new Response(JSON.stringify({ message: 'No Google Forms API key or form ID' }), { status: 404 })
}
// const apiKey = process.env.GOOGLE_FORMS_API_KEY
// const fileId = process.env.GOOGLE_FORMS_FILE_ID
// if (!apiKey || !fileId) {
// return new Response(JSON.stringify({ message: 'No Google Forms API key or form ID' }), { status: 404 })
// }

try {
const BASE_URL = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&key=${apiKey}`
// try {
// const BASE_URL = `https://www.googleapis.com/drive/v3/files/${fileId}?alt=media&key=${apiKey}`

const response = await fetch(BASE_URL, {
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
})
// const response = await fetch(BASE_URL, {
// headers: {
// 'Content-Type': 'application/json',
// Accept: 'application/json',
// },
// })

const responseData = (await response.json()) as GoogleFormUpdates[]
// const responseData = (await response.json()) as GoogleFormUpdates[]

const announcementData = responseData
.map((row) => {
return { createdTime: row.Timestamp, update: row.Message }
})
.sort((a, b) => {
return new Date(b.createdTime).getTime() - new Date(a.createdTime).getTime()
})
// const announcementData = responseData
// .map((row) => {
// return { createdTime: row.Timestamp, update: row.Message }
// })
// .sort((a, b) => {
// return new Date(b.createdTime).getTime() - new Date(a.createdTime).getTime()
// })

return json(announcementData, {
headers: {
'Cache-Control': CACHE_CONTROL.announce,
'Access-Control-Allow-Origin': '*',
// return json(announcementData, {
// headers: {
// 'Cache-Control': CACHE_CONTROL.announce,
// 'Access-Control-Allow-Origin': '*',
// },
// })
// } catch (err) {
// trace.getActiveSpan()?.recordException(resolveError(err))
// return json([], {
// headers: {
// 'Cache-Control': CACHE_CONTROL.announce,
// 'Access-Control-Allow-Origin': '*',
// },
// })
// }

return json(
[
{
createdTime: new Date().toISOString(),
update: 'Get your 2024 Yearbook from the Info Desk!',
},
})
} catch (err) {
trace.getActiveSpan()?.recordException(resolveError(err))
return json([], {
],
{
headers: {
'Cache-Control': CACHE_CONTROL.announce,
'Access-Control-Allow-Origin': '*',
},
})
}
},
)
}

0 comments on commit 8b3454b

Please sign in to comment.