Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ jobs:
uses: DouglasNeuroinformatics/.github/.github/workflows/app-release.yaml@main
with:
org: DouglasNeuroinformatics
packages: open-data-capture-api, open-data-capture-gateway, open-data-capture-api
packages: open-data-capture-api, open-data-capture-gateway, open-data-capture-web
validate_command: GATEWAY_DATABASE_URL=file:${TMPDIR}tmp.db pnpm lint
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';

import { Button, Separator } from '@douglasneuroinformatics/libui/components';
import { useTheme, useTranslation } from '@douglasneuroinformatics/libui/hooks';
import { useNotificationsStore, useTheme, useTranslation } from '@douglasneuroinformatics/libui/hooks';
import type { Theme } from '@douglasneuroinformatics/libui/hooks';
import type { Language } from '@opendatacapture/runtime-core';
import type { Language, RuntimeNotification } from '@opendatacapture/runtime-core';
import { $Json } from '@opendatacapture/schemas/core';
import type { Json } from '@opendatacapture/schemas/core';
import { FullscreenIcon, ZoomInIcon, ZoomOutIcon } from 'lucide-react';
Expand All @@ -20,6 +20,7 @@ export const InteractiveContent = React.memo<InteractiveContentProps>(function I
bundle,
onSubmit
}) {
const addNotification = useNotificationsStore((store) => store.addNotification);
const { changeLanguage, resolvedLanguage } = useTranslation();
const [_, updateTheme] = useTheme();
const [scale, setScale] = useState(100);
Expand Down Expand Up @@ -80,6 +81,12 @@ export const InteractiveContent = React.memo<InteractiveContentProps>(function I
return () => document.removeEventListener('done', handleDoneEvent, false);
}, [handleDoneEvent]);

useEffect(() => {
const handler = (event: CustomEvent<RuntimeNotification>) => addNotification(event.detail);
document.addEventListener('addNotification', handler, false);
return () => document.removeEventListener('addNotification', handler, false);
}, []);

const dimensions = `${(100 / scale) * 100}%`;

return (
Expand Down
3 changes: 2 additions & 1 deletion packages/react-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import type { Theme } from '@douglasneuroinformatics/libui/hooks';
import type { Language } from '@douglasneuroinformatics/libui/i18n';
import type { AnyUnilingualInstrument, Json } from '@opendatacapture/runtime-core';
import type { AnyUnilingualInstrument, Json, RuntimeNotification } from '@opendatacapture/runtime-core';
import type { Subject } from '@opendatacapture/schemas/subject';
import type { Promisable } from 'type-fest';

declare global {
interface GlobalEventHandlersEventMap {
addNotification: CustomEvent<RuntimeNotification>;
changeLanguage: CustomEvent<Language>;
changeTheme: CustomEvent<Theme>;
done: CustomEvent<Json>;
Expand Down
1 change: 1 addition & 0 deletions packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './define.js';
export * from './i18n.js';
export * from './notifications.js';
export type * from './types/core.js';
export type * from './types/instrument.base.js';
export type * from './types/instrument.core.js';
Expand Down
11 changes: 11 additions & 0 deletions packages/runtime-core/src/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export type RuntimeNotification = {
message?: string;
title?: string;
type: 'error' | 'info' | 'success' | 'warning';
variant?: 'critical' | 'standard';
};

/** Display a notification in ODC for the user during an interactive instrument. Please note this will not work with forms. */
export function addNotification(notification: RuntimeNotification) {
window.parent.document.dispatchEvent(new CustomEvent('addNotification', { detail: notification }));
}