Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
fix unique favority devices
Browse files Browse the repository at this point in the history
Summary:
If you ever updated Xcode you probably have more than one device with the same name but different ios version

Currently we preserve favorite devices by name, which means if you favority one device, the other devices with the same name but other version are favorited as well. This is rather a bug. Let's preserve favorite devices by id instead

Reviewed By: mweststrate

Differential Revision: D66095909

fbshipit-source-id: 74310e70d300d7c9f34ba1abd8b728e33aad3477
  • Loading branch information
antonk52 authored and facebook-github-bot committed Nov 19, 2024
1 parent 47172ee commit 9517f80
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions desktop/flipper-ui/src/sandy-chrome/appinspect/LaunchEmulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ export const LaunchEmulatorDialog = withTrackingScope(
const [iOSMessage, setiOSMessage] = useState<IOSState>({type: 'loading'});
const [androidMessage, setAndroidMessage] = useState<string>('Loading...');

const [favoriteVirtualDevices, setFavoriteVirtualDevices] =
const [favoriteVirtualDeviceIds, setFavoriteVirtualDeviceIds] =
useLocalStorageState<string[]>('favourite-virtual-devices', []);

const addToFavorites = (deviceName: string) => {
setFavoriteVirtualDevices(uniq([deviceName, ...favoriteVirtualDevices]));
const addToFavorites = (id: string) => {
setFavoriteVirtualDeviceIds(uniq([id, ...favoriteVirtualDeviceIds]));
};

const removeFromFavorites = (deviceName: string) => {
setFavoriteVirtualDevices(without(favoriteVirtualDevices, deviceName));
const removeFromFavorites = (deviceId: string) => {
setFavoriteVirtualDeviceIds(without(favoriteVirtualDeviceIds, deviceId));
};

const [pendingEmulators, setPendingEmulators] = useState(new Set<string>());
Expand Down Expand Up @@ -185,7 +185,7 @@ export const LaunchEmulatorDialog = withTrackingScope(
...chain(
androidEmulators.map((name) => ({
name,
isFavorite: favoriteVirtualDevices.includes(name),
isFavorite: favoriteVirtualDeviceIds.includes(name),
})),
)
.sortBy((item) => [!item.isFavorite, item.name])
Expand Down Expand Up @@ -235,7 +235,7 @@ export const LaunchEmulatorDialog = withTrackingScope(
addToFavorites={addToFavorites}
removeFromFavorites={removeFromFavorites}
isFavorite={isFavorite}
name={name}>
id={name}>
<Dropdown.Button
overlay={menu}
icon={<MoreOutlined />}
Expand All @@ -258,7 +258,7 @@ export const LaunchEmulatorDialog = withTrackingScope(
...chain(iosEmulators)
.map((device) => ({
device,
isFavorite: favoriteVirtualDevices.includes(device.name),
isFavorite: favoriteVirtualDeviceIds.includes(device.udid),
}))
.sortBy((item) => [!item.isFavorite, item.device.name])
.map(({device, isFavorite}) => (
Expand All @@ -267,7 +267,7 @@ export const LaunchEmulatorDialog = withTrackingScope(
addToFavorites={addToFavorites}
removeFromFavorites={removeFromFavorites}
isFavorite={isFavorite}
name={device.name}>
id={device.udid}>
<Button
type="default"
key={device.udid}
Expand Down Expand Up @@ -405,26 +405,26 @@ function Title({name}: {name: string}) {

function VirtualDeviceRow({
isFavorite,
name,
id,
addToFavorites,
removeFromFavorites,
children,
}: {
children: ReactNode;
isFavorite: boolean;
name: string;
addToFavorites: (deviceName: string) => void;
removeFromFavorites: (deviceName: string) => void;
id: string;
addToFavorites: (id: string) => void;
removeFromFavorites: (id: string) => void;
}) {
return (
<Layout.Horizontal gap="medium" center grow key={name}>
<Layout.Horizontal gap="medium" center grow key={id}>
{children}
{isFavorite ? (
<HeartFilled
testing-id="favorite"
aria-label="favorite"
onClick={() => {
removeFromFavorites(name);
removeFromFavorites(id);
}}
style={FavIconStyle}
/>
Expand All @@ -433,7 +433,7 @@ function VirtualDeviceRow({
testing-id="not-favorite"
aria-label="not-favorite"
onClick={() => {
addToFavorites(name);
addToFavorites(id);
}}
style={FavIconStyle}
/>
Expand Down

0 comments on commit 9517f80

Please sign in to comment.