From 96b9684da24e7eccd920d36322adbdc45c9ddfc1 Mon Sep 17 00:00:00 2001 From: Jannik Streek Date: Wed, 18 Dec 2024 08:05:30 +0100 Subject: [PATCH] refactor --- assets/js/app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 9d01f5ea..d65c9b97 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -6,6 +6,10 @@ import { getRelativeTimeString } from "./timeUtils" const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]'); [...tooltipTriggerList].map(tooltipTriggerEl => new Tooltip(tooltipTriggerEl)); +const sortBrainstormingsByLastAccessedAt = (brainstormings, sliceMax = 10) => { + return Object.values(brainstormings).sort((a, b) => new Date(b.last_accessed_at) - new Date(a.last_accessed_at)).slice(0, sliceMax) +} + // webpack automatically bundles all modules in your // entry points. Those entry points can be configured // in "webpack.config.js". @@ -134,7 +138,7 @@ Hooks.SetIdeaLabelBackgroundColor = { Hooks.TransferLocalStorageBrainstormings = { mounted() { const recentBrainstormings = JSON.parse(localStorage.getItem('brainstormings') || '{}'); - const lastSortedBrainstormings = Object.values(recentBrainstormings).sort((a, b) => new Date(b.last_accessed_at) - new Date(a.last_accessed_at)).slice(0, 5) + const lastSortedBrainstormings = sortBrainstormingsByLastAccessedAt(recentBrainstormings, 5) this.pushEventTo(this.el, "brainstormings_from_local_storage", lastSortedBrainstormings) } } @@ -151,7 +155,7 @@ Hooks.StoreRecentBrainstorming = { last_accessed_at: this.el.dataset.lastAccessedAt } localStorage.setItem('brainstormings', JSON.stringify(recentBrainstormings)); - const lastSortedBrainstormings = Object.values(recentBrainstormings).sort((a, b) => new Date(b.last_accessed_at) - new Date(a.last_accessed_at)).slice(0, 10) + const lastSortedBrainstormings = sortBrainstormingsByLastAccessedAt(recentBrainstormings) this.pushEventTo(this.el,"brainstormings_from_local_storage", lastSortedBrainstormings) } };