chore(Widget): Add another mock follower in multi followers widget

This commit is contained in:
Marcus Kida 2023-02-06 13:51:58 +01:00
parent b5dca48cb2
commit c00e797996
No known key found for this signature in database
GPG Key ID: 19FF64E08013CA40
3 changed files with 20 additions and 8 deletions

View File

@ -52,7 +52,7 @@ struct LatestFollowersEntry: TimelineEntry {
static var unconfigured: Self { static var unconfigured: Self {
LatestFollowersEntry( LatestFollowersEntry(
date: .now, date: .now,
accounts: [], accounts: nil,
configuration: LatestFollowersIntent() configuration: LatestFollowersIntent()
) )
} }

View File

@ -23,14 +23,14 @@ struct MultiFollowersCountWidgetProvider: IntentTimelineProvider {
struct MultiFollowersCountEntry: TimelineEntry { struct MultiFollowersCountEntry: TimelineEntry {
let date: Date let date: Date
let accounts: [FollowersEntryAccountable]? let accounts: [MultiFollowersEntryAccountable]?
let configuration: MultiFollowersCountIntent let configuration: MultiFollowersCountIntent
static var placeholder: Self { static var placeholder: Self {
MultiFollowersCountEntry( MultiFollowersCountEntry(
date: .now, date: .now,
accounts: [ accounts: [
FollowersEntryAccount( MultiFollowersEntryAccount(
followersCount: 99_900, followersCount: 99_900,
displayNameWithFallback: "Mastodon", displayNameWithFallback: "Mastodon",
acct: "mastodon", acct: "mastodon",
@ -45,7 +45,7 @@ struct MultiFollowersCountEntry: TimelineEntry {
static var unconfigured: Self { static var unconfigured: Self {
MultiFollowersCountEntry( MultiFollowersCountEntry(
date: .now, date: .now,
accounts: [], accounts: nil,
configuration: MultiFollowersCountIntent() configuration: MultiFollowersCountIntent()
) )
} }
@ -93,7 +93,7 @@ private extension MultiFollowersCountWidgetProvider {
return completion(.unconfigured) return completion(.unconfigured)
} }
var accounts = [FollowersEntryAccountable]() var accounts = [MultiFollowersEntryAccountable]()
for desiredAccount in desiredAccounts { for desiredAccount in desiredAccounts {
let resultingAccount = try await WidgetExtension.appContext let resultingAccount = try await WidgetExtension.appContext
@ -105,12 +105,24 @@ private extension MultiFollowersCountWidgetProvider {
let imageData = try await URLSession.shared.data(from: resultingAccount.avatarImageURLWithFallback(domain: authBox.domain)).0 let imageData = try await URLSession.shared.data(from: resultingAccount.avatarImageURLWithFallback(domain: authBox.domain)).0
accounts.append(FollowersEntryAccount.from( accounts.append(MultiFollowersEntryAccount.from(
mastodonAccount: resultingAccount, mastodonAccount: resultingAccount,
domain: authBox.domain, domain: authBox.domain,
avatarImage: UIImage(data: imageData) ?? UIImage(named: "missingAvatar")! avatarImage: UIImage(data: imageData) ?? UIImage(named: "missingAvatar")!
)) ))
} }
if context.isPreview {
accounts.append(
MultiFollowersEntryAccount(
followersCount: 1_200,
displayNameWithFallback: "Another follower",
acct: "@another@follower.social",
avatarImage: UIImage(named: "missingAvatar")!,
domain: authBox.domain
)
)
}
let entry = MultiFollowersCountEntry( let entry = MultiFollowersCountEntry(
date: Date(), date: Date(),

View File

@ -28,7 +28,7 @@ struct MultiFollowersCountWidgetView: View {
} }
} }
private func viewForSmallWidget(_ accounts: [FollowersEntryAccountable]) -> some View { private func viewForSmallWidget(_ accounts: [MultiFollowersEntryAccountable]) -> some View {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
ForEach(accounts, id: \.acct) { account in ForEach(accounts, id: \.acct) { account in
HStack { HStack {
@ -59,7 +59,7 @@ struct MultiFollowersCountWidgetView: View {
.padding(.vertical, 16) .padding(.vertical, 16)
} }
private func viewForMediumWidget(_ accounts: [FollowersEntryAccountable]) -> some View { private func viewForMediumWidget(_ accounts: [MultiFollowersEntryAccountable]) -> some View {
VStack(alignment: .leading, spacing: 0) { VStack(alignment: .leading, spacing: 0) {
LazyVGrid(columns: [ LazyVGrid(columns: [
GridItem(.flexible()), GridItem(.flexible()),