Page MenuHomePhabricator

[native] Move complexity of `actionSheetConfig` to `useShowAvatarActionSheet`
ClosedPublic

Authored by atul on Apr 18 2023, 3:32 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Sep 21, 12:01 AM
Unknown Object (File)
Fri, Sep 20, 4:51 AM
Unknown Object (File)
Fri, Sep 20, 3:17 AM
Unknown Object (File)
Fri, Sep 20, 2:19 AM
Unknown Object (File)
Sun, Sep 15, 10:01 PM
Unknown Object (File)
Sun, Sep 8, 9:23 AM
Unknown Object (File)
Sun, Sep 8, 9:23 AM
Unknown Object (File)
Sun, Sep 8, 9:23 AM
Subscribers

Details

Summary

We can simplify the actionSheetConfig constructed in Edit*Avatar by moving some of what's common to useShowAvatarActionSheet. This cuts down on reptition a decent amount.

All of this refactoring brought the size of Edit*Avatar from 234 lines to 40:

3cc48b.png (1×1 px, 302 KB)

This should make the subsequent changes easier to manage.


Depends on D7506

Test Plan

Everything looks and works as it did previously + ESLint + Flow

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

atul published this revision for review.Apr 18 2023, 3:39 PM

Please address inline comments before landing! If you're unable to switch back to $ReadOnlyArray, please re-request review and I'll take a look

native/avatars/avatar-hooks.js
127 ↗(On Diff #25315)

I don't think this function should be mutating the input array, and it doesn't look like it actually does. Can you try switching it back to $ReadOnlyArray and seeing if it has any type errors?

Note that reassigning options is not the same as mutating the input array. Mutating input parameters is in my opinion an anti-pattern, since the caller isn't likely to expect it

171 ↗(On Diff #25315)

I'm not a huge fan of the implicit return undefined... can we make it explicit, so it's clear that cancel doesn't get an icon?

This revision is now accepted and ready to land.Apr 19 2023, 6:03 AM
native/avatars/avatar-hooks.js
127 ↗(On Diff #25315)

I don't think this function should be mutating the input array, and it doesn't look like it actually does.

Ah yeah, I totally blanked here. The reference to options is passed by value so if we were to eg append an element it would mutate the input but by spreading we're creating a new object and reassigning the "internal" meaning of options without mutating the object passed in as argument.

Did a quick sanity check to make sure I understand things correctly:

218599.png (1×892 px, 202 KB)

Will update this diff.

address feedback ($ReadOnlyArray<>)

This revision was landed with ongoing or failed builds.Apr 19 2023, 9:28 AM
This revision was automatically updated to reflect the committed changes.