Load filtered home activity streams
This commit is contained in:
@@ -4,4 +4,4 @@ module gotcha_core {
|
||||
use "Darwin"
|
||||
use "_Builtin_stdbool"
|
||||
use "_Builtin_stdint"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -615,7 +615,7 @@ public protocol GotchaCoreProtocol: AnyObject, Sendable {
|
||||
|
||||
func commits(owner: String, repository: String, branch: String?, path: String, pages: UInt32) async throws -> CommitPage
|
||||
|
||||
func home(page: UInt32) async throws -> HomePage
|
||||
func home(page: UInt32, filter: HomeActivityFilter) async throws -> HomePage
|
||||
|
||||
func issue(owner: String, repository: String, number: Int64, page: UInt32) async throws -> IssuePage
|
||||
|
||||
@@ -819,12 +819,12 @@ open func commits(owner: String, repository: String, branch: String?, path: Stri
|
||||
)
|
||||
}
|
||||
|
||||
open func home(page: UInt32)async throws -> HomePage {
|
||||
open func home(page: UInt32, filter: HomeActivityFilter)async throws -> HomePage {
|
||||
return
|
||||
try await uniffiRustCallAsync(
|
||||
rustFutureFunc: {
|
||||
uniffi_gotcha_core_fn_method_gotchacore_home(
|
||||
self.uniffiCloneHandle(),FfiConverterUInt32.lower(page)
|
||||
self.uniffiCloneHandle(),FfiConverterUInt32.lower(page),FfiConverterTypeHomeActivityFilter_lower(filter)
|
||||
)
|
||||
},
|
||||
pollFunc: ffi_gotcha_core_rust_future_poll_rust_buffer,
|
||||
@@ -1839,22 +1839,18 @@ public func FfiConverterTypeHeatCell_lower(_ value: HeatCell) -> RustBuffer {
|
||||
public struct HomePage: Equatable, Hashable {
|
||||
public var serverName: String
|
||||
public var activities: [ActivityRow]
|
||||
public var issueActivities: [ActivityRow]
|
||||
public var pullActivities: [ActivityRow]
|
||||
public var heatCells: [HeatCell]
|
||||
public var contributionCount: Int64
|
||||
public var hasMore: Bool
|
||||
public var nextPage: UInt32?
|
||||
|
||||
// Default memberwise initializers are never public by default, so we
|
||||
// declare one manually.
|
||||
public init(serverName: String, activities: [ActivityRow], issueActivities: [ActivityRow], pullActivities: [ActivityRow], heatCells: [HeatCell], contributionCount: Int64, hasMore: Bool) {
|
||||
public init(serverName: String, activities: [ActivityRow], heatCells: [HeatCell], contributionCount: Int64, nextPage: UInt32?) {
|
||||
self.serverName = serverName
|
||||
self.activities = activities
|
||||
self.issueActivities = issueActivities
|
||||
self.pullActivities = pullActivities
|
||||
self.heatCells = heatCells
|
||||
self.contributionCount = contributionCount
|
||||
self.hasMore = hasMore
|
||||
self.nextPage = nextPage
|
||||
}
|
||||
|
||||
|
||||
@@ -1875,22 +1871,18 @@ public struct FfiConverterTypeHomePage: FfiConverterRustBuffer {
|
||||
try HomePage(
|
||||
serverName: FfiConverterString.read(from: &buf),
|
||||
activities: FfiConverterSequenceTypeActivityRow.read(from: &buf),
|
||||
issueActivities: FfiConverterSequenceTypeActivityRow.read(from: &buf),
|
||||
pullActivities: FfiConverterSequenceTypeActivityRow.read(from: &buf),
|
||||
heatCells: FfiConverterSequenceTypeHeatCell.read(from: &buf),
|
||||
contributionCount: FfiConverterInt64.read(from: &buf),
|
||||
hasMore: FfiConverterBool.read(from: &buf)
|
||||
nextPage: FfiConverterOptionUInt32.read(from: &buf)
|
||||
)
|
||||
}
|
||||
|
||||
public static func write(_ value: HomePage, into buf: inout [UInt8]) {
|
||||
FfiConverterString.write(value.serverName, into: &buf)
|
||||
FfiConverterSequenceTypeActivityRow.write(value.activities, into: &buf)
|
||||
FfiConverterSequenceTypeActivityRow.write(value.issueActivities, into: &buf)
|
||||
FfiConverterSequenceTypeActivityRow.write(value.pullActivities, into: &buf)
|
||||
FfiConverterSequenceTypeHeatCell.write(value.heatCells, into: &buf)
|
||||
FfiConverterInt64.write(value.contributionCount, into: &buf)
|
||||
FfiConverterBool.write(value.hasMore, into: &buf)
|
||||
FfiConverterOptionUInt32.write(value.nextPage, into: &buf)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3352,6 +3344,79 @@ public func FfiConverterTypeGotchaError_lower(_ value: GotchaError) -> RustBuffe
|
||||
return FfiConverterTypeGotchaError.lower(value)
|
||||
}
|
||||
|
||||
|
||||
|
||||
public enum HomeActivityFilter: Equatable, Hashable {
|
||||
|
||||
case all
|
||||
case issues
|
||||
case pullRequests
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#if compiler(>=6)
|
||||
extension HomeActivityFilter: Sendable {}
|
||||
#endif
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public struct FfiConverterTypeHomeActivityFilter: FfiConverterRustBuffer {
|
||||
typealias SwiftType = HomeActivityFilter
|
||||
|
||||
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> HomeActivityFilter {
|
||||
let variant: Int32 = try readInt(&buf)
|
||||
switch variant {
|
||||
|
||||
case 1: return .all
|
||||
|
||||
case 2: return .issues
|
||||
|
||||
case 3: return .pullRequests
|
||||
|
||||
default: throw UniffiInternalError.unexpectedEnumCase
|
||||
}
|
||||
}
|
||||
|
||||
public static func write(_ value: HomeActivityFilter, into buf: inout [UInt8]) {
|
||||
switch value {
|
||||
|
||||
|
||||
case .all:
|
||||
writeInt(&buf, Int32(1))
|
||||
|
||||
|
||||
case .issues:
|
||||
writeInt(&buf, Int32(2))
|
||||
|
||||
|
||||
case .pullRequests:
|
||||
writeInt(&buf, Int32(3))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeHomeActivityFilter_lift(_ buf: RustBuffer) throws -> HomeActivityFilter {
|
||||
return try FfiConverterTypeHomeActivityFilter.lift(buf)
|
||||
}
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
public func FfiConverterTypeHomeActivityFilter_lower(_ value: HomeActivityFilter) -> RustBuffer {
|
||||
return FfiConverterTypeHomeActivityFilter.lower(value)
|
||||
}
|
||||
|
||||
|
||||
#if swift(>=5.8)
|
||||
@_documentation(visibility: private)
|
||||
#endif
|
||||
@@ -3955,7 +4020,7 @@ private let initializationResult: InitializationResult = {
|
||||
if (uniffi_gotcha_core_checksum_method_gotchacore_commits() != 60062) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_gotcha_core_checksum_method_gotchacore_home() != 38990) {
|
||||
if (uniffi_gotcha_core_checksum_method_gotchacore_home() != 2797) {
|
||||
return InitializationResult.apiChecksumMismatch
|
||||
}
|
||||
if (uniffi_gotcha_core_checksum_method_gotchacore_issue() != 3108) {
|
||||
@@ -4065,4 +4130,4 @@ public func uniffiEnsureGotchaCoreInitialized() {
|
||||
}
|
||||
}
|
||||
|
||||
// swiftlint:enable all
|
||||
// swiftlint:enable all
|
||||
@@ -291,7 +291,7 @@ uint64_t uniffi_gotcha_core_fn_method_gotchacore_commits(uint64_t ptr, RustBuffe
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_HOME
|
||||
#define UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_HOME
|
||||
uint64_t uniffi_gotcha_core_fn_method_gotchacore_home(uint64_t ptr, uint32_t page
|
||||
uint64_t uniffi_gotcha_core_fn_method_gotchacore_home(uint64_t ptr, uint32_t page, RustBuffer filter
|
||||
);
|
||||
#endif
|
||||
#ifndef UNIFFI_FFIDEF_UNIFFI_GOTCHA_CORE_FN_METHOD_GOTCHACORE_ISSUE
|
||||
|
||||
@@ -321,21 +321,21 @@ final class HomeViewController: RefreshingTableViewController {
|
||||
case all
|
||||
case issues
|
||||
case pulls
|
||||
|
||||
var coreValue: HomeActivityFilter {
|
||||
switch self {
|
||||
case .all: return .all
|
||||
case .issues: return .issues
|
||||
case .pulls: return .pullRequests
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private let context: AppContext
|
||||
private var page: HomePage?
|
||||
private var filter = ActivityFilter.all
|
||||
private var currentPage: UInt32 = 0
|
||||
|
||||
private var activities: [ActivityRow] {
|
||||
guard let page else { return [] }
|
||||
switch filter {
|
||||
case .all: return page.activities
|
||||
case .issues: return page.issueActivities
|
||||
case .pulls: return page.pullActivities
|
||||
}
|
||||
}
|
||||
private var nextPage: UInt32?
|
||||
private var activities: [ActivityRow] { page?.activities ?? [] }
|
||||
|
||||
init(context: AppContext) {
|
||||
self.context = context
|
||||
@@ -381,7 +381,8 @@ final class HomeViewController: RefreshingTableViewController {
|
||||
}
|
||||
|
||||
override func loadMoreContent() {
|
||||
loadPage(currentPage + 1, refreshing: false)
|
||||
guard let nextPage else { return }
|
||||
loadPage(nextPage, refreshing: false)
|
||||
}
|
||||
|
||||
private func loadPage(_ requestedPage: UInt32, refreshing: Bool) {
|
||||
@@ -392,23 +393,25 @@ final class HomeViewController: RefreshingTableViewController {
|
||||
loadingTask?.cancel()
|
||||
loadingTask = Task {
|
||||
do {
|
||||
let result = try await context.core.home(page: requestedPage)
|
||||
let result = try await context.core.home(
|
||||
page: requestedPage,
|
||||
filter: filter.coreValue
|
||||
)
|
||||
if requestedPage == 1 {
|
||||
page = result
|
||||
} else {
|
||||
page?.activities.append(contentsOf: result.activities)
|
||||
page?.issueActivities.append(contentsOf: result.issueActivities)
|
||||
page?.pullActivities.append(contentsOf: result.pullActivities)
|
||||
page?.hasMore = result.hasMore
|
||||
page?.nextPage = result.nextPage
|
||||
}
|
||||
currentPage = requestedPage
|
||||
finishPagination(hasMore: result.hasMore)
|
||||
nextPage = result.nextPage
|
||||
finishPagination(hasMore: result.nextPage != nil)
|
||||
title = page?.serverName
|
||||
if requestedPage == 1 { tableView.tableHeaderView = page.map { page in
|
||||
HeatmapView(page: page, selectedFilter: filter.rawValue) { [weak self] index in
|
||||
guard let self, let filter = ActivityFilter(rawValue: index) else { return }
|
||||
guard filter != self.filter else { return }
|
||||
self.filter = filter
|
||||
self.updateActivities()
|
||||
self.loadPage(1, refreshing: false)
|
||||
}
|
||||
} }
|
||||
updateActivities()
|
||||
|
||||
Reference in New Issue
Block a user