diff --git a/src/lib/stores/types.ts b/src/lib/stores/types.ts index 7572d1bf..01fad164 100644 --- a/src/lib/stores/types.ts +++ b/src/lib/stores/types.ts @@ -25,7 +25,7 @@ export interface State { export interface User { uid: string; - createdOn: { seconds: number; nanoseconds: number }; + createdOn: { seconds: number; nanoseconds: number; }; enrolled: boolean; onboarded: boolean; demographicsData: object; @@ -36,9 +36,28 @@ export interface UserStudies { } export interface UserStudy { - joinedOn: { seconds: number; nanoseconds: number }; + joinedOn: { seconds: number; nanoseconds: number; }; enrolled: false; } -// FIXME: this should be well-defined and probably should live elsewhere. -export interface StudyMetadata { } +export interface StudyMetadata { + name: string; + description: string; + studyId?: string; + tags: string[]; + icons: Record; + addonId?: string; + authors: { + name: string; + url?: string; + }; + endDate: string; + version: string; + studyEnded: boolean; + studyPaused: boolean; + downloadLink: string; + schemaNamespace?: string; + studyDetailsLink: string; + minimumCoreVersion?: string; + dataCollectionDetails: string[]; +} \ No newline at end of file diff --git a/src/routes/studies/index.svelte b/src/routes/studies/index.svelte index a70f30a4..eab403b1 100644 --- a/src/routes/studies/index.svelte +++ b/src/routes/studies/index.svelte @@ -14,18 +14,26 @@ const notifications: NotificationStore = getContext("rally:notifications"); function joinStudy(studyId) { + const study = $store.studies.find((s) => s.studyId === studyId); + + if (!study) { + throw new Error(`Study with id: ${studyId} not found.`); + } + + window.open(study.downloadLink, "_blank"); + store.updateStudyEnrollment(studyId, true); notifications.send({ code: "SUCCESSFULLY_JOINED_STUDY" }); } + function leaveStudy(studyId) { store.updateStudyEnrollment(studyId, false); notifications.send({ code: "SUCCESSFULLY_LEFT_STUDY" }); } - + $: if ($store._initialized) { if (!$store?.user?.uid) { goto("/signup"); - } else if (!$store?.user?.enrolled) { goto("/welcome/terms"); }