mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-05-02 13:44:54 +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);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const items = await catalogService.getLibraryItems();
|
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
|
// 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
|
// Map StreamingContent to LibraryItem shape
|
||||||
const libraryItem: LibraryItem = {
|
const libraryItem: LibraryItem = {
|
||||||
...item,
|
...item,
|
||||||
|
|
@ -301,8 +309,15 @@ const LibraryScreen = () => {
|
||||||
|
|
||||||
// Subscribe to library updates
|
// Subscribe to library updates
|
||||||
const unsubscribe = catalogService.subscribeToLibraryUpdates(async (items) => {
|
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
|
// 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
|
// Map StreamingContent to LibraryItem shape
|
||||||
const libraryItem: LibraryItem = {
|
const libraryItem: LibraryItem = {
|
||||||
...item,
|
...item,
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,7 @@ export interface StreamingContent {
|
||||||
poster_path?: string;
|
poster_path?: string;
|
||||||
backdrop_path?: string;
|
backdrop_path?: string;
|
||||||
};
|
};
|
||||||
|
addedToLibraryAt?: number; // Timestamp when added to library
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CatalogContent {
|
export interface CatalogContent {
|
||||||
|
|
@ -853,7 +854,10 @@ class CatalogService {
|
||||||
|
|
||||||
public async addToLibrary(content: StreamingContent): Promise<void> {
|
public async addToLibrary(content: StreamingContent): Promise<void> {
|
||||||
const key = `${content.type}:${content.id}`;
|
const key = `${content.type}:${content.id}`;
|
||||||
this.library[key] = content;
|
this.library[key] = {
|
||||||
|
...content,
|
||||||
|
addedToLibraryAt: Date.now() // Add timestamp
|
||||||
|
};
|
||||||
this.saveLibrary();
|
this.saveLibrary();
|
||||||
this.notifyLibrarySubscribers();
|
this.notifyLibrarySubscribers();
|
||||||
try { this.libraryAddListeners.forEach(l => l(content)); } catch {}
|
try { this.libraryAddListeners.forEach(l => l(content)); } catch {}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue