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

[$500] [Wave Collect] [Ideal Nav] Display the home route when the app restarts on mobile platforms #35927

Closed
hayata-suenaga opened this issue Feb 6, 2024 · 32 comments
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2

Comments

@hayata-suenaga
Copy link
Contributor

hayata-suenaga commented Feb 6, 2024

Clear the value for the LAST_VISITED_PATH Onyx key on mobile platforms (i.e. iOS and Android) so that when the app restarts on these platforms, the home route is displayed instead of the last visited route.

Internal Slack discussion

Related issues:

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01e8861874ab17080a
  • Upwork Job ID: 1754921316058124288
  • Last Price Increase: 2024-02-13
  • Automatic offers:
    • HezekielT | Contributor | 0
@hayata-suenaga hayata-suenaga added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Feb 6, 2024
@hayata-suenaga hayata-suenaga self-assigned this Feb 6, 2024
Copy link

melvin-bot bot commented Feb 6, 2024

Triggered auto assignment to @dylanexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@hayata-suenaga hayata-suenaga changed the title [Wave 8] [Ideal Nav] Display the home route when the app restarts [Wave 8] [Ideal Nav] Display the home route when the app restarts on mobile platforms Feb 6, 2024
@hayata-suenaga hayata-suenaga added the External Added to denote the issue can be worked on by a contributor label Feb 6, 2024
@melvin-bot melvin-bot bot changed the title [Wave 8] [Ideal Nav] Display the home route when the app restarts on mobile platforms [$500] [Wave 8] [Ideal Nav] Display the home route when the app restarts on mobile platforms Feb 6, 2024
Copy link

melvin-bot bot commented Feb 6, 2024

Job added to Upwork: https://www.upwork.com/jobs/~01e8861874ab17080a

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 6, 2024
Copy link

melvin-bot bot commented Feb 6, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @rushatgabhane (External)

@Krishna2323
Copy link
Contributor

Krishna2323 commented Feb 6, 2024

Proposal

Please re-state the problem that we are trying to solve in this issue.

Display the home route when the app restarts on mobile platforms.

What is the root cause of that problem?

NA

What changes do you think we should make in order to solve the problem?

We should use AppState to get the state of the app and whenever app is being inactive we can clear LAST_VISITED_PATH using updateLastVisitedPath. We will run this only if the device is an android or ios native device. We can add this logic in App.ts file or in NavigationRoot file.

