Skip to content

Commit

Permalink
fix searching source library, fix reloading updates when visiting page
Browse files Browse the repository at this point in the history
  • Loading branch information
mgn-norm committed Nov 21, 2022
1 parent 9dd9429 commit 6b79991
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/models/SourcesLibraryModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ SourcesLibraryModel::SourcesLibraryModel(QObject* parent)
receiveReply = [&](const QJsonDocument& reply) {
const auto& mangaList = reply["mangaList"].toArray();

if (resetModel) {
if (_resetModel) {
beginResetModel();
_sources.clear();
} else {
beginInsertRows({}, _sources.size(), _sources.size() + mangaList.count() - 1);
}

_hasNextPage = reply["hasNextPage"].toBool();
qDebug() << "has next page?" << _hasNextPage;

for (const auto& entry_arr : mangaList) {
const auto& entry = entry_arr.toObject();
Expand All @@ -42,8 +44,8 @@ SourcesLibraryModel::SourcesLibraryModel(QObject* parent)
}
}

if (resetModel) {
resetModel = false;
if (_resetModel) {
_resetModel = false;
endResetModel();
} else {
endInsertRows();
Expand Down Expand Up @@ -153,8 +155,13 @@ QHash<int, QByteArray> SourcesLibraryModel::roleNames() const {
*****************************************************************************/
void SourcesLibraryModel::search(const QString& searchTerm)
{
resetModel = true;
NetworkManager::instance().get(QUrl(u"source/"_qs % _source % "/search/" % searchTerm), this, receiveReply);
beginResetModel();
_resetModel = true;
_hasNextPage = false;
_sources.clear();
endResetModel();

NetworkManager::instance().get(QUrl(u"source/"_qs % _source % "/search?searchTerm=" % QUrl::toPercentEncoding(searchTerm)), this, receiveReply);
}

/******************************************************************************
Expand All @@ -164,7 +171,9 @@ void SourcesLibraryModel::search(const QString& searchTerm)
*****************************************************************************/
void SourcesLibraryModel::next()
{
NetworkManager::instance().get(QStringLiteral("source/%1/latest/%2").arg(_source).arg(++_pageNumber));
if (!_hasNextPage) {
return;
}
NetworkManager::instance().get(QUrl(u"source/"_qs % _source % "/latest/" % QString::number(++_pageNumber)), this, receiveReply);

}
3 changes: 2 additions & 1 deletion src/models/SourcesLibraryModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class SourcesLibraryModel : public QAbstractListModel, public QQmlParserStatus
QString _source;
qint32 _pageNumber = 0;

bool resetModel = true;
bool _hasNextPage = true;
bool _resetModel = true;

protected:

Expand Down
1 change: 0 additions & 1 deletion src/models/SourcesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ void SourcesModel::componentComplete()
*****************************************************************************/
void SourcesModel::refresh()
{
qDebug() << "queury sources";
NetworkManager::instance().get(QUrl("source/list"), this,
[&](const auto& reply)
{
Expand Down
14 changes: 14 additions & 0 deletions src/models/UpdatesModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ QHash<int, QByteArray> UpdatesModel::roleNames() const {
return roles;
}

/******************************************************************************
*
* Method: pageRefresh()
*
*****************************************************************************/
void UpdatesModel::pageRefresh()
{
_pageNumber = 0;
_hasNext = false;
_sources.clear();
beginResetModel();
next();
endResetModel();
}
/******************************************************************************
*
* Method: next()
Expand Down
1 change: 1 addition & 0 deletions src/models/UpdatesModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class UpdatesModel : public QAbstractListModel, public QQmlParserStatus
int role = Qt::DisplayRole) const override;

Q_INVOKABLE void next();
Q_INVOKABLE void pageRefresh();
Q_INVOKABLE void refresh();
Q_INVOKABLE void downloadChapter(int index);
Q_INVOKABLE void chapterRead(qint32 mangaId, quint32 chapter);
Expand Down
2 changes: 1 addition & 1 deletion src/qml/LibraryBase.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Rectangle {
listviewLoaded = true
}
onAtYEndChanged: {
if (!listviewLoaded) {
if (!listviewLoaded || !flicking) {
return
}
reachedEnd()
Expand Down
3 changes: 2 additions & 1 deletion src/qml/Updates.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Rectangle {
}

function refresh() {
// idk is this even needed? ... need proper refresh for getting new chapters
// idk is this even needed? ... need proper refresh for getting new chapters and badges
console.log("updates refresh")
updatesModel.pageRefresh()
}

function markRead(mangaId, chapter) {
Expand Down

0 comments on commit 6b79991

Please sign in to comment.