Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Status message not cleared #53810

Merged
merged 13 commits into from
Jan 13, 2025
29 changes: 29 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {findFocusedRoute} from '@react-navigation/native';
import {format} from 'date-fns';
import React, {memo, useEffect, useRef, useState} from 'react';
import {NativeModules, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
Expand All @@ -13,12 +14,14 @@
import TestToolsModal from '@components/TestToolsModal';
import * as TooltipManager from '@components/Tooltip/EducationalTooltip/TooltipManager';
import useActiveWorkspace from '@hooks/useActiveWorkspace';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useOnboardingFlowRouter from '@hooks/useOnboardingFlow';
import usePermissions from '@hooks/usePermissions';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {READ_COMMANDS} from '@libs/API/types';
import DateUtils from '@libs/DateUtils';
import HttpUtils from '@libs/HttpUtils';
import KeyboardShortcut from '@libs/KeyboardShortcut';
import Log from '@libs/Log';
Expand Down Expand Up @@ -147,7 +150,7 @@
return;
}

currentAccountID = value.accountID ?? -1;

Check failure on line 153 in src/libs/Navigation/AppNavigator/AuthScreens.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check


if (Navigation.isActiveRoute(ROUTES.SIGN_IN_MODAL)) {
// This means sign in in RHP was successful, so we can subscribe to user events
Expand Down Expand Up @@ -237,6 +240,7 @@
const rootNavigatorOptions = useRootNavigatorOptions();
const {canUseDefaultRooms} = usePermissions();
const {activeWorkspaceID} = useActiveWorkspace();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const {toggleSearch} = useSearchRouterContext();

const modal = useRef<OnyxTypes.Modal>({});
Expand All @@ -249,7 +253,7 @@
}

const initialReport = ReportUtils.findLastAccessedReport(!canUseDefaultRooms, shouldOpenOnAdminRoom(), activeWorkspaceID);
return initialReport?.reportID ?? '';

Check failure on line 256 in src/libs/Navigation/AppNavigator/AuthScreens.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

});

useEffect(() => {
Expand Down Expand Up @@ -402,6 +406,31 @@
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, []);

const clearStatus = () => {
User.updateDraftCustomStatus({
text: '',
emojiCode: '',
clearAfter: DateUtils.getEndOfToday(),
});
};
useEffect(() => {
const currentTime = format(new Date(), 'yyyy-MM-dd HH:mm:ss');
if (!currentUserPersonalDetails.status?.clearAfter) {
return;
}
if (new Date(currentUserPersonalDetails.status?.clearAfter).getTime() > new Date(currentTime).getTime()) {
const subMilisecondsTime = new Date(currentUserPersonalDetails.status?.clearAfter).getTime() - new Date(currentTime).getTime();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make the code cleaner like

    if (!currentUserPersonalDetails.status?.clearAfter) {
        return;
    }
    const currentTime = new Date();
    const clearAfterTime = new Date(currentUserPersonalDetails.status.clearAfter);
    if (isNaN(clearAfterTime.getTime())) {
        return;
    }
    const timeDifference = clearAfterTime.getTime() - currentTime.getTime();
    if (subMilisecondsTime > 0) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eh2077 i updated

const timeoutID = setTimeout(() => {
clearStatus();
}, subMilisecondsTime);
return () => {
clearTimeout(timeoutID);
};
}

clearStatus();
}, [currentUserPersonalDetails.status?.clearAfter]);

const CentralPaneScreenOptions: PlatformStackNavigationOptions = {
...hideKeyboardOnSwipe,
headerShown: false,
Expand Down
Loading