Page MenuHomePhabricator

D4886.diff
No OneTemporary

D4886.diff

diff --git a/web/app.react.js b/web/app.react.js
--- a/web/app.react.js
+++ b/web/app.react.js
@@ -31,6 +31,7 @@
import LoadingIndicator from './loading-indicator.react';
import { MenuProvider } from './menu-provider.react';
import { ModalProvider, useModalContext } from './modals/modal-provider.react';
+import DeviceIDUpdater from './redux/device-id-updater';
import DisconnectedBar from './redux/disconnected-bar';
import DisconnectedBarVisibilityHandler from './redux/disconnected-bar-visibility-handler';
import FocusHandler from './redux/focus-handler.react';
@@ -142,6 +143,7 @@
<MenuProvider>
<FocusHandler />
<VisibilityHandler />
+ <DeviceIDUpdater />
{content}
{this.props.modals}
</MenuProvider>
diff --git a/web/redux/device-id-reducer.js b/web/redux/device-id-reducer.js
--- a/web/redux/device-id-reducer.js
+++ b/web/redux/device-id-reducer.js
@@ -1,5 +1,11 @@
// @flow
+import {
+ deleteAccountActionTypes,
+ logOutActionTypes,
+} from 'lib/actions/user-actions.js';
+import { setNewSessionActionType } from 'lib/utils/action-utils.js';
+
import type { Action } from '../redux/redux-setup';
import { deviceIDFormatRegex } from '../utils/device-id';
import { setDeviceIDActionType } from './action-types';
@@ -10,6 +16,13 @@
return action.payload;
}
return null;
+ } else if (
+ action.type === logOutActionTypes.success ||
+ action.type === deleteAccountActionTypes.success ||
+ (action.type === setNewSessionActionType &&
+ action.payload.sessionChange.cookieInvalidated)
+ ) {
+ return null;
}
return state;
}
diff --git a/web/redux/device-id-updater.js b/web/redux/device-id-updater.js
new file mode 100644
--- /dev/null
+++ b/web/redux/device-id-updater.js
@@ -0,0 +1,28 @@
+// @flow
+import * as React from 'react';
+import { useDispatch, useSelector } from 'react-redux';
+
+import { generateDeviceID, deviceIDTypes } from '../utils/device-id';
+import { setDeviceIDActionType } from './action-types';
+
+function DeviceIDUpdater(): null {
+ const dispatch = useDispatch();
+ const deviceID = useSelector(state => state.deviceID);
+ const hasDeviceID = !!deviceID;
+ const hadDeviceIDRef = React.useRef<?boolean>(null);
+
+ React.useEffect(() => {
+ if (hadDeviceIDRef.current !== false && !hasDeviceID) {
+ const newDeviceID = generateDeviceID(deviceIDTypes.WEB);
+ dispatch({
+ type: setDeviceIDActionType,
+ payload: newDeviceID,
+ });
+ }
+ hadDeviceIDRef.current = hasDeviceID;
+ }, [hasDeviceID, dispatch]);
+
+ return null;
+}
+
+export default DeviceIDUpdater;

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 12:33 AM (20 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573270
Default Alt Text
D4886.diff (2 KB)

Event Timeline