Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mithril DOMException when reordering gamecards #2396

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/announce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ export async function set(a?: Announcement): Promise<void> {
return
}
}
announce = a
redraw()
if (announce !== a) {
announce = a
redraw()
}
}

export async function dismiss(): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gamesMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,5 @@ function renderAllGames() {
return h('div.games_carousel', {
oncreate: wrapperOnCreate,
onremove: wrapperOnRemove,
}, allCards)
}, helper.isPortrait() ? h('div', allCards.map(card => h('div', card))) : allCards)
}
36 changes: 11 additions & 25 deletions src/ui/helper/Siema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class Siema {
// Resolve selector's type
this.selector = typeof this.config.selector === 'string' ? document.querySelector(this.config.selector) : this.config.selector

// Early throw if selector doesn't exists
if (this.selector === null) {
// Early throw if selector or sliderframe don't exist
if (this.selector === null || this.selector.firstElementChild === null) {
throw new Error('Something wrong with your selector ??')
}

Expand All @@ -24,7 +24,7 @@ export default class Siema {

// Create global references
this.selectorWidth = this.selector.offsetWidth
this.innerElements = [].slice.call(this.selector.children)
this.innerElements = [].slice.call(this.selector.firstElementChild.children)
this.currentSlide =
Math.max(0, Math.min(this.config.startIndex, this.innerElements.length - this.perPage))
this.transformProperty = 'transform';
Expand Down Expand Up @@ -134,36 +134,22 @@ export default class Siema {
const widthItem = this.selectorWidth / this.perPage
const itemsToBuild = this.innerElements.length

// Create frame and apply styling
this.sliderFrame = document.createElement('div')
// Get frame and apply styling
this.sliderFrame = this.selector.firstElementChild
this.sliderFrame.style.width = `${widthItem * itemsToBuild}px`

// Create a document fragment to put slides into it
const docFragment = document.createDocumentFragment()

for (let i = 0; i < this.innerElements.length; i++) {
const element = this.buildSliderFrameItem(this.innerElements[i])
docFragment.appendChild(element)
this.buildSliderFrameItem(this.innerElements[i])
}

// Add fragment to the frame
this.sliderFrame.appendChild(docFragment)

// Clear selector (just in case something is there) and insert a frame
this.selector.innerHTML = ''
this.selector.appendChild(this.sliderFrame)

// Go to currently active slide after initial build
this.slideToCurrent()
}

buildSliderFrameItem(elm) {
const elementContainer = document.createElement('div')
buildSliderFrameItem(elementContainer) {
elementContainer.style.cssFloat = this.config.rtl ? 'right' : 'left'
elementContainer.style.float = this.config.rtl ? 'right' : 'left'
elementContainer.style.width = `${100 / (this.innerElements.length)}%`
elementContainer.appendChild(elm)
return elementContainer
}


Expand Down Expand Up @@ -463,12 +449,12 @@ export default class Siema {
this.selector.style.cursor = 'auto'

if (restoreMarkup) {
const slides = document.createDocumentFragment()
for (let i = 0; i < this.innerElements.length; i++) {
slides.appendChild(this.innerElements[i])
this.innerElements[i].removeAttribute('style')
}
if (this.sliderFrame) {
this.sliderFrame.removeAttribute('style')
}
this.selector.innerHTML = ''
this.selector.appendChild(slides)
this.selector.removeAttribute('style')
}

Expand Down