Remember story sorting in local storage
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { jobPanel, refreshJobs, watchJobs } from './jobs.js';
|
||||
import { api, badge, button, checkbox, fill, fmtDate, h, link, showError, toast } from './lib.js';
|
||||
|
||||
const STORY_SORT_KEY = 'bindery.story-sort';
|
||||
const STORY_COLUMNS = [
|
||||
{ label: 'Title', key: 'title', type: 'text' },
|
||||
{ label: 'Author', key: 'author', type: 'text' },
|
||||
@@ -219,6 +220,15 @@ export function storiesPage(main, _params, config) {
|
||||
let filter = '';
|
||||
let sort = 'title';
|
||||
let direction = 1;
|
||||
try {
|
||||
const saved = JSON.parse(window.localStorage.getItem(STORY_SORT_KEY));
|
||||
if (saved && STORY_COLUMNS.some(({ key }) => key === saved.column) && [1, -1].includes(saved.direction)) {
|
||||
sort = saved.column;
|
||||
direction = saved.direction;
|
||||
}
|
||||
} catch {
|
||||
// Keep the default if storage is blocked or its value is invalid.
|
||||
}
|
||||
const sortButtons = new Map();
|
||||
const table = h('div', {}, h('p', { class: 'empty' }, 'Loading…'));
|
||||
const jobs = jobPanel({ hours: config.main_jobs_hours, count: config.main_jobs_count });
|
||||
@@ -260,6 +270,11 @@ export function storiesPage(main, _params, config) {
|
||||
const control = button(label, () => {
|
||||
sort = key;
|
||||
direction = nextDirection;
|
||||
try {
|
||||
window.localStorage.setItem(STORY_SORT_KEY, JSON.stringify({ column: sort, direction }));
|
||||
} catch {
|
||||
// Sorting still works when the browser blocks storage.
|
||||
}
|
||||
render();
|
||||
sortButtons.get(key).focus();
|
||||
}, { title: action, 'aria-label': action });
|
||||
|
||||
Reference in New Issue
Block a user