Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

refactor: simplify covering-workspace resolution and trim comments

Gabriel Steina6b55afa5588
diff --git a/src/components/SettingsPage.tsx b/src/components/SettingsPage.tsx
index efaa64d46..491db9390 100644
--- a/src/components/SettingsPage.tsx
+++ b/src/components/SettingsPage.tsx
@@ -95,7 +95,6 @@ import type {
GpuDevice,
LocalTranscriptionProvider,
InferenceMode,
- Workspace,
} from "../types/electron";
import logger from "../utils/logger";
import { SettingsRow, InferenceModeSelector } from "./ui/SettingsSection";
@@ -1009,24 +1008,23 @@ export default function SettingsPage({
const { theme, setTheme } = useTheme();
const usage = useUsage();
const billingWorkspaces = useWorkspaceStore((s) => s.workspaces);
- const coveringWorkspaces = (usage?.entitledWorkspaceIds ?? [])
- .map((id) => billingWorkspaces.find((workspace) => workspace.id === id))
- .filter((workspace): workspace is Workspace => Boolean(workspace));
+ const coveringWorkspaces = billingWorkspaces.filter((workspace) =>
+ usage?.entitledWorkspaceIds?.includes(workspace.id)
+ );
const coveringWorkspaceNames = coveringWorkspaces.map((workspace) => workspace.name);
- // Gated on the usage payload rather than the resolved workspaces: the workspace
- // store loads separately, and the upgrade affordances must stay hidden while it
- // does, or a covered member is invited to buy a plan their seat already grants.
+ // Reads the usage payload, not the workspace store, so the upgrade affordances
+ // stay hidden across the window where the store is still loading.
const isWorkspaceCovered =
!usage?.isPersonallySubscribed && (usage?.entitledWorkspaceIds?.length ?? 0) > 0;
- // Names the tier the seat actually grants. Null until the store resolves, which
- // leaves the personal-plan label untouched rather than guessing at a tier.
- const coveringPlanLabel = coveringWorkspaces.length
- ? t(
- `settingsPage.workspace.billing.planLabel.${highestPlan(
- coveringWorkspaces.map((workspace) => workspace.plan)
- )}`
- )
- : null;
+ // Null until the store resolves, so the label waits rather than guessing a tier.
+ const coveringPlanLabel =
+ isWorkspaceCovered && coveringWorkspaces.length
+ ? t(
+ `settingsPage.workspace.billing.planLabel.${highestPlan(
+ coveringWorkspaces.map((workspace) => workspace.plan)
+ )}`
+ )
+ : null;
const hasShownApproachingToast = useRef(false);
useEffect(() => {
if (usage?.isApproachingLimit && !hasShownApproachingToast.current) {
@@ -1943,9 +1941,8 @@ export default function SettingsPage({
? t("settingsPage.unifiedBilling.providedBy", {
workspaces: coveringWorkspaceNames.join(", "),
})
- : // Covered, but the workspace store hasn't resolved a
- // name yet. The free-usage copy would print the
- // subscribed sentinel limit as "-1 words".
+ : // usage.limit is -1 once subscribed, which the
+ // free-usage copy would print as "-1 words".
isWorkspaceCovered
? t("settingsPage.account.planDescriptions.unlimited")
: t("settingsPage.account.planDescriptions.freeUsage", {
diff --git a/src/lib/usageStore.ts b/src/lib/usageStore.ts
index 4ac671e74..9ff622fd3 100644
--- a/src/lib/usageStore.ts
+++ b/src/lib/usageStore.ts
@@ -6,8 +6,7 @@ const USAGE_CACHE_TTL = CACHE_CONFIG.API_KEY_TTL;
const RETRY_DELAYS_MS = [2000, 4000, 8000];
const PAID_PLANS = new Set(["pro", "business", "enterprise"]);
-// Ascending tier ladder. Unknown plans rank as free so a tier this build has
-// never heard of can never out-rank a known paid one.
+// Unknown tiers rank as free so a plan this build predates can't out-rank a paid one.
const PLAN_ORDER: Record<string, number> = { free: 0, pro: 1, business: 2, enterprise: 3 };
export function highestPlan(plans: string[]): string {