function updateLastVisitedPath(path: string) {

App/src/libs/actions/App.ts

Lines 138 to 144 in b5bb986

let appState: AppStateStatus;
AppState.addEventListener('change', (nextAppState) => {
if (nextAppState.match(/inactive|background/) && appState === 'active') {
Log.info('Flushing logs as app is going inactive', true, {}, true);
}
appState = nextAppState;
});

Only run when isNative is true:
const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID;

Since there is no simple way to trigger a function when app is being closed we can set the lastVisitedPath in ONYX to an empty string and save the value in a variable and if the app again comes in focus we will set the lastVisitedPath in ONYX to the original value which was there before the app was inactive.

Demo code, can be simplified and tested during the PR
    const [lastVisitedPathBeforeInactive, setLastVisitedPathBeforeInactive] = useState(props.lastVisitedPath);
    const isAppActive = useRef(false);
    const platform = getPlatform();
    const isNative = platform === CONST.PLATFORM.IOS || platform === CONST.PLATFORM.ANDROID;


    useEffect(() => {
        if (!isNative) {
            return;
        }
        const appStateSubscription = AppState.addEventListener('change', (nextAppState) => {
            if (nextAppState.match(/inactive|background/)) {
                isAppActive.current = false;
                setLastVisitedPathBeforeInactive(props.lastVisitedPath);
                updateLastVisitedPath('');
            } else {
                isAppActive.current = true;
                updateLastVisitedPath(lastVisitedPathBeforeInactive);
            }
        });

        return () => {
            appStateSubscription.remove();
        };
    }, [props.disableKeyboard, props.lastVisitedPath, lastVisitedPathBeforeInactive, isNative]);

    useEffect(() => {
        if (!isNative) {
            return;
        }
        if (isAppActive.current) {
            updateLastVisitedPath(props.lastVisitedPath);
        }
    }, [props.lastVisitedPath, isNative]);

Result

navigate_to_homepage_after_restart.mp4
app_restart.mp4

@bernhardoj
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

We want to show the home instead of the last visited route when restarting the native app.

What is the root cause of that problem?

We have a logic here to show the last visited route if exists on all platforms.

const initialState = useMemo(
() => {
if (!lastVisitedPath) {
return undefined;
}
const path = initialUrl ? getPathFromURL(initialUrl) : null;
// For non-nullable paths we don't want to set initial state
if (path) {
return;
}
const {adaptedState} = getAdaptedStateFromPath(lastVisitedPath, linkingConfig.config);
return adaptedState;
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);

And now we want to change it.

Based on the OP, we want to clear the last visited route/path onyx when the app is closed, but there is no way to know whether the app is closed.

What changes do you think we should make in order to solve the problem?

Instead of trying to clear it when the app is closed, we can create a new platform-specific file called shouldOpenLastVisitedPath that will return false for native.ts, then return early if shouldOpenLastVisitedPath is false.

if (!lastVisitedPath || !shouldOpenLastVisitedPath()) {
    return undefined;
}

What alternative solutions did you explore? (Optional)

Or we can create a platform-specific file for updateLastVisitedPath that will do nothing for the native file.

App/src/libs/actions/App.ts

Lines 507 to 509 in 7f4cdce

function updateLastVisitedPath(path: string) {
Onyx.merge(ONYXKEYS.LAST_VISITED_PATH, path);
}

@dylanexpensify
Copy link
Contributor

@rushatgabhane can we get reviews?

@HezekielT
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

Display the home route when the app is restarted.

What is root cause of that problem?

Based on the current implementation we always show the last visited path when opening the app but for native platforms we want to chage that and navigate the user home route instead when the app is opened.

What Changes do you think we should make in order to solve the problem?

When we open the app for the first time or after killing it, we always perform some setup actions while initializing the onyx such as clearing the error which prevents an error from appearing when the app is opened after killing it which means we can also follow a similar approach to address this issue which is to initialize ONYXKEYS.LAST_VISITED_PATH to '' for native platforms. This will cause the app to open the home route instead of the last visited chat when restarting it.

App/src/setup/index.js

Lines 33 to 34 in a1b1595

// Clear any loading and error messages so they do not appear on app startup
[ONYXKEYS.SESSION]: {loading: false},

We can do that by adding the following line of code in initialKeyStates

[ONYXKEYS.LAST_VISITED_PATH]: initializeLastVisitedPath()

where initializeLastVisitedPath function is defined as

function initializeLastVisitedPath() {
    if(!(getPlatform() === CONST.PLATFORM.IOS || getPlatform() === CONST.PLATFORM.ANDROID())) {
        return;
    }
    return '';
}

given that this is how we perform actions such as clearing an error, we might as well use a similar approach to redirect the user to home route.

This works as expected.

What alternative solutions did you explore? (Optional)

None

@rushatgabhane
Copy link
Member

i like @bernhardoj's proposal

#35927 (comment)

🎀👀🎀

Copy link

melvin-bot bot commented Feb 7, 2024

Current assignee @hayata-suenaga is eligible for the choreEngineerContributorManagement assigner, not assigning anyone new.

@HezekielT
Copy link
Contributor

@rushatgabhane What do you think about my proposal?

@bernhardoj
Copy link
Contributor

I think @HezekielT suggestion is nicer.

@hayata-suenaga
Copy link
Contributor Author

@rushatgabhane can you check @HezekielT's proposal again? @bernhardoj thinks @HezekielT's proposal is better

@melvin-bot melvin-bot bot added the Overdue label Feb 12, 2024
Copy link

melvin-bot bot commented Feb 12, 2024

@rushatgabhane, @dylanexpensify, @hayata-suenaga Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@hayata-suenaga
Copy link
Contributor Author

bump @rushatgabhane

@melvin-bot melvin-bot bot removed the Overdue label Feb 12, 2024
@hayata-suenaga
Copy link
Contributor Author

there is an additional discussion on this issue

It's an internal link. I'll post updates once the discussion concludes.

Copy link

melvin-bot bot commented Feb 13, 2024

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@hayata-suenaga
Copy link
Contributor Author

@dylanexpensify
Copy link
Contributor

thank you!

@hayata-suenaga
Copy link
Contributor Author

I confirmed that we want to display the Home route when the app restarts on mobile platforms. And by "Home" route, we mean the chat list screen without any workspace filter applied.

@rushatgabhane, please look at this comment and confirm who we should assign the issue to. 🙇

@rushatgabhane
Copy link
Member

rushatgabhane commented Feb 15, 2024

@hayata-suenaga We can assign @HezekielT, i like their proposal better because setup is the place Onyx is initialized

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Feb 15, 2024
Copy link

melvin-bot bot commented Feb 15, 2024

📣 @HezekielT 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

Offer link
Upwork job
Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑‍💻
Keep in mind: Code of Conduct | Contributing 📖

@hayata-suenaga
Copy link
Contributor Author

@HezekielT this is a HIGH priority issue. If you could prioritize this one, we'd appreciate it 🙇

@HezekielT
Copy link
Contributor

Thanks @bernhardoj for the suggestion. I really appreciate that. Thanks @rushatgabhane as well for reconsidering my proposal.

@HezekielT
Copy link
Contributor

@hayata-suenaga PR is ready

@dylanexpensify
Copy link
Contributor

PR merged! Pending payout if no regressions!

@dylanexpensify
Copy link
Contributor

coming up!

@rushatgabhane
Copy link
Member

created money req - https://staging.new.expensify.com/r/2577190139543546

@JmillsExpensify
Copy link

Mind adding a payment summary @dylanexpensify?

@trjExpensify trjExpensify changed the title [$500] [Wave 8] [Ideal Nav] Display the home route when the app restarts on mobile platforms [$500] [Wave Collect] [Ideal Nav] Display the home route when the app restarts on mobile platforms Mar 5, 2024
@dylanexpensify
Copy link
Contributor

Payment summary:

Please apply/request

@JmillsExpensify
Copy link

$500 approved for @rushatgabhane based on summary.

@HezekielT
Copy link
Contributor

@dylanexpensify Friendly bump for payment

@dylanexpensify
Copy link
Contributor

Done!

@hayata-suenaga hayata-suenaga removed the Reviewing Has a PR in review label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Weekly KSv2
Projects
Archived in project
Status: Release 1: Ideal Nav & Collect Simplfied Profile, Members, Categories, Workflows (approvals)
Development

No branches or pull requests

7 participants