Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
51e15ea
Preserve offline state when signing out
yuwenmemon Dec 6, 2022
3f696ad
Use keyStatesToPreserve instead
yuwenmemon Dec 6, 2022
bf1c4e9
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 6, 2022
9fef987
Semi colon
yuwenmemon Dec 6, 2022
b707787
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 7, 2022
e3a5174
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 8, 2022
e968a16
keyStatesToPreserve -> keysToPreserve
yuwenmemon Dec 9, 2022
6ed7781
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 9, 2022
748c7a7
Also preserve active clients
yuwenmemon Dec 9, 2022
f405f1f
Bump Onyx version
yuwenmemon Dec 9, 2022
c372860
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 9, 2022
ab14ca4
Make sure Network test uses Onyx call that would set keysToPreserve a…
yuwenmemon Dec 9, 2022
3a49c3f
Add comment
yuwenmemon Dec 12, 2022
390ea5f
Preserve certain keystates always
yuwenmemon Dec 13, 2022
7d0a7e7
Remove unneeded ONYX connections
yuwenmemon Dec 13, 2022
6401f5e
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 13, 2022
9e43b33
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 13, 2022
fbbb00d
Merge branch 'main' of github.com:Expensify/App into yuwen-preserveOf…
yuwenmemon Dec 14, 2022
6227a80
Upgrade to onyx version 1.0.31
yuwenmemon Dec 14, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"react-native-image-picker": "^4.10.2",
"react-native-image-size": "git+https://github.com/Expensify/react-native-image-size#6b5ab5110dc3ed554f8eafbc38d7d87c17147972",
"react-native-modal": "^13.0.0",
"react-native-onyx": "1.0.29",
"react-native-onyx": "1.0.31",
"react-native-pdf": "^6.6.2",
"react-native-performance": "^2.0.0",
"react-native-permissions": "^3.0.1",
Expand Down
51 changes: 17 additions & 34 deletions src/libs/actions/SignInRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import * as Localize from '../Localize';
import * as PersistedRequests from './PersistedRequests';
import NetworkConnection from '../NetworkConnection';

let currentActiveClients;
Onyx.connect({
key: ONYXKEYS.ACTIVE_CLIENTS,
callback: (val) => {
currentActiveClients = !val ? [] : val;
},
});

let currentPreferredLocale;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: val => currentPreferredLocale = val,
});

let currentIsOffline;
let currentShouldForceOffline;
Onyx.connect({
Expand All @@ -37,31 +23,28 @@ Onyx.connect({
* @param {String} errorMessage
*/
function clearStorageAndRedirect(errorMessage) {
const activeClients = currentActiveClients;
const preferredLocale = currentPreferredLocale;
const isOffline = currentIsOffline;
const shouldForceOffline = currentShouldForceOffline;
// Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out.
// We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting
// flashes of unwanted default state.
const keysToPreserve = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NAB: Add a comment above keysToPreserve explaining why we preserve some keys and how that works.

keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE);
keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS);

// After signing out, set ourselves as offline if we were offline before logging out and we are not forcing it.
// If we are forcing offline, ignore it while signed out, otherwise it would require a refresh because there's no way to toggle the switch to go back online while signed out.
if (currentIsOffline && !currentShouldForceOffline) {
keysToPreserve.push(ONYXKEYS.NETWORK);
}

// Clearing storage discards the authToken. This causes a redirect to the SignIn screen
Onyx.clear()
Onyx.clear(keysToPreserve)
.then(() => {
if (preferredLocale) {
Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, preferredLocale);
}
if (activeClients && activeClients.length > 0) {
Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients);
if (!errorMessage) {
return;
}

// After signing out, set ourselves as offline if we were offline before logging out and we are not forcing it.
// If we are forcing offline, ignore it while signed out, otherwise it would require a refresh because there's no way to toggle the switch to go back online while signed out.
if (isOffline && !shouldForceOffline) {
Onyx.set(ONYXKEYS.NETWORK, {isOffline});
}

// `Onyx.clear` reinitialize the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set`
if (errorMessage) {
Onyx.merge(ONYXKEYS.SESSION, {errors: {[DateUtils.getMicroseconds()]: Localize.translateLocal(errorMessage)}});
}
// `Onyx.clear` reinitializes the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set`
Onyx.merge(ONYXKEYS.SESSION, {errors: {[DateUtils.getMicroseconds()]: Localize.translateLocal(errorMessage)}});
});
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function signInAndGetAppWithUnreadChat() {
}

describe('Unread Indicators', () => {
afterEach(Onyx.clear);
afterEach(() => Onyx.clear());
Comment thread
neil-marcellini marked this conversation as resolved.

it('Display bold in the LHN for unread chat and new line indicator above the chat message when we navigate to it', () => {
let renderedApp;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/NetworkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ beforeEach(() => {
// Wait for any Log command to finish and Onyx to fully clear
jest.advanceTimersByTime(CONST.NETWORK.PROCESS_REQUEST_DELAY_MS);
return waitForPromisesToResolve()
.then(Onyx.clear)
.then(() => Onyx.clear())
Comment thread
neil-marcellini marked this conversation as resolved.
.then(waitForPromisesToResolve);
});

Expand Down