Raccourcit les liens de partage

This commit is contained in:
Tom Hubrecht 2022-08-02 18:08:58 +02:00
parent 30259d31bd
commit 6aa3c6820c
2 changed files with 26 additions and 1 deletions

View file

@ -9,6 +9,8 @@
Toast Toast
} from 'sveltestrap'; } from 'sveltestrap';
import { ancestors } from './calendar';
export let calendar = null; export let calendar = null;
export let selectedCalendars = []; export let selectedCalendars = [];
@ -33,6 +35,16 @@
.finally((isToastOpen = true)); .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 updateShareLink = () => {
const loc = document.location; const loc = document.location;
const search = new URLSearchParams(); const search = new URLSearchParams();
@ -41,7 +53,7 @@
if (calendar !== null) { if (calendar !== null) {
search.append('v', api.view.type); 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()); search.append('d', api.getDate().toISOString());
} }

View file

@ -176,6 +176,19 @@ export const calendarTree = {
Divers: {} 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) { export function getSubCalendars(name, tree = calendarTree) {
let ret let ret
for (const [cal, subTree] of Object.entries(tree)) { for (const [cal, subTree] of Object.entries(tree)) {