From 5457157856dca28fb6afacdbc45b80ed11a65bb2 Mon Sep 17 00:00:00 2001 From: igoradamenko Date: Sun, 6 May 2018 23:17:37 +0300 Subject: [PATCH] save comment sort to LS --- web/app/components/root/root.jsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/web/app/components/root/root.jsx b/web/app/components/root/root.jsx index 4dbe89ef..473cf4fa 100644 --- a/web/app/components/root/root.jsx +++ b/web/app/components/root/root.jsx @@ -12,15 +12,25 @@ import Input from 'components/input'; import Preloader from 'components/preloader'; import Thread from 'components/thread'; +const LS_SORT_KEY = '__remarkSort'; + export default class Root extends Component { constructor(props) { super(props); + let sort; + + try { + sort = localStorage.getItem(LS_SORT_KEY); + } catch(e) { + sort = '-score'; + } + this.state = { loaded: false, user: {}, replyingCommentId: null, - sort: '-score', + sort, }; this.addComment = this.addComment.bind(this); @@ -141,6 +151,12 @@ export default class Root extends Component { this.setState({ sort }); + try { + localStorage.setItem(LS_SORT_KEY, sort); + } catch (e) { + // can't save; ignore it + } + api.find({ sort, url }).then(({ comments } = {}) => store.set('comments', comments)); } @@ -159,7 +175,7 @@ export default class Root extends Component { }); } - render({}, { config = {}, comments = [], user, loaded, isBlockedVisible, bannedUsers, replyingCommentId }) { + render({}, { config = {}, comments = [], user, sort, loaded, isBlockedVisible, bannedUsers, replyingCommentId }) { if (!loaded) { return (
@@ -179,6 +195,7 @@ export default class Root extends Component {