From 781ec913f2e8851b5e8de24d49851a20aa1dc8f1 Mon Sep 17 00:00:00 2001 From: I Made Setia Baruna Date: Mon, 8 Mar 2021 23:35:24 +0800 Subject: [PATCH] Fix wish ordering --- src/components/WishImportModal.svelte | 5 +---- src/routes/wish/_counter.svelte | 11 ++++++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/WishImportModal.svelte b/src/components/WishImportModal.svelte index 7cfc2ab1..7c8f5d6c 100644 --- a/src/components/WishImportModal.svelte +++ b/src/components/WishImportModal.svelte @@ -347,10 +347,7 @@ const importedWishes = wishes[code].slice().reverse(); const oldestWish = importedWishes[0]; - localWishes = localWishes - .slice() - .filter((e) => e.time < oldestWish.time) - .sort((a, b) => a.time - b.time); + localWishes = localWishes.slice().filter((e) => e.time < oldestWish.time); const combined = [...localWishes, ...importedWishes]; diff --git a/src/routes/wish/_counter.svelte b/src/routes/wish/_counter.svelte index e7ddc659..c0518800 100644 --- a/src/routes/wish/_counter.svelte +++ b/src/routes/wish/_counter.svelte @@ -99,7 +99,16 @@ } function addPullDetail(newPull) { - pulls = [...pulls, newPull]; + let index = -1; + for (let i = pulls.length - 1; i >= 0; i--) { + if (newPull.time >= pulls[i].time) { + index = i + 1; + break; + } + } + const lastPulls = [...pulls]; + lastPulls.splice(index, 0, newPull); + pulls = lastPulls; closeModal(); saveData(); }