Finalize watchlist migration
This commit is contained in:
+23
-3
@@ -2,9 +2,29 @@ import { Controller } from 'stimulus'
|
|||||||
|
|
||||||
export default class extends Controller {
|
export default class extends Controller {
|
||||||
|
|
||||||
static targets = [ 'watchlist' ]
|
static targets = [ 'watchlist', 'watchlistLabel' ]
|
||||||
|
static values = { watchlist: Array }
|
||||||
|
|
||||||
updateWatchlist(e) {
|
connect() {
|
||||||
this.watchlistTarget.style.display = e.detail.length ? 'block' : 'none'
|
const initialList = JSON.parse(sessionStorage.getItem('myep-watchlist'))
|
||||||
|
this.watchlistValue = initialList ? initialList : []
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleWatchlist(e) {
|
||||||
|
const uid = e.detail
|
||||||
|
const currentList = this.watchlistValue
|
||||||
|
const listIndex = currentList.indexOf(uid)
|
||||||
|
if (-1 === listIndex) {
|
||||||
|
currentList.push(uid)
|
||||||
|
} else {
|
||||||
|
currentList.splice(listIndex, 1)
|
||||||
|
}
|
||||||
|
this.watchlistValue = currentList
|
||||||
|
sessionStorage.setItem('myep-watchlist', JSON.stringify(currentList))
|
||||||
|
}
|
||||||
|
|
||||||
|
watchlistValueChanged() {
|
||||||
|
this.watchlistTarget.style.display = this.watchlistValue.length > 0 ? 'block' : 'none'
|
||||||
|
this.watchlistLabelTarget.textContent = `Merkliste (${this.watchlistValue.length})`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-12
@@ -12,18 +12,9 @@ export default class extends Controller {
|
|||||||
|
|
||||||
toggle(e) {
|
toggle(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const list = this.getCurrentList()
|
this.onListValue = !this.onListValue
|
||||||
const listIndex = list.indexOf(this.uidValue)
|
window.dispatchEvent(new CustomEvent('watchlist-toggle', {
|
||||||
if (-1 === listIndex) {
|
detail: this.uidValue
|
||||||
list.push(this.uidValue)
|
|
||||||
this.onListValue = true
|
|
||||||
} else {
|
|
||||||
list.splice(listIndex, 1)
|
|
||||||
this.onListValue = false
|
|
||||||
}
|
|
||||||
sessionStorage.setItem('myep-watchlist', JSON.stringify(list))
|
|
||||||
window.dispatchEvent(new CustomEvent('watchlist-update', {
|
|
||||||
detail: list
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
|
{namespace v=FluidTYPO3\Vhs\ViewHelpers}
|
||||||
<div class="ep-contactnav" data-controller="contactbar" data-action="watchlist-update@window->contactbar#updateWatchlist">
|
<div class="ep-contactnav" data-controller="contactbar" data-action="watchlist-toggle@window->contactbar#toggleWatchlist">
|
||||||
<a href="{f:uri.typolink(parameter: settings.watchlistPageUid)}" class="bg-red watchlist"
|
<a href="{f:uri.typolink(parameter: settings.watchlistPageUid)}" class="bg-red watchlist"
|
||||||
data-contactbar-target="watchlist" rel="nofollow">
|
data-contactbar-target="watchlist" rel="nofollow">
|
||||||
<span class="fa fa-list" aria-hidden="true"></span>
|
<span class="fa fa-list" aria-hidden="true"></span>
|
||||||
<div>Merkliste ({{ $store.getters.watchlistCount }})</div>
|
<div data-contactbar-target="watchlistLabel"></div>
|
||||||
</a>
|
</a>
|
||||||
<a href="tel:{settings.phoneNumberLink}" class="bg-red phone" title="Telefonische Beratung" rel="nofollow">
|
<a href="tel:{settings.phoneNumberLink}" class="bg-red phone" title="Telefonische Beratung" rel="nofollow">
|
||||||
<span class="fa fa-phone" aria-hidden="true"></span>
|
<span class="fa fa-phone" aria-hidden="true"></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user