Skip to content
Merged
Changes from all commits
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
26 changes: 16 additions & 10 deletions app/models/favorites/favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,23 @@ export const useFavoritesStore = create<FavoritesStore>((set, get) => ({
const toText = (route: FavoriteRoute) =>
translate("favorites.toStation", { stationName: stationsObject[route.destinationId][stationLocale] })

// Both iOS quick actions and Android dynamic shortcuts cap at ~4-5 per app;
// some Android devices report lower limits and throw if exceeded.
const MAX_HOME_SHORTCUTS = 4
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While defining the constant here works, it's generally better practice to define configuration constants like MAX_HOME_SHORTCUTS at the top level of the file. This improves visibility and maintainability, especially if the value needs to be referenced elsewhere in the future.


Shortcuts.setShortcuts(
get().routes.map((route) => ({
type: `favorite-${route.id}`,
title: route.label || fromText(route),
subtitle: !route.label && toText(route),
iconName: "star",
data: {
originId: route.originId,
destinationId: route.destinationId,
},
})),
get()
.routes.slice(0, MAX_HOME_SHORTCUTS)
.map((route) => ({
type: `favorite-${route.id}`,
title: route.label || fromText(route),
subtitle: !route.label && toText(route),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The expression !route.label && toText(route) evaluates to false when route.label is present. Passing a boolean value to Shortcuts.setShortcuts for a field that expects a string (like subtitle) can cause a ClassCastException on the native Android side when the library attempts to call getString("subtitle"). It is safer to use a ternary operator to ensure the value is either a string or undefined.

Suggested change
subtitle: !route.label && toText(route),
subtitle: !route.label ? toText(route) : undefined,

iconName: "star",
data: {
originId: route.originId,
destinationId: route.destinationId,
},
})),
)
},

Expand Down
Loading