Page MenuHomePhabricator

[web] Add dispatching SET_DEVICE_ID action
ClosedPublic

Authored by inka on Aug 19 2022, 2:49 AM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Nov 26, 8:12 PM
Unknown Object (File)
Tue, Nov 26, 7:18 PM
Unknown Object (File)
Tue, Nov 26, 6:49 PM
Unknown Object (File)
Sat, Nov 23, 4:36 AM
Unknown Object (File)
Sat, Nov 23, 4:06 AM
Unknown Object (File)
Sat, Nov 23, 12:33 AM
Unknown Object (File)
Tue, Nov 12, 4:22 AM
Unknown Object (File)
Tue, Nov 5, 1:15 PM
Subscribers

Details

Summary

I added a copmonent re-rendering on device ID change and setting a device ID whenever the device ID is null.
On logout/account deletion/cookie invalidation the reducer sets device ID to null, causing SET_DEVICE_ID action to get dispatched.
For now the device ID set on the login/create account screen is also used after login/account creation as I didn't find any reasons not to.
Persistance has not yet been added

Test Plan

Test using redux tools that the device ID is present and changes on logout, cookie invalidation and account deletion.

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

inka requested review of this revision.Aug 19 2022, 2:59 AM
tomek requested changes to this revision.Aug 19 2022, 8:10 AM

it is not yet possible to delete an account on web

It is possible. You can do that by opening account settings (cog icon in bottom left corner), then open danger zone and there's an option to do so.

web/redux/device-id-updater.js
2–12 ↗(On Diff #15784)

In all the places we import React and use it instead of importing the effect. I think it might make sense to keep it consistent.

13 ↗(On Diff #15784)

It might be a little safer to handle also undefined. We can do that by converting deviceID to boolean

This revision now requires changes to proceed.Aug 19 2022, 8:10 AM

It is possible. You can do that by opening account settings (cog icon in bottom left corner), then open danger zone and there's an option to do so.

Right, sorry, I missed that.

tomek requested changes to this revision.Aug 22 2022, 5:33 AM
tomek added inline comments.
web/redux/device-id-updater.js
8–23 ↗(On Diff #15799)

In all the places we split exporting and defining functions

20 ↗(On Diff #15799)

We should always specify dependency array for effect hook. In this case skipping it wouldn't be a huge issue, but it is a good practice to never skip it.

This revision now requires changes to proceed.Aug 22 2022, 5:33 AM

Make code follow the project standars

web/redux/device-id-updater.js
13–19 ↗(On Diff #15816)

If we end up adding more parameters into the dep list, or if dispatch changes, we could end up calling this twice in a row. It could be good to make sure we call this only when !deviceID becomes true. We could do this with two variables:

const hasDeviceID = !!deviceID;
const hadDeviceIDRef = React.useRef(hasDeviceID);
React.useEffect(() => {
  if (hadDeviceIDRef.value && !hasDeviceID) {
    ...
  }
  hadDeviceIDRef.value = hasDeviceID;
}, [hasDeviceID, dispatch]);
web/redux/device-id-updater.js
12–15 ↗(On Diff #15905)

We still need it to run at the beginning, when the server returns the initial id=null, hence the null

This revision is now accepted and ready to land.Aug 25 2022, 1:21 AM