Skip to content

Commit

Permalink
Save the sorting option in local storage (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalexling committed Jul 4, 2020
1 parent c00016f commit 38ba324
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion public/js/sort-items.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
$(() => {
const titleID = $('.data').attr('data-title-id') || 'library';

const sortItems = () => {
const sort = $('#sort-select').find(':selected').attr('id');
localStorage.setItem(`sort-${titleID}`, sort);

const ary = sort.split('-');
const by = ary[0];
const dir = ary[1];
Expand Down Expand Up @@ -115,7 +119,10 @@ $(() => {
sortItems();
});

if ($('option#auto-up').length > 0)
const sortID = localStorage.getItem(`sort-${titleID}`);
if (sortID)
$(`option#${sortID}`).attr('selected', '');
else if ($('option#auto-up').length > 0)
$('option#auto-up').attr('selected', '');
else
$('option#name-up').attr('selected', '');
Expand Down
1 change: 1 addition & 0 deletions src/views/title.html.ecr
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<div class="data" data-title-id="<%= title.id %>"></div>
<div>
<h2 class=uk-title><span><%= title.display_name %></span>
&nbsp;
Expand Down

0 comments on commit 38ba324

Please sign in to comment.