Skip to content

Commit 6d797c3

Browse files
committed
Try to fix local storage issue by resetting the filter
1 parent f6917ea commit 6d797c3

1 file changed

Lines changed: 23 additions & 15 deletions

File tree

app.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ let DATA_INDEX = []
7070
let min_loaded_year = 0;
7171
let max_loaded_year = 0;
7272

73-
let FILTER = JSON.parse(localStorage.getItem('filter')) ?? {
74-
school: [0, CONSTANTS.school_years.length-1],
75-
sciences: Object.keys(CONSTANTS.sciences),
76-
countries: Object.keys(CONSTANTS.countries),
77-
types: CONSTANTS.type_combinations,
78-
organizers: [...DEFAULT_ORGANIZERS, '*'],
79-
default_organizers: DEFAULT_ORGANIZERS,
73+
function load_new_filter(){
74+
return {
75+
school: [0, CONSTANTS.school_years.length-1],
76+
sciences: Object.keys(CONSTANTS.sciences),
77+
countries: Object.keys(CONSTANTS.countries),
78+
types: CONSTANTS.type_combinations,
79+
organizers: [...DEFAULT_ORGANIZERS, '*'],
80+
default_organizers: DEFAULT_ORGANIZERS,
81+
}
8082
}
83+
let FILTER = JSON.parse(localStorage.getItem('filter')) ?? load_new_filter();
84+
8185
const CALENDAR = jsCalendar.new({
8286
target: '#calendar',
8387
firstDayOfTheWeek: '2',
@@ -361,7 +365,6 @@ const render = (move_focus = true) => {
361365
})
362366

363367
// Type filter
364-
console.log(FILTER.types);
365368
visible_events = visible_events.filter((event) => {
366369
for (let i = FILTER.types.length - 1; i >= 0; i--) {
367370
if (FILTER.types[i].indexOf(event.type) !== -1) return true
@@ -515,13 +518,18 @@ setup_calendar()
515518

516519
// FILTERS
517520
const filter_update_checked = () => {
518-
document.querySelectorAll('.js-filter-checkbox').forEach((elem) => {
519-
if (FILTER[elem.dataset.filter].indexOf(elem.value) !== -1) {
520-
elem.checked = true
521-
} else {
522-
elem.checked = false
523-
}
524-
})
521+
try {
522+
document.querySelectorAll('.js-filter-checkbox').forEach((elem) => {
523+
if (FILTER[elem.dataset.filter].indexOf(elem.value) !== -1) {
524+
elem.checked = true
525+
} else {
526+
elem.checked = false
527+
}
528+
})
529+
} catch {
530+
FILTER = load_new_filter();
531+
filter_update_checked();
532+
}
525533
}
526534

527535
window.addEventListener('keydown', e => {

0 commit comments

Comments
 (0)