Merge pull request 'Raccourcit les liens de partage' (#47) from thubrecht/reduce-share into master

Reviewed-on: https://git.rz.ens.wtf/Klub-RZ/metis/pulls/47
This commit is contained in:
tomate 2022-08-04 23:32:10 +02:00
commit 0ee44ac32a
2 changed files with 26 additions and 1 deletions

View file

@ -9,6 +9,8 @@
Toast
} from 'sveltestrap';
import { ancestors } from './calendar';
export let calendar = null;
export let selectedCalendars = [];
@ -33,6 +35,16 @@
.finally((isToastOpen = true));
};
const filter = calendars => {
let reduced = [];
calendars.forEach(c => {
if (!ancestors[c].some(p => calendars.includes(p))) {
reduced.push(c);
}
});
return reduced;
};
const updateShareLink = () => {
const loc = document.location;
const search = new URLSearchParams();
@ -41,7 +53,7 @@
if (calendar !== null) {
search.append('v', api.view.type);
selectedCalendars.forEach(c => search.append('c', c));
filter(selectedCalendars).forEach(c => search.append('c', c));
search.append('d', api.getDate().toISOString());
}

View file

@ -176,6 +176,19 @@ export const calendarTree = {
Divers: {}
}
const dfs = (p, t, l) => {
for (const [c, s] of Object.entries(t)) {
l[c] = p === null ? [] : [p, ...l[p]]
dfs(c, s, l)
}
}
export const ancestors = (() => {
let l = []
dfs(null, calendarTree, l)
return l
})()
export function getSubCalendars(name, tree = calendarTree) {
let ret
for (const [cal, subTree] of Object.entries(tree)) {