mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-25 09:41:00 +00:00
Load more WIP
This commit is contained in:
parent
4199ad96bf
commit
33f026f9cc
7 changed files with 32 additions and 8 deletions
|
@ -42,13 +42,23 @@ public extension ContentDatabase {
|
|||
|
||||
func insert(statuses: [Status], timeline: Timeline) -> AnyPublisher<Never, Error> {
|
||||
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 {
|
||||
try status.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()
|
||||
.eraseToAnyPublisher()
|
||||
|
@ -117,7 +127,7 @@ public extension ContentDatabase {
|
|||
func setLists(_ lists: [List]) -> AnyPublisher<Never, Error> {
|
||||
databaseWriter.writePublisher {
|
||||
for list in lists {
|
||||
try Timeline.list(list).save($0)
|
||||
try TimelineRecord(timeline: Timeline.list(list)).save($0)
|
||||
}
|
||||
|
||||
try TimelineRecord
|
||||
|
@ -130,7 +140,7 @@ public extension ContentDatabase {
|
|||
}
|
||||
|
||||
func createList(_ list: List) -> AnyPublisher<Never, Error> {
|
||||
databaseWriter.writePublisher(updates: Timeline.list(list).save)
|
||||
databaseWriter.writePublisher(updates: TimelineRecord(timeline: Timeline.list(list)).save)
|
||||
.ignoreOutput()
|
||||
.eraseToAnyPublisher()
|
||||
}
|
||||
|
@ -191,7 +201,7 @@ public extension ContentDatabase {
|
|||
guard let index = timelineItems.firstIndex(where: {
|
||||
guard case let .status(configuration) = $0 else { return false }
|
||||
|
||||
return loadMore.afterStatusId < configuration.status.id
|
||||
return loadMore.afterStatusId > configuration.status.id
|
||||
}) else { continue }
|
||||
|
||||
timelineItems.insert(.loadMore(loadMore), at: index)
|
||||
|
|
|
@ -5,10 +5,6 @@ import GRDB
|
|||
import Mastodon
|
||||
|
||||
extension Timeline {
|
||||
func save(_ db: Database) throws {
|
||||
try TimelineRecord(timeline: self).save(db)
|
||||
}
|
||||
|
||||
init?(record: TimelineRecord) {
|
||||
switch (record.id,
|
||||
record.listId,
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
"identities.browsing" = "Browsing";
|
||||
"identities.pending" = "Pending";
|
||||
"lists.new-list-title" = "New List Title";
|
||||
"load-more" = "Load More";
|
||||
"pending.pending-confirmation" = "Your account is pending confirmation";
|
||||
"preferences" = "Preferences";
|
||||
"preferences.posting-reading" = "Posting and Reading";
|
||||
|
|
|
@ -27,6 +27,12 @@ class TableViewController: UITableViewController {
|
|||
statusListCell.viewModel = statusViewModel
|
||||
case (let accountListCell as AccountListCell, let accountViewModel as 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:
|
||||
return nil
|
||||
}
|
||||
|
|
5
ViewModels/Sources/ViewModels/LoadMoreViewModel.swift
Normal file
5
ViewModels/Sources/ViewModels/LoadMoreViewModel.swift
Normal file
|
@ -0,0 +1,5 @@
|
|||
// Copyright © 2020 Metabolist. All rights reserved.
|
||||
|
||||
public struct LoadMoreViewModel {
|
||||
|
||||
}
|
|
@ -85,6 +85,8 @@ extension StatusListViewModel: CollectionViewModel {
|
|||
switch item.kind {
|
||||
case .status:
|
||||
return statusViewModel(item: item)
|
||||
case .loadMore:
|
||||
return LoadMoreViewModel()
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -3,5 +3,9 @@
|
|||
import UIKit
|
||||
|
||||
class LoadMoreCell: UITableViewCell {
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
|
||||
separatorInset.left = UIDevice.current.userInterfaceIdiom == .phone ? 0 : layoutMargins.left
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue