Skip to content

Commit

Permalink
Merge pull request #1486 from 1hitsong/fixHomeRefreshCrash
Browse files Browse the repository at this point in the history
  • Loading branch information
cewert authored Nov 11, 2023
2 parents 4e7937a + 02f6ec9 commit 06fe0b2
Showing 1 changed file with 41 additions and 9 deletions.
50 changes: 41 additions & 9 deletions components/home/HomeRows.bs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ sub removeHomeSection(sectionType as string)
end for

m.homeSectionIndexes.Delete(sectionName)
m.homeSectionIndexes.AddReplace("count", m.homeSectionIndexes.count - 1)

m.top.content.removeChildIndex(removedSectionIndex)
end sub
Expand Down Expand Up @@ -408,10 +407,12 @@ sub updateLatestInRows()
loadLatest.itemsToLoad = "latest"
loadLatest.itemId = lib.id

metadata = { "title": lib.name }
metadata.Append({ "contentType": lib.json.CollectionType })
loadLatest.metadata = metadata
metadata = {
"title": lib.name,
"contentType": lib.json.CollectionType
}

loadLatest.metadata = metadata
loadLatest.observeField("content", "updateLatestItems")
loadLatest.control = "RUN"
end if
Expand All @@ -429,8 +430,6 @@ sub updateLatestItems(msg)

sectionName = "latestin" + LCase(node.metadata.title).Replace(" ", "")

rowIndex = m.homeSectionIndexes[sectionName]

if itemData.count() < 1
removeHomeSection(sectionName)
return
Expand All @@ -457,9 +456,42 @@ sub updateLatestItems(msg)
row.appendChild(item)
end for

' replace the old row
updateSizeArray(itemSize, rowIndex, "replace")
m.top.content.replaceChild(row, rowIndex)
rowIndex = m.homeSectionIndexes[sectionName]

' Replace the old row
if isValid(rowIndex)
updateSizeArray(itemSize, rowIndex, "replace")
m.top.content.replaceChild(row, rowIndex)
return
end if

' Determine highest index of a Lastest In section so we can append the new section after it
highestLatestHomeSectionIndex = 0

for each section in m.homeSectionIndexes
if LCase(Left(section, 6)) = "latest"
if m.homeSectionIndexes[section] > highestLatestHomeSectionIndex
highestLatestHomeSectionIndex = m.homeSectionIndexes[section]
end if
end if
end for

' We have data for a section that doesn't currently exist
rowIndex = highestLatestHomeSectionIndex + 1

' Advance all the indexes greater than or equal than our new row
for each section in m.homeSectionIndexes
if m.homeSectionIndexes[section] >= rowIndex
m.homeSectionIndexes[section]++
end if
end for

m.homeSectionIndexes.AddReplace(sectionName, rowIndex)

m.top.content.insertChild(row, rowIndex)
updateSizeArray(itemSize, rowIndex)

return
end if
end sub

Expand Down

0 comments on commit 06fe0b2

Please sign in to comment.