Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit e4bb47f

Browse files
Merge pull request #278 from deckgo/sort-deck-updated_at
feat(#249): sort deck by updated dates rather than created
2 parents a888023 + d1768d6 commit e4bb47f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

studio/src/app/components/core/app-menu/app-menu.tsx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ export class AppMenu {
5959
this.decks = await this.deckService.getUserDecks(authUser.uid);
6060
await this.filterDecks(null);
6161
} catch (err) {
62-
// TODO: print error?
6362
this.decks = [];
6463
await this.filterDecks(null);
6564
}
@@ -120,13 +119,18 @@ export class AppMenu {
120119
return filteredDeck.id === deck.id;
121120
});
122121

123-
if (index < 0) {
124-
this.decks = [deck, ...this.decks];
125-
} else {
126-
this.decks[index].data.name = deck.data.name;
127-
this.decks = [...this.decks];
122+
// New deck has been updated? If not, we don't have to update the list
123+
if (index >= 0 && this.decks[index].data.updated_at && deck.data.updated_at && this.decks[index].data.updated_at.isEqual(deck.data.updated_at)) {
124+
resolve();
125+
return;
128126
}
129127

128+
if (index >= 0) {
129+
this.decks.splice(index, 1);
130+
}
131+
132+
this.decks = [deck, ...this.decks];
133+
130134
resolve();
131135
});
132136
}

studio/src/app/services/data/deck/deck.service.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class DeckService {
8585

8686
const snapshot: firebase.firestore.QuerySnapshot = await firestore.collection('decks')
8787
.where('owner_id', '==', userId)
88-
.orderBy('created_at', 'desc')
88+
.orderBy('updated_at', 'desc')
8989
.get();
9090

9191
const decks: Deck[] = snapshot.docs.map((documentSnapshot: firebase.firestore.QueryDocumentSnapshot) => {

0 commit comments

Comments
 (0)