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 }