feat(Widget): Implement small latest followers widget
This commit is contained in:
parent
d685b9e365
commit
3240a36013
|
@ -13,9 +13,6 @@ struct FollowersCountWidgetProvider: IntentTimelineProvider {
|
|||
}
|
||||
|
||||
func getSnapshot(for configuration: FollowersCountIntent, in context: Context, completion: @escaping (FollowersCountEntry) -> ()) {
|
||||
guard !context.isPreview else {
|
||||
return completion(.placeholder)
|
||||
}
|
||||
loadCurrentEntry(for: configuration, in: context, completion: completion)
|
||||
}
|
||||
|
||||
|
@ -81,6 +78,9 @@ private extension FollowersCountWidgetProvider {
|
|||
.mastodonAuthenticationBoxes
|
||||
.first
|
||||
else {
|
||||
guard !context.isPreview else {
|
||||
return completion(.placeholder)
|
||||
}
|
||||
return completion(.unconfigured)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,6 @@ struct LatestFollowersWidgetProvider: IntentTimelineProvider {
|
|||
}
|
||||
|
||||
func getSnapshot(for configuration: LatestFollowersIntent, in context: Context, completion: @escaping (LatestFollowersEntry) -> ()) {
|
||||
guard !context.isPreview else {
|
||||
return completion(.placeholder)
|
||||
}
|
||||
loadCurrentEntry(for: configuration, in: context, completion: completion)
|
||||
}
|
||||
|
||||
|
@ -85,19 +82,12 @@ private extension LatestFollowersWidgetProvider {
|
|||
.mastodonAuthenticationBoxes
|
||||
.first
|
||||
else {
|
||||
guard !context.isPreview else {
|
||||
return completion(.placeholder)
|
||||
}
|
||||
return completion(.unconfigured)
|
||||
}
|
||||
|
||||
// guard let desiredAccount: String = {
|
||||
// guard let account = authBox.authenticationRecord.object(in: WidgetExtension.appContext.managedObjectContext)?.user.acct else {
|
||||
// return nil
|
||||
// }
|
||||
// return account
|
||||
// }() else {
|
||||
// return completion(.unconfigured)
|
||||
// }
|
||||
|
||||
|
||||
|
||||
var accounts = [LatestFollowersEntryAccountable]()
|
||||
|
||||
let followers = try await WidgetExtension.appContext
|
||||
|
@ -127,23 +117,6 @@ private extension LatestFollowersWidgetProvider {
|
|||
)
|
||||
|
||||
completion(entry)
|
||||
|
||||
// for desiredAccount in desiredAccounts {
|
||||
// let resultingAccount = try await WidgetExtension.appContext
|
||||
// .apiService
|
||||
// .search(query: .init(q: desiredAccount, type: .accounts), authenticationBox: authBox)
|
||||
// .value
|
||||
// .accounts
|
||||
// .first!
|
||||
//
|
||||
// let imageData = try await URLSession.shared.data(from: resultingAccount.avatarImageURLWithFallback(domain: authBox.domain)).0
|
||||
//
|
||||
// accounts.append(FollowersEntryAccount.from(
|
||||
// mastodonAccount: resultingAccount,
|
||||
// domain: authBox.domain,
|
||||
// avatarImage: UIImage(data: imageData) ?? UIImage(named: "missingAvatar")!
|
||||
// ))
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,10 @@ struct LatestFollowersWidgetView: View {
|
|||
}
|
||||
|
||||
private func viewForSmallWidget(_ accounts: [LatestFollowersEntryAccountable], lastUpdate: Date) -> some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Latest followers")
|
||||
.font(.system(size: UIFontMetrics.default.scaledValue(for: 16)))
|
||||
|
||||
ForEach(accounts, id: \.acct) { account in
|
||||
HStack {
|
||||
if let avatarImage = account.avatarImage {
|
||||
|
@ -47,23 +50,29 @@ struct LatestFollowersWidgetView: View {
|
|||
.cornerRadius(5)
|
||||
}
|
||||
VStack(alignment: .leading) {
|
||||
Text(account.note)
|
||||
.font(.caption)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
|
||||
Text("@\(account.acct)")
|
||||
.font(.caption2)
|
||||
.foregroundColor(.secondary)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
Text(account.displayNameWithFallback)
|
||||
.font(.footnote.bold())
|
||||
.foregroundColor(.secondary)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
|
||||
Text("@\(account.acct)")
|
||||
.font(.caption2)
|
||||
.foregroundColor(.secondary)
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.padding(.leading, 20)
|
||||
}
|
||||
Spacer()
|
||||
Text("Last update: \(dateFormatter.string(from: lastUpdate))")
|
||||
.font(.caption2)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
.padding(.horizontal, 20)
|
||||
.padding(.vertical, 16)
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,6 @@ struct MultiFollowersCountWidgetProvider: IntentTimelineProvider {
|
|||
}
|
||||
|
||||
func getSnapshot(for configuration: MultiFollowersCountIntent, in context: Context, completion: @escaping (MultiFollowersCountEntry) -> ()) {
|
||||
guard !context.isPreview else {
|
||||
return completion(.placeholder)
|
||||
}
|
||||
loadCurrentEntry(for: configuration, in: context, completion: completion)
|
||||
}
|
||||
|
||||
|
@ -78,6 +75,9 @@ private extension MultiFollowersCountWidgetProvider {
|
|||
.mastodonAuthenticationBoxes
|
||||
.first
|
||||
else {
|
||||
guard !context.isPreview else {
|
||||
return completion(.placeholder)
|
||||
}
|
||||
return completion(.unconfigured)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue