From 0709cabea197bc705a2909004659beee42503a16 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Tue, 10 Sep 2019 06:08:19 -0500 Subject: [PATCH] Fix journal ordering (#28) --- src/app/.gitignore | 2 +- src/app/src/store/index.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/app/.gitignore b/src/app/.gitignore index d20aef9..7851063 100644 --- a/src/app/.gitignore +++ b/src/app/.gitignore @@ -21,4 +21,4 @@ yarn-error.log* *.sw* # Auth0 settings -src/auth/auth0-variables.js \ No newline at end of file +src/auth/auth0-variables.* \ No newline at end of file diff --git a/src/app/src/store/index.js b/src/app/src/store/index.js index 9b06795..d50a4b8 100644 --- a/src/app/src/store/index.js +++ b/src/app/src/store/index.js @@ -50,6 +50,14 @@ const setBearer = async function () { } /* eslint-enable no-console */ +/** + * Sort journal requests either by asOf or showAfter + */ +const journalSort = function (a, b) { + const sortValue = x => x.showAfter === 0 ? x.asOf : x.showAfter + return sortValue(a) - sortValue(b) +} + export default new Vuex.Store({ state: { user: auth.session.profile, @@ -62,7 +70,7 @@ export default new Vuex.Store({ state.isLoadingJournal = flag }, [mutations.LOADED_JOURNAL] (state, journal) { - state.journal = journal + state.journal = journal.sort(journalSort) }, [mutations.REQUEST_ADDED] (state, newRequest) { state.journal.push(newRequest)