From 74f6220d7cac7afb601ca20136218e08b8ae1305 Mon Sep 17 00:00:00 2001 From: Andrew Bierman Date: Fri, 10 Apr 2026 23:48:42 -0600 Subject: [PATCH] chore(guards): migrate remaining expo files to @packrat/guards Finishes the migration started in #2039: - apps/expo/lib/utils/itemCalculations.ts: replace the inline isWeightUnit guard with makeEnumGuard from @packrat/guards and export it so other call sites can reuse it - apps/expo/features/packs/components/PackCard.tsx: import isArray from @packrat/guards instead of radash directly - apps/expo/features/pack-templates/components/PackTemplateCard.tsx: same - apps/expo/features/pack-templates/hooks/useGenerateTemplateFromOnlineContent.ts: use the canonical isWeightUnit from itemCalculations instead of re-declaring an inline copy --- .../pack-templates/components/PackTemplateCard.tsx | 2 +- .../hooks/useGenerateTemplateFromOnlineContent.ts | 7 ++----- apps/expo/features/packs/components/PackCard.tsx | 2 +- apps/expo/lib/utils/itemCalculations.ts | 8 ++++---- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/apps/expo/features/pack-templates/components/PackTemplateCard.tsx b/apps/expo/features/pack-templates/components/PackTemplateCard.tsx index 155e27a28d..c8881283a4 100644 --- a/apps/expo/features/pack-templates/components/PackTemplateCard.tsx +++ b/apps/expo/features/pack-templates/components/PackTemplateCard.tsx @@ -1,4 +1,5 @@ import { useActionSheet } from '@expo/react-native-action-sheet'; +import { isArray } from '@packrat/guards'; import { Button, Text } from '@packrat/ui/nativewindui'; import { Icon } from '@roninoss/icons'; import { appAlert } from 'expo-app/app/_layout'; @@ -6,7 +7,6 @@ import { WeightBadge } from 'expo-app/components/initial/WeightBadge'; import { useColorScheme } from 'expo-app/lib/hooks/useColorScheme'; import { useTranslation } from 'expo-app/lib/hooks/useTranslation'; import { router } from 'expo-router'; -import { isArray } from 'radash'; import { Image, Pressable, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useDeletePackTemplate, usePackTemplateDetails } from '../hooks'; diff --git a/apps/expo/features/pack-templates/hooks/useGenerateTemplateFromOnlineContent.ts b/apps/expo/features/pack-templates/hooks/useGenerateTemplateFromOnlineContent.ts index 3cddc4065b..296a264059 100644 --- a/apps/expo/features/pack-templates/hooks/useGenerateTemplateFromOnlineContent.ts +++ b/apps/expo/features/pack-templates/hooks/useGenerateTemplateFromOnlineContent.ts @@ -1,13 +1,10 @@ import { useMutation } from '@tanstack/react-query'; import axiosInstance, { handleApiError } from 'expo-app/lib/api/client'; import { obs } from 'expo-app/lib/store'; +import { isWeightUnit } from 'expo-app/lib/utils/itemCalculations'; import { packTemplateItemsStore } from '../store/packTemplateItems'; import { packTemplatesStore } from '../store/packTemplates'; -import type { PackTemplateInStore, PackTemplateItem, WeightUnit } from '../types'; - -const WEIGHT_UNITS: ReadonlySet = new Set(['g', 'kg', 'oz', 'lb']); -const isWeightUnit = (value: string): value is WeightUnit => - (WEIGHT_UNITS as ReadonlySet).has(value); +import type { PackTemplateInStore, PackTemplateItem } from '../types'; export interface GenerateFromOnlineContentInput { contentUrl: string; diff --git a/apps/expo/features/packs/components/PackCard.tsx b/apps/expo/features/packs/components/PackCard.tsx index 86d010bcf7..64eb89870f 100644 --- a/apps/expo/features/packs/components/PackCard.tsx +++ b/apps/expo/features/packs/components/PackCard.tsx @@ -1,10 +1,10 @@ import { useActionSheet } from '@expo/react-native-action-sheet'; +import { isArray } from '@packrat/guards'; import { Button, Text } from '@packrat/ui/nativewindui'; import { Icon } from '@roninoss/icons'; import { WeightBadge } from 'expo-app/components/initial/WeightBadge'; import { useColorScheme } from 'expo-app/lib/hooks/useColorScheme'; import { router } from 'expo-router'; -import { isArray } from 'radash'; import { Alert, Image, Pressable, View } from 'react-native'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { useDeletePack, usePackDetailsFromStore } from '../hooks'; diff --git a/apps/expo/lib/utils/itemCalculations.ts b/apps/expo/lib/utils/itemCalculations.ts index 8f9d55e1a2..ed2d30a59e 100644 --- a/apps/expo/lib/utils/itemCalculations.ts +++ b/apps/expo/lib/utils/itemCalculations.ts @@ -1,9 +1,13 @@ +import { makeEnumGuard } from '@packrat/guards'; import type { CatalogItem } from 'expo-app/features/catalog/types'; import type { PackTemplateItem } from 'expo-app/features/pack-templates'; import type { PackItem, WeightUnit } from 'expo-app/features/packs'; type Item = CatalogItem | PackItem | PackTemplateItem; +const WEIGHT_UNITS = ['g', 'kg', 'oz', 'lb'] as const satisfies readonly WeightUnit[]; +export const isWeightUnit = makeEnumGuard(WEIGHT_UNITS); + /** * Checks if an item is a catalog item */ @@ -43,10 +47,6 @@ export function getWeightUnit(item: Item): WeightUnit { return item.weightUnit; } -function isWeightUnit(value: string): value is WeightUnit { - return ['g', 'oz', 'kg', 'lb'].includes(value); -} - /** Gets the notes of an item */ export function getNotes(item: Item): string | undefined { return isCatalogItem(item) ? undefined : item.notes;