Load more WIP

This commit is contained in:
Justin Mazzocchi 2020-10-02 00:41:30 -07:00
parent 4199ad96bf
commit 33f026f9cc
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
7 changed files with 32 additions and 8 deletions

View file

@ -42,13 +42,23 @@ public extension ContentDatabase {
func insert(statuses: [Status], timeline: Timeline) -> AnyPublisher<Never, Error> { func insert(statuses: [Status], timeline: Timeline) -> AnyPublisher<Never, Error> {
databaseWriter.writePublisher { databaseWriter.writePublisher {
try timeline.save($0) let timelineRecord = TimelineRecord(timeline: timeline)
try timelineRecord.save($0)
let maxIDPresent = try String.fetchOne($0, timelineRecord.statuses.select(max(StatusRecord.Columns.id)))
for status in statuses { for status in statuses {
try status.save($0) try status.save($0)
try TimelineStatusJoin(timelineId: timeline.id, statusId: status.id).save($0) try TimelineStatusJoin(timelineId: timeline.id, statusId: status.id).save($0)
} }
if let maxIDPresent = maxIDPresent,
let minIDInserted = statuses.map(\.id).min(),
minIDInserted > maxIDPresent {
try LoadMore(timelineId: timeline.id, afterStatusId: minIDInserted).save($0)
}
} }
.ignoreOutput() .ignoreOutput()
.eraseToAnyPublisher() .eraseToAnyPublisher()
@ -117,7 +127,7 @@ public extension ContentDatabase {
func setLists(_ lists: [List]) -> AnyPublisher<Never, Error> { func setLists(_ lists: [List]) -> AnyPublisher<Never, Error> {
databaseWriter.writePublisher { databaseWriter.writePublisher {
for list in lists { for list in lists {
try Timeline.list(list).save($0) try TimelineRecord(timeline: Timeline.list(list)).save($0)
} }
try TimelineRecord try TimelineRecord
@ -130,7 +140,7 @@ public extension ContentDatabase {
} }
func createList(_ list: List) -> AnyPublisher<Never, Error> { func createList(_ list: List) -> AnyPublisher<Never, Error> {
databaseWriter.writePublisher(updates: Timeline.list(list).save) databaseWriter.writePublisher(updates: TimelineRecord(timeline: Timeline.list(list)).save)
.ignoreOutput() .ignoreOutput()
.eraseToAnyPublisher() .eraseToAnyPublisher()
} }
@ -191,7 +201,7 @@ public extension ContentDatabase {
guard let index = timelineItems.firstIndex(where: { guard let index = timelineItems.firstIndex(where: {
guard case let .status(configuration) = $0 else { return false } guard case let .status(configuration) = $0 else { return false }
return loadMore.afterStatusId < configuration.status.id return loadMore.afterStatusId > configuration.status.id
}) else { continue } }) else { continue }
timelineItems.insert(.loadMore(loadMore), at: index) timelineItems.insert(.loadMore(loadMore), at: index)

View file

@ -5,10 +5,6 @@ import GRDB
import Mastodon import Mastodon
extension Timeline { extension Timeline {
func save(_ db: Database) throws {
try TimelineRecord(timeline: self).save(db)
}
init?(record: TimelineRecord) { init?(record: TimelineRecord) {
switch (record.id, switch (record.id,
record.listId, record.listId,

View file

@ -28,6 +28,7 @@
"identities.browsing" = "Browsing"; "identities.browsing" = "Browsing";
"identities.pending" = "Pending"; "identities.pending" = "Pending";
"lists.new-list-title" = "New List Title"; "lists.new-list-title" = "New List Title";
"load-more" = "Load More";
"pending.pending-confirmation" = "Your account is pending confirmation"; "pending.pending-confirmation" = "Your account is pending confirmation";
"preferences" = "Preferences"; "preferences" = "Preferences";
"preferences.posting-reading" = "Posting and Reading"; "preferences.posting-reading" = "Posting and Reading";

View file

@ -27,6 +27,12 @@ class TableViewController: UITableViewController {
statusListCell.viewModel = statusViewModel statusListCell.viewModel = statusViewModel
case (let accountListCell as AccountListCell, let accountViewModel as AccountViewModel): case (let accountListCell as AccountListCell, let accountViewModel as AccountViewModel):
accountListCell.viewModel = accountViewModel accountListCell.viewModel = accountViewModel
case (let loadMoreCell as LoadMoreCell, let loadMoreViewModel as LoadMoreViewModel):
var contentConfiguration = loadMoreCell.defaultContentConfiguration()
contentConfiguration.text = NSLocalizedString("load-more", comment: "")
loadMoreCell.contentConfiguration = contentConfiguration
default: default:
return nil return nil
} }

View file

@ -0,0 +1,5 @@
// Copyright © 2020 Metabolist. All rights reserved.
public struct LoadMoreViewModel {
}

View file

@ -85,6 +85,8 @@ extension StatusListViewModel: CollectionViewModel {
switch item.kind { switch item.kind {
case .status: case .status:
return statusViewModel(item: item) return statusViewModel(item: item)
case .loadMore:
return LoadMoreViewModel()
default: default:
return nil return nil
} }

View file

@ -3,5 +3,9 @@
import UIKit import UIKit
class LoadMoreCell: UITableViewCell { class LoadMoreCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
separatorInset.left = UIDevice.current.userInterfaceIdiom == .phone ? 0 : layoutMargins.left
}
} }