From e09678c72f4406ad82a58b4918032dd2a4ea2d0f Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sun, 11 Nov 2018 15:43:57 +0200 Subject: [PATCH] save sorting key to cookies instead of local storage --- web/app/common/constants.js | 4 +++- web/app/components/root/root.jsx | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/web/app/common/constants.js b/web/app/common/constants.js index 2cf97f01..77937f25 100644 --- a/web/app/common/constants.js +++ b/web/app/common/constants.js @@ -15,8 +15,10 @@ export const PROVIDER_NAMES = { yandex: 'Yandex', dev: 'Dev', }; + export const LS_COLLAPSE_KEY = '__remarkCollapsed'; -export const LS_SORT_KEY = '__remarkSort'; + +export const COOKIE_SORT_KEY = 'remarkSort'; export const BLOCKING_DURATIONS = [ { diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index 986a6d47..be5a4e16 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -7,9 +7,10 @@ import { NODE_ID, COMMENT_NODE_CLASSNAME_PREFIX, DEFAULT_SORT, - LS_SORT_KEY, + COOKIE_SORT_KEY, MAX_SHOWN_ROOT_COMMENTS, } from 'common/constants'; +import { getCookie, setCookie } from 'common/cookies'; import { siteId, url, maxShownComments } from 'common/settings'; import store from 'common/store'; @@ -29,7 +30,7 @@ export default class Root extends Component { let sort; try { - sort = localStorage.getItem(LS_SORT_KEY) || DEFAULT_SORT; + sort = getCookie(COOKIE_SORT_KEY) || DEFAULT_SORT; } catch (e) { sort = DEFAULT_SORT; } @@ -190,7 +191,7 @@ export default class Root extends Component { this.setState({ sort, isCommentsListLoading: true }); try { - localStorage.setItem(LS_SORT_KEY, sort); + setCookie(COOKIE_SORT_KEY, sort, { expires: 60 * 60 * 24 * 365 }); // save sorting for a year } catch (e) { // can't save; ignore it }