Skip to content

Commit

Permalink
fix(compose): Current draft, newest drafts, are now at the top
Browse files Browse the repository at this point in the history
  • Loading branch information
castaway committed Apr 29, 2024
1 parent 053df50 commit bbd9b02
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/compose/draftdesk.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@ export class DraftDeskComponent implements OnInit {

updateDraftsInView() {
if (this.draftModelsInView.length > 0) {
// need to apply C(R)UD instead of setting the new array:
// Add any new ones
// Update in-place rather than just redrawing the whole array:
// Add any "new" ones
// This includes items we excluded because of max-length
// don't worry, the sort will fix em
const newEntries = this.draftDeskservice.draftModels.value.filter(
(msg) => !this.draftModelsInView.some(
(dMsg) => dMsg.mid === msg.mid));
Expand Down Expand Up @@ -101,7 +103,7 @@ export class DraftDeskComponent implements OnInit {
}
});
this.draftModelsInView.splice(0, 0, ...newEntries);
this.draftModelsInView.sort((a,b) => a.mid < b.mid ? -1 : 1);
this.draftModelsInView.sort((a,b) => a.mid == -1 ? -1 : b.mid == -1 ? 1 : a.mid > b.mid ? -1 : 1);
this.draftModelsInView = this.draftModelsInView.slice(0, this.currentMaxDraftsInView);
deletedEntries.forEach(
(dMsgId) => this.draftModelsInView.splice(this.draftModelsInView.findIndex((dMsg) => dMsg.mid === dMsgId), 1));
Expand Down

0 comments on commit bbd9b02

Please sign in to comment.