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

Refactor os & mobile util functions #7303

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Refactor os & mobile util functions #7303

wants to merge 4 commits into from

Conversation

cadeban
Copy link
Contributor

@cadeban cadeban commented Oct 9, 2024

Description

AVO-552: Refactor os & mobile util functions because while we like spaghetti, we don't like it in our code. 🙅🍝

🎵 Cha-cha-cha-changes:

  • Move isIos, isIphone, and IsAndroid to the component files in which they are in use & inline isIphone & isAndroid userAgent sniffing
    • Not really used elsewhere, so I think it makes sense to keep them in their respective files
  • Use Capacitor.isNativePlatform() to determine if mobile
  • Move and rename isMobile -> hasMobileUserAgent

Still TODO:

  • Confirm changes on native apps/native app emulators

Additional discussion:

  • userAgent sniffing is rather fragile, but it may be good enough for our purposes

Preview

n/a, visual & functionality should be the same

Double check

  • I have tested my parser changes locally with poetry run test_parser "zone_key"
  • I have run pnpx prettier@2 --write . and poetry run format in the top level directory to format my changes.

@cadeban cadeban self-assigned this Oct 9, 2024
@cadeban cadeban removed their assignment Oct 10, 2024
@cadeban cadeban marked this pull request as ready for review October 10, 2024 09:29
@cadeban cadeban force-pushed the cadeban/utils2 branch 2 times, most recently from a8e298c to 5414838 Compare October 10, 2024 09:50
@cadeban cadeban changed the title [WIP] Refactor os & mobile util functions Refactor os & mobile util functions Oct 10, 2024
Cadence added 2 commits October 10, 2024 12:00
- favor inline regex
- abstract isMobile -> hasMobileUserAgent into new file
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

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

Some general feedback and suggestions.

Comment on lines -21 to -25
export function isMobile() {
return /android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(
navigator.userAgent
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Very nice to see this gone, was quite confusing as we have a useIsMobile hook as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🥾

Comment on lines 107 to 111
export function defaultShouldShowIosIcon() {
return (
/Mac|iPad|iPhone|iPod/.test(navigator.userAgent) || Capacitor.getPlatform() === 'ios'
);
}
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 Oct 10, 2024

Choose a reason for hiding this comment

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

Suggested change
export function defaultShouldShowIosIcon() {
return (
/Mac|iPad|iPhone|iPod/.test(navigator.userAgent) || Capacitor.getPlatform() === 'ios'
);
}
export const defaultShouldShowIosIcon = () =>
/Mac|iPad|iPhone|iPod/.test(navigator.userAgent) || Capacitor.getPlatform() === 'ios'

Tiny bit smaller and takes advantage of the bundlers ability to declare multiple constants at the same time.

This regex could also be extracted to a isApplePlatform function to be reused by the app store url function.

Comment on lines 165 to 169
export function hasMobileUserAgent() {
return /android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(
navigator.userAgent
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export function hasMobileUserAgent() {
return /android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(
navigator.userAgent
);
}
export const hasMobileUserAgent = () => /android|blackberry|iemobile|ipad|iphone|ipod|opera mini|webos/i.test(
navigator.userAgent
);

Just a tiny bit smaller, I also think we can ditch iemobile and blackbarry. As far as I know they don't support the app anyhow 😅

And is not webOS only used in TVs these days?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's also being used for the windlayer and may need support on mobile web, so I'm a little shy about removing blackberry and iemobile just yet

Maybe people are browsing our web app on their tvs? 😅

},
{
userAgent:
'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Mobile Safari/537.36',
Copy link
Member

Choose a reason for hiding this comment

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

Should Mobile be a part of the regex test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That seems reasonable! 👍

web/src/components/AppStoreBanner.tsx Show resolved Hide resolved
Copy link
Member

@VIKTORVAV99 VIKTORVAV99 left a comment

Choose a reason for hiding this comment

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

Approving!

If you want to do any of the suggested changes to the regex feel free to do so but everything looks good to me!

@VIKTORVAV99
Copy link
Member

@cadeban could you try and get this merged today?

Before we get even more merge conflicts 😬

@cadeban
Copy link
Contributor Author

cadeban commented Oct 16, 2024

Will handle the merge conflicts later today. Some of the work that came out of the Avo sync jumped ahead in the queue

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 9 changed files in this pull request and generated no suggestions.

Files not reviewed (4)
  • web/src/features/panels/zone/ShareButton.tsx: Evaluated as low risk
  • web/src/features/weather-layers/wind-layer/windy.ts: Evaluated as low risk
  • web/src/translation/i18n.ts: Evaluated as low risk
  • web/src/features/panels/zone/ShareButton.test.tsx: Evaluated as low risk
@VIKTORVAV99
Copy link
Member

@cadeban can we try and get this merged or put it in draft/close it? It's been open for a while now 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants