Fix empty results errors

This commit is contained in:
Syer10
2023-04-07 00:02:00 -04:00
parent 671466a737
commit 0b88207ad5
11 changed files with 197 additions and 81 deletions

View File

@@ -259,15 +259,29 @@ class MangaQuery {
return MangaNodeList(
resultsAsType,
MangaNodeList.MangaEdges(
cursor = getAsCursor(orderBy, resultsAsType.last()),
node = resultsAsType.last()
),
if (resultsAsType.isEmpty()) {
emptyList()
} else {
listOf(
resultsAsType.first().let {
MangaNodeList.MangaEdge(
getAsCursor(orderBy, it),
it
)
},
resultsAsType.last().let {
MangaNodeList.MangaEdge(
getAsCursor(orderBy, it),
it
)
}
)
},
pageInfo = PageInfo(
hasNextPage = queryResults.lastKey != resultsAsType.last().id,
hasPreviousPage = queryResults.firstKey != resultsAsType.first().id,
startCursor = getAsCursor(orderBy, resultsAsType.first()),
endCursor = getAsCursor(orderBy, resultsAsType.last())
startCursor = resultsAsType.firstOrNull()?.let { getAsCursor(orderBy, it) },
endCursor = resultsAsType.lastOrNull()?.let { getAsCursor(orderBy, it) }
),
totalCount = queryResults.total.toInt()
)