mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-03-11 17:45:38 +00:00
fixed order of library screen contents
This commit is contained in:
parent
a0e5332897
commit
d6216d95db
2 changed files with 22 additions and 3 deletions
|
|
@ -274,8 +274,16 @@ const LibraryScreen = () => {
|
|||
setLoading(true);
|
||||
try {
|
||||
const items = await catalogService.getLibraryItems();
|
||||
|
||||
// Sort by date added (most recent first)
|
||||
const sortedItems = items.sort((a, b) => {
|
||||
const timeA = (a as any).addedToLibraryAt || 0;
|
||||
const timeB = (b as any).addedToLibraryAt || 0;
|
||||
return timeB - timeA; // Descending order (newest first)
|
||||
});
|
||||
|
||||
// Load watched status for each item from AsyncStorage
|
||||
const updatedItems = await Promise.all(items.map(async (item) => {
|
||||
const updatedItems = await Promise.all(sortedItems.map(async (item) => {
|
||||
// Map StreamingContent to LibraryItem shape
|
||||
const libraryItem: LibraryItem = {
|
||||
...item,
|
||||
|
|
@ -301,8 +309,15 @@ const LibraryScreen = () => {
|
|||
|
||||
// Subscribe to library updates
|
||||
const unsubscribe = catalogService.subscribeToLibraryUpdates(async (items) => {
|
||||
// Sort by date added (most recent first)
|
||||
const sortedItems = items.sort((a, b) => {
|
||||
const timeA = (a as any).addedToLibraryAt || 0;
|
||||
const timeB = (b as any).addedToLibraryAt || 0;
|
||||
return timeB - timeA; // Descending order (newest first)
|
||||
});
|
||||
|
||||
// Sync watched status on update
|
||||
const updatedItems = await Promise.all(items.map(async (item) => {
|
||||
const updatedItems = await Promise.all(sortedItems.map(async (item) => {
|
||||
// Map StreamingContent to LibraryItem shape
|
||||
const libraryItem: LibraryItem = {
|
||||
...item,
|
||||
|
|
|
|||
|
|
@ -131,6 +131,7 @@ export interface StreamingContent {
|
|||
poster_path?: string;
|
||||
backdrop_path?: string;
|
||||
};
|
||||
addedToLibraryAt?: number; // Timestamp when added to library
|
||||
}
|
||||
|
||||
export interface CatalogContent {
|
||||
|
|
@ -853,7 +854,10 @@ class CatalogService {
|
|||
|
||||
public async addToLibrary(content: StreamingContent): Promise<void> {
|
||||
const key = `${content.type}:${content.id}`;
|
||||
this.library[key] = content;
|
||||
this.library[key] = {
|
||||
...content,
|
||||
addedToLibraryAt: Date.now() // Add timestamp
|
||||
};
|
||||
this.saveLibrary();
|
||||
this.notifyLibrarySubscribers();
|
||||
try { this.libraryAddListeners.forEach(l => l(content)); } catch {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue