Skip to content

Commit

Permalink
(chore) register Offline Handler
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-jofrancisco committed Dec 19, 2023
1 parent 63768af commit 01a286e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ const OfflineReadyModal: React.FC<OfflineActionsProgressModalProps> = ({ closeMo
const [abortController, setAbortController] = useState(() => new AbortController());

async function dispatchOfflineEvent() {
//TODO CHANGE MODE
let mode = getCurrentOfflineMode().active;
window.dispatchEvent(
new CustomEvent(`openmrs:offline-${mode ? 'enabled' : 'disabled'}`, {
new CustomEvent(`openmrs:offline-enabled`, {
detail: getCurrentOfflineMode(),
}),
);
Expand Down
6 changes: 2 additions & 4 deletions packages/apps/esm-offline-tools-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineConfigSchema, getSyncLifecycle, registerBreadcrumbs } from '@openmrs/esm-framework';
import { defineConfigSchema, getSyncLifecycle, registerBreadcrumbs, registerOfflineHandler } from '@openmrs/esm-framework';
import { routes } from './constants';
import { createDashboardLink } from './createDashboardLink';
import { dashboardMeta } from './dashboard.meta';
Expand Down Expand Up @@ -88,11 +88,9 @@ export const offlineToolsOptInButton = getSyncLifecycle(offlineToolsOptInButtonC

export function startupApp() {
defineConfigSchema(moduleName, {});
setupOffline();
registerOfflineHandler(setupOffline);
setupSynchronizingOfflineActionsNotifications();

// registerOfflineHandler(setupOffline);

registerBreadcrumbs([
{
path: `${window.spaBase}/${routes.offlineTools}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function SynchronizingNotification({ mySynchronizationIndex }) {
<div className={styles.notificationLoadingContainer}>
{isCanceled
? t('offlineActionsSynchronizationNotificationCanceling', 'Canceling...')
: t('offlineActionsSynchronizationNotificationStatus', '{current} / {total} actions', {
: t('offlineActionsSynchronizationNotificationStatus', '{{current}} / {{total}} actions', {
current: synchronization.totalCount - synchronization.pendingCount,
total: synchronization.totalCount,
})}
Expand Down
5 changes: 1 addition & 4 deletions packages/framework/esm-offline/src/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ export function setCurrentOfflineMode(mode: OfflineMode) {
localStorage.setItem(offlineModeStorageKey, mode === 'on' ? 'active' : 'disabled');
offlineMode = mode;
}
lastRun = new Date().toLocaleString();
}

export function registerOfflineHandler(setupOffline: OfflineHandler) {
window.addEventListener('openmrs:offline-enabled', setupOffline);
const offlineMode = getCurrentOfflineMode();
if (offlineMode.active) {
setupOffline();
}
}

export async function activateOfflineCapability() {
Expand Down

0 comments on commit 01a286e

Please sign in to comment.