Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate 'EmojiPickerAction.js' lib to TypeScript #26795

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
62 changes: 0 additions & 62 deletions src/libs/actions/EmojiPickerAction.js

This file was deleted.

77 changes: 77 additions & 0 deletions src/libs/actions/EmojiPickerAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {ValueOf} from 'type-fest';
import React from 'react';
import {View} from 'react-native';
import CONST from '../../CONST';

type AnchorOrigin = {
horizontal: ValueOf<typeof CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL>;
vertical: ValueOf<typeof CONST.MODAL.ANCHOR_ORIGIN_VERTICAL>;
};

type EmojiPicker = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we defining the component type in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not the component type, it's what is defined in useImperativeHandle here. Do you think the name is misleading? @hayata-suenaga

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean this is component API right? the methods exposed the component through useImperativeHandle?

I think we should define this inside the component file instead of defining this here where we store the reference to the component.

I know we haven't started migration of component files, but I think we should start thinking about where type definitions should belong and how to coordinates the migration when the type needed are not defined yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that EmojiPicker type should be defined next to EmojiPicker component. But until it's not migrated we have couple options:

  • Put this PR on hold until we get to EmojiPicker component
  • Merge this now, and move the type when EmojiPicker component is migrated (we can add a comment on the issue to remember about this)
  • Define types.ts file with EmojiPicker type next to the component

Generally I think we won't be able to avoid such situations and sometimes we have to define types in undesirable places. At some point of the migration we will have to clean a bit, for example we'll have to clean style types or define shared types that are often used - until then we have to accept that we will repeat or litter the code sometimes.

cc @fabioh8010 @hayata-suenaga

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confortable with option two, and adding a TODO comment above the type as well:

Merge this now, and move the type when EmojiPicker component is migrated (we can add a comment on the issue to remember about this)

Copy link
Contributor

Choose a reason for hiding this comment

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

We can create some cleanup and review issues for some of the categories of files (I kinda have been done this cleanup for styles already) , e.g. styles, models, libs, hooks, hoc's, components and pages I think are good candidates for these clean ups. After each migration of all issues of that category we will create a new issue to review all past work and ensure consistency. I can add these "checkpoints" on our spreadsheet, WDYT? @hayata-suenaga @blazejkustra

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@fabioh8010 That sounds good to me 😄 Add it to the spreadsheet please, and we will get back to this.

I don't have the capacity to manage this, so I'd appreciate if SWM and CallStack and develop a strategy to coordinate and keep track the cleanup efforts we have to do. 🙇

Sure thing @hayata-suenaga, that's on me and @fabioh8010, we will coordinate such cleanups!

Copy link
Contributor

Choose a reason for hiding this comment

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

Let me know if issues need to be created in App 🙇

Copy link
Contributor

Choose a reason for hiding this comment

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

@hayata-suenaga @blazejkustra I created new rows in the spreadsheet about these review issues, here are the lines:

  • 57
  • 261
  • 277
  • 295
  • 486
  • 550

@hayata-suenaga Could you please create the issues? Thank you!

Copy link
Contributor

Choose a reason for hiding this comment

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

showEmojiPicker: (onModalHideValue?: () => void, onEmojiSelectedValue?: () => void, emojiPopoverAnchor?: View, anchorOrigin?: AnchorOrigin, onWillShow?: () => void, id?: string) => void;
isActive: (id: string) => boolean;
hideEmojiPicker: (isNavigating: boolean) => void;
isEmojiPickerVisible: boolean;
resetEmojiPopoverAnchor: () => void;
};

const emojiPickerRef = React.createRef<EmojiPicker>();

/**
* Show the EmojiPicker modal popover.
*
* @param onModalHide - Run a callback when Modal hides.
* @param onEmojiSelected - Run a callback when Emoji selected.
* @param emojiPopoverAnchor - Element on which EmojiPicker is anchored
* @param anchorOrigin - Anchor origin for Popover
* @param onWillShow - Run a callback when Popover will show
* @param id - Unique id for EmojiPicker
*/
function showEmojiPicker(onModalHide = () => {}, onEmojiSelected = () => {}, emojiPopoverAnchor = undefined, anchorOrigin = undefined, onWillShow = () => {}, id = undefined): void {
if (!emojiPickerRef.current) {
return;
}

emojiPickerRef.current.showEmojiPicker(onModalHide, onEmojiSelected, emojiPopoverAnchor, anchorOrigin, onWillShow, id);
}

/**
* Hide the Emoji Picker modal.
*/
function hideEmojiPicker(isNavigating: boolean): void {
if (!emojiPickerRef.current) {
return;
}

emojiPickerRef.current.hideEmojiPicker(isNavigating);
}

/**
* Whether Emoji Picker is active for the given id.
*/
function isActive(id: string): boolean {
if (!emojiPickerRef.current) {
return false;
}

return emojiPickerRef.current.isActive(id);
}

function isEmojiPickerVisible(): boolean {
if (!emojiPickerRef.current) {
return false;
}

return emojiPickerRef.current.isEmojiPickerVisible;
}

function resetEmojiPopoverAnchor(): void {
if (!emojiPickerRef.current) {
return;
}

emojiPickerRef.current.resetEmojiPopoverAnchor();
}

export {emojiPickerRef, showEmojiPicker, hideEmojiPicker, isActive, isEmojiPickerVisible, resetEmojiPopoverAnchor};