Skip to content

Commit 16aedf2

Browse files
committed
refactor: replace feature availability checks with useFeatureAvailability hook for improved clarity and consistency
1 parent ee53ba9 commit 16aedf2

File tree

7 files changed

+37
-48
lines changed

7 files changed

+37
-48
lines changed

packages/vscode-extension/src/webview/components/DeviceSelect.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { useStore } from "../providers/storeProvider";
1313
import { DeviceInfo, DevicePlatform, DeviceType } from "../../common/State";
1414
import { useSelectedDeviceSessionState } from "../hooks/selectedSession";
1515
import { usePaywalledCallback } from "../hooks/usePaywalledCallback";
16-
import { Feature } from "../../common/License";
16+
import { Feature, FeatureAvailabilityStatus } from "../../common/License";
1717
import { useDevices } from "../hooks/useDevices";
1818
import { PropsWithDataTest } from "../../common/types";
19-
import { useIsFeatureAdminDisabled } from "../hooks/useFeatureAvailabilityCheck";
19+
import { useFeatureAvailability } from "../hooks/useFeatureAvailability";
2020

2121
enum DeviceSection {
2222
IosSimulator = "IosSimulator",
@@ -211,7 +211,9 @@ function DeviceSelect() {
211211
};
212212

213213
const isAdminDisabledDeviceSections = (section: DeviceSection): boolean => {
214-
const isRemoteAndroidAdminDisabled = useIsFeatureAdminDisabled(Feature.AndroidPhysicalDevice);
214+
const isRemoteAndroidAdminDisabled =
215+
useFeatureAvailability(Feature.AndroidPhysicalDevice) ===
216+
FeatureAvailabilityStatus.ADMIN_DISABLED;
215217
return !(section === DeviceSection.PhysicalAndroid && isRemoteAndroidAdminDisabled);
216218
};
217219

packages/vscode-extension/src/webview/components/Preview.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ import {
3737
} from "../../common/State";
3838
import { useSelectedDeviceSessionState } from "../hooks/selectedSession";
3939
import { ActivateLicenseMessage } from "./ActivateLicenseMessage";
40-
import { useIsFeatureAdminDisabled } from "../hooks/useFeatureAvailabilityCheck";
41-
import { Feature } from "../../common/License";
40+
import { useFeatureAvailability } from "../hooks/useFeatureAvailability";
41+
import { Feature, FeatureAvailabilityStatus } from "../../common/License";
4242

4343
function TouchPointIndicator({ isPressing }: { isPressing: boolean }) {
4444
return <div className={`touch-indicator ${isPressing ? "pressed" : ""}`}></div>;
@@ -131,7 +131,8 @@ function Preview({
131131

132132
const isRunning = selectedDeviceSessionStatus === "running";
133133

134-
const isSendFilesAdminDisabled = useIsFeatureAdminDisabled(Feature.SendFile);
134+
const isSendFilesAdminDisabled =
135+
useFeatureAvailability(Feature.SendFile) === FeatureAvailabilityStatus.ADMIN_DISABLED;
135136

136137
const isRefreshing = use$(() =>
137138
isRunning ? selectedDeviceSessionState.applicationSession.isRefreshing.get() : false

packages/vscode-extension/src/webview/components/shared/PaywallDropdownMenu.tsx

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import React, { useMemo } from "react";
22
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
33
import classnames from "classnames";
4-
import { Feature } from "../../../common/License";
5-
import {
6-
useIsFeatureAvailable,
7-
useIsFeaturePaywalled,
8-
} from "../../hooks/useFeatureAvailabilityCheck";
4+
import { Feature, FeatureAvailabilityStatus } from "../../../common/License";
5+
import { useFeatureAvailability } from "../../hooks/useFeatureAvailability";
96
import { usePaywalledCallback } from "../../hooks/usePaywalledCallback";
107
import * as DropdownMenuComponents from "../shared/DropdownMenuComponents";
118

@@ -36,8 +33,8 @@ export function Item({
3633
feature,
3734
...props
3835
}: PaywallItemProps) {
39-
const isPaywalled = useIsFeaturePaywalled(feature);
40-
const isAvailable = useIsFeatureAvailable(feature);
36+
const isPaywalled = useFeatureAvailability(feature) === FeatureAvailabilityStatus.PAYWALLED;
37+
const isAvailable = useFeatureAvailability(feature) === FeatureAvailabilityStatus.AVAILABLE;
4138

4239
const handleSelect = usePaywalledCallback(onSelect, feature, [onSelect]);
4340

@@ -59,8 +56,8 @@ interface PaywallSubProps extends DropdownMenu.DropdownMenuSubProps {
5956
}
6057

6158
export function Sub({ feature, children, open, ...props }: PaywallSubProps) {
62-
const isPaywalled = useIsFeaturePaywalled(feature);
63-
const isAvailable = useIsFeatureAvailable(feature);
59+
const isPaywalled = useFeatureAvailability(feature) === FeatureAvailabilityStatus.PAYWALLED;
60+
const isAvailable = useFeatureAvailability(feature) === FeatureAvailabilityStatus.AVAILABLE;
6461

6562
const isOpen = isAvailable ? open : false;
6663

@@ -104,8 +101,8 @@ interface PaywallSwitchItemProps extends DropdownMenuComponents.SwitchItemProps
104101
}
105102

106103
export function SwitchItem({ children, className, feature, ...props }: PaywallSwitchItemProps) {
107-
const isPaywalled = useIsFeaturePaywalled(feature);
108-
const isAvailable = useIsFeatureAvailable(feature);
104+
const isPaywalled = useFeatureAvailability(feature) === FeatureAvailabilityStatus.PAYWALLED;
105+
const isAvailable = useFeatureAvailability(feature) === FeatureAvailabilityStatus.AVAILABLE;
109106

110107
const handleOnClick = usePaywalledCallback(() => {}, feature, []);
111108

packages/vscode-extension/src/webview/components/shared/PaywallIconButton.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import classnames from "classnames";
2-
import { Feature } from "../../../common/License";
2+
import { Feature, FeatureAvailabilityStatus } from "../../../common/License";
33
import { PropsWithDataTest } from "../../../common/types";
4-
import { useIsFeaturePaywalled } from "../../hooks/useFeatureAvailabilityCheck";
4+
import { useFeatureAvailability } from "../../hooks/useFeatureAvailability";
55
import { usePaywalledCallback } from "../../hooks/usePaywalledCallback";
66
import IconButton, { type IconButtonProps } from "./IconButton";
77

@@ -17,7 +17,7 @@ const PaywallIconButton = ({
1717
onClick = () => {},
1818
...props
1919
}: PaywallIconButtonProps) => {
20-
const isPaywalled = useIsFeaturePaywalled(feature);
20+
const isPaywalled = useFeatureAvailability(feature) === FeatureAvailabilityStatus.PAYWALLED;
2121
const badge = isPaywalled ? <span className={"pro-feature-badge"}>Pro</span> : null;
2222

2323
const handleOnClick = usePaywalledCallback(onClick, feature, [onClick]);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { use$ } from "@legendapp/state/react";
2+
import { Feature, FeatureAvailabilityStatus } from "../../common/License";
3+
import { useStore } from "../providers/storeProvider";
4+
5+
export function useFeatureAvailability(feature: Feature): FeatureAvailabilityStatus {
6+
const store$ = useStore();
7+
const featuresAvailability = use$(store$.license.featuresAvailability);
8+
return featuresAvailability[feature];
9+
}

packages/vscode-extension/src/webview/hooks/useFeatureAvailabilityCheck.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

packages/vscode-extension/src/webview/views/PreviewView.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import {
3131
import { useModal } from "../providers/ModalProvider";
3232
import Button from "../components/shared/Button";
3333
import { ActivateLicenseView } from "./ActivateLicenseView";
34-
import { Feature, LicenseStatus } from "../../common/License";
34+
import { Feature, FeatureAvailabilityStatus, LicenseStatus } from "../../common/License";
3535
import { useDevices } from "../hooks/useDevices";
36-
import { useIsFeatureAdminDisabled } from "../hooks/useFeatureAvailabilityCheck";
36+
import { useFeatureAvailability } from "../hooks/useFeatureAvailability";
3737
import PaywallIconButton from "../components/shared/PaywallIconButton";
3838

3939
const INSPECTOR_AVAILABILITY_MESSAGES = {
@@ -220,7 +220,8 @@ function PreviewView() {
220220
};
221221
}, []);
222222

223-
const isRecordingAdminDisabled = useIsFeatureAdminDisabled(Feature.ScreenRecording);
223+
const isRecordingAdminDisabled =
224+
useFeatureAvailability(Feature.ScreenRecording) === FeatureAvailabilityStatus.ADMIN_DISABLED;
224225

225226
const showRecordingButton = !isRecordingAdminDisabled;
226227

@@ -250,7 +251,8 @@ function PreviewView() {
250251
project.stopMaestroTest();
251252
}
252253

253-
const isReplayAdminDisabled = useIsFeatureAdminDisabled(Feature.ScreenReplay);
254+
const isReplayAdminDisabled =
255+
useFeatureAvailability(Feature.ScreenReplay) === FeatureAvailabilityStatus.ADMIN_DISABLED;
254256

255257
async function handleReplay() {
256258
try {
@@ -260,7 +262,8 @@ function PreviewView() {
260262
}
261263
}
262264

263-
const isScreenshotAdminDisabled = useIsFeatureAdminDisabled(Feature.Screenshot);
265+
const isScreenshotAdminDisabled =
266+
useFeatureAvailability(Feature.Screenshot) === FeatureAvailabilityStatus.ADMIN_DISABLED;
264267

265268
const showScreenshotButton = !isScreenshotAdminDisabled;
266269

0 commit comments

Comments
 (0)