1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Remove redundant logic in client-side javascript

This commit is contained in:
Daste 2022-12-03 12:50:55 +01:00
parent 97fab3e109
commit 10648d66ad
2 changed files with 4 additions and 19 deletions

View File

@ -2,15 +2,8 @@ PetiteVue.createApp({
$delimiters: ['${', '}'],
get currentInterval() {
const urlParams = new URLSearchParams(window.location.search)
const cookies = new URLSearchParams(document.cookie.replaceAll('; ', '&'))
if (urlParams.has('interval'))
return urlParams.get('interval')
if (cookies.has('wakapi_summary_interval'))
return cookies.get('wakapi_summary_interval')
if (!urlParams.has('from') && !urlParams.has('to'))
return 'today'
if (urlParams.has('interval')) return urlParams.get('interval')
if (!urlParams.has('from') && !urlParams.has('to')) return 'today'
return null
}
}).mount('#summary-page')

View File

@ -23,16 +23,8 @@ function TimePicker({ fromDate, toDate, timeSelection }) {
})
const query = new URLSearchParams(window.location.search)
const cookies = new URLSearchParams(document.cookie.replaceAll('; ', '&'))
let interval = undefined;
if (query.has('interval'))
interval = query.get('interval')
else if (cookies.has('wakapi_summary_interval'))
interval = cookies.get('wakapi_summary_interval')
if (interval) {
const refEl = document.getElementById(`time-option-${interval}`)
if (query.has('interval')) {
const refEl = document.getElementById(`time-option-${query.get('interval')}`)
this.timeSelection = refEl ? refEl.innerText : 'Unknown'
}
}