Skip to content

Commit

Permalink
chore: resolve linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pac-guerreiro committed Jan 29, 2024
1 parent da4ffd7 commit c8fa793
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ const CONST = {
DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'},
DEFAULT_ACCOUNT_DATA: {errors: null, success: '', isLoading: false},
DEFAULT_CLOSE_ACCOUNT_DATA: {errors: null, success: '', isLoading: false},
DEFAULT_NETWORK_DATA: {isOffline: false},
FORMS: {
LOGIN_FORM: 'LoginForm',
VALIDATE_CODE_FORM: 'ValidateCodeForm',
Expand Down
5 changes: 3 additions & 2 deletions src/hooks/useNetwork.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import {useContext, useEffect, useRef} from 'react';
import {NetworkContext} from '@components/OnyxProvider';
import CONST from '@src/CONST';

type UseNetworkProps = {
onReconnect?: () => void;
};

type UseNetwork = {isOffline?: boolean};
type UseNetwork = {isOffline: boolean};

export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = {}): UseNetwork {
const callback = useRef(onReconnect);
callback.current = onReconnect;

const {isOffline} = useContext(NetworkContext) ?? {};
const {isOffline} = useContext(NetworkContext) ?? CONST.DEFAULT_NETWORK_DATA;
const prevOfflineStatusRef = useRef(isOffline);
useEffect(() => {
// If we were offline before and now we are not offline then we just reconnected
Expand Down
9 changes: 5 additions & 4 deletions src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli
const {isSmallScreenWidth} = useWindowDimensions();
const [visibility, setVisibility] = useState<ValueOf<typeof CONST.REPORT.VISIBILITY>>(CONST.REPORT.VISIBILITY.RESTRICTED);
const [writeCapability, setWriteCapability] = useState<ValueOf<typeof CONST.REPORT.WRITE_CAPABILITIES>>(CONST.REPORT.WRITE_CAPABILITIES.ALL);
const wasLoading = usePrevious(formState?.isLoading);
const wasLoading = usePrevious<boolean>(!!formState?.isLoading);
const visibilityDescription = useMemo(() => translate(`newRoomPage.${visibility}Description`), [translate, visibility]);
const {isLoading = false, errorFields = {}} = formState ?? {};

const workspaceOptions = useMemo(
() =>
Expand Down Expand Up @@ -100,7 +101,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli
participants,
values.roomName,
CONST.REPORT.CHAT_TYPE.POLICY_ROOM,
policyID ?? undefined,
policyID,
CONST.REPORT.OWNER_ACCOUNT_ID_FAKE,
false,
'',
Expand Down Expand Up @@ -134,12 +135,12 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli
}, [activePolicyID, policyID, workspaceOptions]);

useEffect(() => {
if (!(((wasLoading && !formState?.isLoading) || (isOffline && formState?.isLoading)) && isEmptyObject(formState?.errorFields))) {
if (!(((wasLoading && !isLoading) || (isOffline && isLoading)) && isEmptyObject(errorFields))) {
return;
}
Navigation.dismissModal(newRoomReportID);
// eslint-disable-next-line react-hooks/exhaustive-deps -- we just want this to update on changing the form State
}, [formState]);
}, [isLoading, errorFields]);

useEffect(() => {
if (isPolicyAdmin) {
Expand Down
2 changes: 1 addition & 1 deletion src/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default function () {
// Clear any loading and error messages so they do not appear on app startup
[ONYXKEYS.SESSION]: {loading: false},
[ONYXKEYS.ACCOUNT]: CONST.DEFAULT_ACCOUNT_DATA,
[ONYXKEYS.NETWORK]: {isOffline: false},
[ONYXKEYS.NETWORK]: CONST.DEFAULT_NETWORK_DATA,
[ONYXKEYS.IS_SIDEBAR_LOADED]: false,
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: true,
[ONYXKEYS.MODAL]: {
Expand Down
2 changes: 1 addition & 1 deletion src/types/onyx/Network.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type Network = {
/** Is the network currently offline or not */
isOffline?: boolean;
isOffline: boolean;

/** Should the network be forced offline */
shouldForceOffline?: boolean;
Expand Down

0 comments on commit c8fa793

Please sign in to comment.