Skip to content

Commit

Permalink
hidden email: Smooth transitions with a bit of fake blank data.
Browse files Browse the repository at this point in the history
We're about to start using this `email` property for `getOwnEmail`;
and we'd like to have it throw an error if we don't actually have a
valid own-email because there isn't a logged-in active account.

Unfortunately it turns out -- as we learn from trying that -- that
there are existing parts of our code that can end up trying to get at
the own-email when there is no valid answer.  That's a bug, but for
now just keep it papered over by making up some blank data (like we do
in a lot of our legacy code), and make a TODO comment.

The harder-line `initialState` value still has a foothold, in that we
use it on first startup.
  • Loading branch information
gnprice committed Jul 17, 2019
1 parent 30c4f7f commit bf030f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/realm/__tests__/realmReducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { NULL_OBJECT } from '../../nullObjects';

describe('realmReducer', () => {
describe('ACCOUNT_SWITCH', () => {
test('resets state to initial state', () => {
test('resets state to blank state', () => {
const initialState = NULL_OBJECT;

const action = deepFreeze({
Expand All @@ -21,6 +21,7 @@ describe('realmReducer', () => {
const expectedState = {
canCreateStreams: true,
crossRealmBots: [],
email: '',
isAdmin: false,
twentyFourHourTime: false,
emoji: {},
Expand Down
19 changes: 18 additions & 1 deletion src/realm/realmReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ const initialState = {
nonActiveUsers: [],
};

/**
* A version of `initialState` with some made-up blank data.
*
* On `LOGIN_SUCCESS`, we go straight to showing the main app UI (see
* `navReducer`) even though we're still loading the actual data from the
* server. So we need some fake data that the UI code will swallow.
* TODO: Probably stop doing that.
*
* Also: On `ACCOUNT_SWITCH`, during the transition animation, some old
* components can still be mounted from the UI for the previous account that
* make no sense without server data. Probably ditto `LOGOUT`.
*/
const fakeBlankState = {
...initialState,
email: '',
};

const convertRealmEmoji = (data): RealmEmojiById => {
const emojis = {};
Object.keys(data).forEach(id => {
Expand All @@ -35,7 +52,7 @@ export default (state: RealmState = initialState, action: Action): RealmState =>
case LOGOUT:
case LOGIN_SUCCESS:
case ACCOUNT_SWITCH:
return initialState;
return fakeBlankState;

case REALM_INIT: {
return {
Expand Down

0 comments on commit bf030f1

Please sign in to comment.