From 244a4b108de743f9a6258204b7eb8e815ace12e4 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Fri, 8 Sep 2017 18:16:49 +0700 Subject: [PATCH] Correctly detect subsequent change --- plugins/talk-plugin-remember-sort/client/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/talk-plugin-remember-sort/client/index.js b/plugins/talk-plugin-remember-sort/client/index.js index 515eda186..4f1850b3f 100644 --- a/plugins/talk-plugin-remember-sort/client/index.js +++ b/plugins/talk-plugin-remember-sort/client/index.js @@ -14,7 +14,7 @@ export default { return; } - const sort = JSON.parse(storage.getItem(STORAGE_PATH)); + let sort = JSON.parse(storage.getItem(STORAGE_PATH)); if ( sort && introspection.isValidEnumValue('SORT_ORDER', sort.sortOrder) && @@ -26,8 +26,11 @@ export default { const state = store.getState(); const sortOrder = sortOrderSelector(state); const sortBy = sortBySelector(state); + + // Save sorting choice to storage if it has changed. if (!sort || sort.sortOrder !== sortOrder || sort.sortBy !== sortBy) { - storage.setItem(STORAGE_PATH, JSON.stringify({sortOrder, sortBy})); + sort = {sortOrder, sortBy}; + storage.setItem(STORAGE_PATH, JSON.stringify(sort)); } }); }