Skip to content

Commit

Permalink
mv OnlineStatusController.initOnlineEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Bulat committed Mar 11, 2024
1 parent a613ab9 commit 15a6c06
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 0 additions & 4 deletions src/contexts/Api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useTabs } from 'contexts/Tabs';
import { useEventListener } from 'usehooks-ts';
import { isCustomEvent } from 'Utils';
import type { APIChainSpec, ApiStatus } from 'model/Api/types';
import { OnlineStatusController } from 'controllers/OnlineStatusController';

export const Api = createContext<ApiContextInterface>(defaultApiContext);

Expand Down Expand Up @@ -151,9 +150,6 @@ export const ApiProvider = ({ children }: { children: ReactNode }) => {

// Initialisation of Api.
useEffect(() => {
// Start listening for online / offline events.
OnlineStatusController.initOnlineEvents();

// Instantiate Api instances from tabs.
tabs.forEach((tab) => {
if (tab.autoConnect) {
Expand Down
8 changes: 7 additions & 1 deletion src/library/Offline/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import { Wrapper } from './Wrapper';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faWarning } from '@fortawesome/free-solid-svg-icons';
import { useRef, useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import { useEventListener } from 'usehooks-ts';
import { isCustomEvent } from 'Utils';
import { OnlineStatusController } from 'controllers/OnlineStatusController';

export const Offline = () => {
// Whether the app is offline.
Expand All @@ -21,6 +22,11 @@ export const Offline = () => {
};

// Listen for online status updates.
useEffect(() => {
// Start listening for online / offline events.
OnlineStatusController.initOnlineEvents();
}, []);

const documentRef = useRef<Document>(document);
useEventListener('online-status', handleOnlineStatus, documentRef);

Expand Down

0 comments on commit 15a6c06

Please sign in to comment.