Complete favorites system version separation and homepage update

- **ChapterSelector**: Added version filtering for chapter favorites
- **VersionProp**: ChapterSelector now receives and uses version parameter
- **API calls**: Chapter favorites include version in create requests
- **Favorites filtering**: .filter(...&& fav.version === version) for both level and chapter favorites
- **Homepage text**: Changed 'Both translations' to 'All translations' for future-proofing
- **All favorite types**: Now properly separated by Bible version

Users can now safely favorite books/chapters/verses in different versions without cross-contamination.
This commit is contained in:
Ryderjj89
2025-09-28 15:32:08 -04:00
parent eeb30c24e8
commit 12c9a4a055
3 changed files with 12 additions and 8 deletions

View File

@@ -325,6 +325,7 @@ function App() {
formatBookName={formatBookName}
user={user}
onFavoriteChange={handleFavoriteChange}
version={versionId}
/>
);
};

View File

@@ -9,9 +9,10 @@ interface ChapterSelectorProps {
formatBookName: (bookName: string) => string;
user?: any;
onFavoriteChange?: () => void;
version?: string;
}
const ChapterSelector: React.FC<ChapterSelectorProps> = ({ book, onChapterSelect, onBack, formatBookName, user, onFavoriteChange }) => {
const ChapterSelector: React.FC<ChapterSelectorProps> = ({ book, onChapterSelect, onBack, formatBookName, user, onFavoriteChange, version = 'esv' }) => {
const [chapters, setChapters] = useState<string[]>([]);
const [loading, setLoading] = useState(true);
const [favorites, setFavorites] = useState<Set<string>>(new Set());
@@ -25,24 +26,25 @@ const ChapterSelector: React.FC<ChapterSelectorProps> = ({ book, onChapterSelect
if (user) {
loadFavorites();
}
}, [user, book]);
}, [user, book, version]);
const loadFavorites = async () => {
if (!user) return;
try {
const response = await fetch('/api/favorites', {
credentials: 'include'
});
if (response.ok) {
const data = await response.json();
const favoriteChapters: string[] = data.favorites
.filter((fav: any) => fav.book === book && fav.chapter && !fav.verse_start) // Only chapter-level favorites for this book
.filter((fav: any) => fav.book === book && fav.chapter && fav.version === version && !fav.verse_start) // Only chapter-level favorites for this book and version
.map((fav: any) => fav.chapter);
const chapterFavorites = new Set<string>(favoriteChapters);
setFavorites(chapterFavorites);
console.log('Loaded chapter favorites for version:', version, favoriteChapters);
}
} catch (error) {
console.error('Failed to load favorites:', error);
@@ -93,7 +95,8 @@ const ChapterSelector: React.FC<ChapterSelectorProps> = ({ book, onChapterSelect
credentials: 'include',
body: JSON.stringify({
book: book,
chapter: chapter
chapter: chapter,
version: version
})
});

View File

@@ -83,7 +83,7 @@ const VersionSelector: React.FC<VersionSelectorProps> = ({ onVersionSelect }) =>
<div className="text-center mt-12">
<p className="text-sm text-gray-500 dark:text-gray-400">
Both translations include the complete Old and New Testaments, with search and bookmarking features.
All translations include the complete Old and New Testaments, with search and bookmarking features.
</p>
</div>
</div>