diff --git a/components/DatabaseProvider.tsx b/components/DatabaseProvider.tsx index d5a16e2..5ebf129 100644 --- a/components/DatabaseProvider.tsx +++ b/components/DatabaseProvider.tsx @@ -3,7 +3,6 @@ import { View, ActivityIndicator, ScrollView, Text } from 'react-native'; import { SQLiteProvider, openDatabaseSync, SQLiteDatabase } from 'expo-sqlite'; import { schema } from '@/lib/db/schema'; import { ExerciseService } from '@/lib/db/services/ExerciseService'; -import { DevSeederService } from '@/lib/db/services/DevSeederService'; import { PublicationQueueService } from '@/lib/db/services/PublicationQueueService'; import { FavoritesService } from '@/lib/db/services/FavoritesService'; import { WorkoutService } from '@/lib/db/services/WorkoutService'; @@ -17,7 +16,6 @@ interface DatabaseServicesContextValue { exerciseService: ExerciseService | null; workoutService: WorkoutService | null; templateService: TemplateService | null; - devSeeder: DevSeederService | null; publicationQueue: PublicationQueueService | null; favoritesService: FavoritesService | null; powrPackService: POWRPackService | null; @@ -28,7 +26,6 @@ const DatabaseServicesContext = React.createContext = ({children}) = return <>{children}; }; + export function DatabaseProvider({ children }: DatabaseProviderProps) { const [isReady, setIsReady] = React.useState(false); const [error, setError] = React.useState(null); @@ -71,7 +69,6 @@ export function DatabaseProvider({ children }: DatabaseProviderProps) { exerciseService: null, workoutService: null, templateService: null, - devSeeder: null, publicationQueue: null, favoritesService: null, powrPackService: null, @@ -83,8 +80,7 @@ export function DatabaseProvider({ children }: DatabaseProviderProps) { // Effect to set NDK on services when it becomes available React.useEffect(() => { - if (ndk && services.devSeeder && services.publicationQueue) { - services.devSeeder.setNDK(ndk); + if (ndk && services.publicationQueue) { services.publicationQueue.setNDK(ndk); } }, [ndk, services]); @@ -129,7 +125,6 @@ export function DatabaseProvider({ children }: DatabaseProviderProps) { const exerciseService = new ExerciseService(db); const workoutService = new WorkoutService(db); const templateService = new TemplateService(db, exerciseService); - const devSeeder = new DevSeederService(db, exerciseService); const publicationQueue = new PublicationQueueService(db); const favoritesService = new FavoritesService(db); const powrPackService = new POWRPackService(db); @@ -139,7 +134,6 @@ export function DatabaseProvider({ children }: DatabaseProviderProps) { // Initialize NDK on services if available if (ndk) { - devSeeder.setNDK(ndk); publicationQueue.setNDK(ndk); } @@ -148,21 +142,14 @@ export function DatabaseProvider({ children }: DatabaseProviderProps) { exerciseService, workoutService, templateService, - devSeeder, publicationQueue, favoritesService, powrPackService, db, }); - // Seed development database + + // Display database info in development mode if (__DEV__) { - console.log('[DB] Seeding development database...'); - try { - await devSeeder.seedDatabase(); - } catch (seedError) { - console.error('[DB] Error seeding database:', seedError); - // Continue even if seeding fails - } await logDatabaseInfo(); } @@ -231,14 +218,6 @@ export function useTemplateService() { return context.templateService; } -export function useDevSeeder() { - const context = React.useContext(DatabaseServicesContext); - if (!context.devSeeder) { - throw new Error('Dev seeder not initialized'); - } - return context.devSeeder; -} - export function usePublicationQueue() { const context = React.useContext(DatabaseServicesContext); if (!context.publicationQueue) { @@ -269,4 +248,4 @@ export function useDatabase() { throw new Error('Database not initialized'); } return context.db; -} +} \ No newline at end of file diff --git a/components/social/POWRPackSection.tsx b/components/social/POWRPackSection.tsx index e9bd47c..43e5ce0 100644 --- a/components/social/POWRPackSection.tsx +++ b/components/social/POWRPackSection.tsx @@ -13,77 +13,42 @@ import { PackageOpen, ArrowRight } from 'lucide-react-native'; import { NDKEvent } from '@nostr-dev-kit/ndk-mobile'; import { usePOWRPackService } from '@/components/DatabaseProvider'; import { Clipboard } from 'react-native'; - -// Hardcoded test pack naddr -const TEST_PACK_NADDR = 'naddr1qq88qmmhwgkhgetnwskhqctrdvqs6amnwvaz7tmwdaejumr0dsq3gamnwvaz7tmjv4kxz7fwv3sk6atn9e5k7q3q25f8lj0pcq7xk3v68w4h9ldenhh3v3x97gumm5yl8e0mgq0dnvssxpqqqp6ng325rsl'; +import { nip19 } from 'nostr-tools'; export default function POWRPackSection() { const { ndk } = useNDK(); const powrPackService = usePOWRPackService(); const [featuredPacks, setFeaturedPacks] = useState([]); - const [isLoading, setIsLoading] = useState(true); // Subscribe to POWR packs (kind 30004 with powrpack hashtag) - const { events, isLoading: isSubscribeLoading } = useSubscribe( - ndk ? [{ kinds: [30004], '#t': ['powrpack'], limit: 10 }] : false, + const { events, isLoading } = useSubscribe( + ndk ? [{ kinds: [30004], '#t': ['powrpack', 'fitness', 'workout'], limit: 10 }] : false, { enabled: !!ndk } ); - // Set up test data on component mount - useEffect(() => { - const setupTestData = async () => { - try { - setIsLoading(true); - // For testing, create a mock event that mimics what we'd get from the network - const testPack = new NDKEvent(ndk || undefined); - testPack.kind = 30004; - testPack.pubkey = '55127fc9e1c03c6b459a3bab72fdb99def1644c5f239bdd09f3e5fb401ed9b21'; - testPack.content = 'This is a test POWR Pack containing 2 workout templates and 2 exercises. Created for testing POWR Pack import functionality.'; - testPack.id = 'c1838367545275c12a969b7f1b84c60edbaec548332bfb4af7e2d12926090211'; - testPack.created_at = 1741832829; - - // Add all the tags - testPack.tags = [ - ['d', 'powr-test-pack'], - ['name', 'POWR Test Pack'], - ['about', 'A test collection of workout templates and exercises for POWR app'], - ['a', '33402:55127fc9e1c03c6b459a3bab72fdb99def1644c5f239bdd09f3e5fb401ed9b21:e8256e9f70b87ad9fc4cf5712fe8f61641fc1313c608c38525c81537b5b411a5'], - ['a', '33402:55127fc9e1c03c6b459a3bab72fdb99def1644c5f239bdd09f3e5fb401ed9b21:404faf8c2bc3cf2477b7753b0888af48fd1416c3ff77a019fef89a8199826bcd'], - ['a', '33401:55127fc9e1c03c6b459a3bab72fdb99def1644c5f239bdd09f3e5fb401ed9b21:d25892222f1bb4a457c840c5c829915c4e2a0d1ced55b40d69e4682d9a8e3fb2'], - ['a', '33401:55127fc9e1c03c6b459a3bab72fdb99def1644c5f239bdd09f3e5fb401ed9b21:9f93ee6c8c314e7938ebf00e3de86e6e255c3ed48ad9763843758669092bb92a'] - ]; - - // Always include the test pack in our featured packs - setFeaturedPacks([testPack]); - } catch (error) { - console.error('Error setting up test data:', error); - } finally { - setIsLoading(false); - } - }; - - setupTestData(); - }, [ndk]); - // Update featured packs when events change useEffect(() => { if (events.length > 0) { - // Combine the test pack with any events from the subscription - setFeaturedPacks(prevPacks => { - // Filter out duplicates by ID - const uniqueEvents = events.filter(event => - !prevPacks.some(pack => pack.id === event.id) - ); - return [...prevPacks, ...uniqueEvents]; - }); + setFeaturedPacks(events); } }, [events]); // Handle pack click const handlePackClick = (packEvent: NDKEvent) => { try { + // Get dTag for the pack + const dTag = findTagValue(packEvent.tags, 'd'); + if (!dTag) { + throw new Error('Pack is missing identifier (d tag)'); + } + // Create shareable naddr - const naddr = TEST_PACK_NADDR; // Use hardcoded test pack naddr for now + const naddr = nip19.naddrEncode({ + kind: 30004, + pubkey: packEvent.pubkey, + identifier: dTag, + relays: ['wss://relay.damus.io', 'wss://nos.lol', 'wss://relay.nostr.band'] + }); // Copy to clipboard Clipboard.setString(naddr); @@ -104,8 +69,8 @@ export default function POWRPackSection() { router.push('/(packs)/manage'); }; - // Even if there are no network packs, we'll always show our test pack - const showSection = true; + // Only show section if we have packs or are loading + const showSection = featuredPacks.length > 0 || isLoading; if (!showSection) { return null; @@ -182,7 +147,7 @@ export default function POWRPackSection() { No packs found