diff --git a/app/(app)/drawer/courses/courseWork/[...ids].tsx b/app/(app)/drawer/courses/courseWork/[...ids].tsx index 1b57439..9aa5094 100644 --- a/app/(app)/drawer/courses/courseWork/[...ids].tsx +++ b/app/(app)/drawer/courses/courseWork/[...ids].tsx @@ -1,3 +1,4 @@ +import type { classroom_v1 } from '@googleapis/classroom' import { useLocalSearchParams } from 'expo-router' import { useEffect } from 'react' import { View } from 'react-native' @@ -40,13 +41,44 @@ export default function CourseWorkViewer() { {data?.materials && ( <> Attachments - {data.materials.map((material) => ( - - ))} + {data.materials.map((material) => { + // TODO: Move to classroom utils file + const getAttachmentDetails = ( + material: classroom_v1.Schema$Material, + ) => { + if (material.driveFile) { + return { + title: material.driveFile.driveFile!.title!, + link: material.driveFile.driveFile!.alternateLink!, + } + } + if (material.youtubeVideo) { + return { + title: material.youtubeVideo.title!, + link: material.youtubeVideo.alternateLink!, + } + } + if (material.link) { + return { + title: material.link.title || material.link.url, + link: material.link.url!, + } + } + if (material.form) { + return { + title: material.form.title!, + link: material.form.formUrl!, + } + } + return { + title: 'Unknown Material Type', + link: '#', + } + } + + const { title, link } = getAttachmentDetails(material) + return + })} )}