From a44a61b017695c5de021df3442581315b1c9dcba Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Wed, 8 Dec 2021 00:06:59 +0100 Subject: [PATCH] Remove redundant query for replies when collapsed and expanded --- Model/CommentsModel.swift | 6 ++++++ Shared/Player/CommentView.swift | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Model/CommentsModel.swift b/Model/CommentsModel.swift index 67bc1d0a..23922a9b 100644 --- a/Model/CommentsModel.swift +++ b/Model/CommentsModel.swift @@ -12,6 +12,7 @@ final class CommentsModel: ObservableObject { @Published var disabled = false @Published var replies = [Comment]() + @Published var repliesPageID: String? @Published var repliesLoaded = false var accounts: AccountsModel! @@ -77,7 +78,12 @@ final class CommentsModel: ObservableObject { return } + if page == repliesPageID { + return + } + replies = [] + repliesPageID = page repliesLoaded = false api?.comments(player.currentVideo!.videoID, page: page)? diff --git a/Shared/Player/CommentView.swift b/Shared/Player/CommentView.swift index 13e159f8..377e9539 100644 --- a/Shared/Player/CommentView.swift +++ b/Shared/Player/CommentView.swift @@ -144,10 +144,6 @@ struct CommentView: View { Button { repliesID = repliesID == comment.id ? nil : comment.id - if repliesID.isNil { - comments.replies = [] - } - guard !repliesID.isNil, !comment.repliesPage.isNil else { return }