ThatAIguyA world of ideas

THE CONSCIOUSNESS ATLAS
Read. Experiment. Follow the evidence.

ConsciousnessLearn · Explore · Joseph Anady

Janady13/llms-txt-hub / apps/web/components/favorites/favorites-context.tsx

Source identity, revision, and recovered contents.

GitHub sourceSource text recovered

Source identity

FieldRecorded value
Source typeGitHub source
Original recordJanady13/llms-txt-hub / apps/web/components/favorites/favorites-context.tsx
DateNot specified in source
RepositoryJanady13/llms-txt-hub
Revisione0f4bf978d4df168369c7601d9c5f5ea89e84377
Branchmain
Path or archive memberapps/web/components/favorites/favorites-context.tsx
Original SHA-25635b897868664a02de5d27b56c2b782825f591acf9bc20a514789dda4703e6259
Git blob SHAd03d447eac7ba0dbac53e825d5dc5761de2dce56
Reading-copy SHA-25635b897868664a02de5d27b56c2b782825f591acf9bc20a514789dda4703e6259

Original source ↗

Recovered source transcript

'use client' import { useAuth } from '@thedaviddias/auth' import { logger } from '@thedaviddias/logging' import { createContext, useCallback, useContext, useEffect, useState } from 'react' import { getFavoritesFromStorage, saveFavoritesToStorage, toggleFavorite as toggleFavoriteLogic } from '@/lib/favorites' interface FavoritesContextType { favorites: Set<string> favoritesCount: number isFavorite: (slug: string) => boolean toggleFavorite: (slug: string) => void isLoading: boolean } const FavoritesContext = createContext<FavoritesContextType | undefined>(undefined) /** * Provides favorites state and actions to child components */ export function FavoritesProvider({ children }: { children: React.ReactNode }) { const [favorites, setFavorites] = useState<Set<string>>(new Set()) const [isLoading, setIsLoading] = useState(true) const { user } = useAuth() // Initialize favorites from localStorage on mount useEffect(() => { const storedFavorites = getFavoritesFromStorage() setFavorites(new Set(storedFavorites)) setIsLoading(false) }, []) // Sync with user profile when user changes useEffect(() => { if (!user) return /** * Syncs local favorites with the user's server-side profile */ const syncWithProfile = async () => { try { // TODO: Implement user profile sync // For now, we rely on localStorage as the primary storage logger.info('User profile sync not implemented yet') } catch (error) { logger.error('Failed to sync with user profile:', { data: error, tags: { type: 'component' } }) } } syncWithProfile() }, [user]) const isFavorite = useCallback((slug: string) => favorites.has(slug), [favorites]) const toggleFavorite = useCallback( (slug: string) => { setFavorites(prev => { const current = Array.from(prev) const updated = toggleFavoriteLogic(slug, current) const newSet = new Set(updated) // Save to localStorage saveFavoritesToStorage(updated) // If user is logged in, update their profile if (user) { // TODO: Update user profile // This would require calling a server action or API route } return newSet }) }, [user] ) return ( <FavoritesContext.Provider value={{ favorites, favoritesCount: favorites.size, isFavorite, toggleFavorite, isLoading }} > {children} </FavoritesContext.Provider> ) } /** * Hook that provides access to the favorites context */ export function useFavorites() { const context = useContext(FavoritesContext) if (context === undefined) { throw new Error('useFavorites must be used within a FavoritesProvider') } return context }

Search equations, builds, manuscript text, and recovered sources.