From 7328c00006c121bcc17608eba852de99ac152767 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sun, 5 May 2024 19:41:04 +0200 Subject: [PATCH] Widget: Remove optional parameters --- .../HashtagPostsWidget/HashtagPostsWidget.swift | 14 ++++---------- .../HashtagPostsWidgetConfiguration.swift | 4 ++-- .../LatestPosts/LatestPostsWidget.swift | 16 ++++------------ .../LatestPostsWidgetConfiguration.swift | 4 ++-- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidget.swift b/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidget.swift index 2c8a33e5..7144d5be 100644 --- a/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidget.swift +++ b/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidget.swift @@ -28,20 +28,14 @@ struct HashtagPostsWidgetProvider: AppIntentTimelineProvider { } private func timeline(for configuration: HashtagPostsWidgetConfiguration, context: Context) async -> Timeline { - guard let account = configuration.account, let hashgtag = configuration.hashgtag else { - return Timeline(entries: [.init(date: Date(), - timeline: .hashtag(tag: "Mastodon", accountId: nil), - statuses: [], - images: [:])], - policy: .atEnd) - } do { - let statuses = await loadStatuses(for: .hashtag(tag: hashgtag, accountId: nil), - account: account, + let statuses = await loadStatuses(for: .hashtag(tag: configuration.hashgtag, accountId: nil), + account: configuration.account, widgetFamily: context.family) let images = try await loadImages(urls: statuses.map{ $0.account.avatar } ) return Timeline(entries: [.init(date: Date(), - timeline: .hashtag(tag: hashgtag, accountId: nil), + timeline: .hashtag(tag: configuration.hashgtag, + accountId: nil), statuses: statuses, images: images)], policy: .atEnd) } catch { diff --git a/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidgetConfiguration.swift b/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidgetConfiguration.swift index 71804530..d638eb39 100644 --- a/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidgetConfiguration.swift +++ b/IceCubesAppWidgetsExtension/HashtagPostsWidget/HashtagPostsWidgetConfiguration.swift @@ -6,10 +6,10 @@ struct HashtagPostsWidgetConfiguration: WidgetConfigurationIntent { static let description = IntentDescription("Choose the account and hashtag for this widget") @Parameter(title: "Account") - var account: AppAccountEntity? + var account: AppAccountEntity @Parameter(title: "Hashtag") - var hashgtag: String? + var hashgtag: String } extension HashtagPostsWidgetConfiguration { diff --git a/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidget.swift b/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidget.swift index 526ee947..20181a7f 100644 --- a/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidget.swift +++ b/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidget.swift @@ -27,21 +27,13 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider { } private func timeline(for configuration: LatestPostsWidgetConfiguration, context: Context) async -> Timeline { - guard let account = configuration.account, let timeline = configuration.timeline else { - return Timeline(entries: [.init(date: Date(), - timeline: .home, - statuses: [], - images: [:])], - policy: .atEnd) - } - do { - let statuses = await loadStatuses(for: timeline.timeline, - account: account, - widgetFamily: context.family) + let statuses = await loadStatuses(for: configuration.timeline.timeline, + account: configuration.account, + widgetFamily: context.family) let images = try await loadImages(urls: statuses.map{ $0.account.avatar } ) return Timeline(entries: [.init(date: Date(), - timeline: timeline.timeline, + timeline: configuration.timeline.timeline, statuses: statuses, images: images)], policy: .atEnd) } catch { diff --git a/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidgetConfiguration.swift b/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidgetConfiguration.swift index ac6c3818..b92cbb81 100644 --- a/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidgetConfiguration.swift +++ b/IceCubesAppWidgetsExtension/LatestPosts/LatestPostsWidgetConfiguration.swift @@ -6,10 +6,10 @@ struct LatestPostsWidgetConfiguration: WidgetConfigurationIntent { static let description = IntentDescription("Choose the account and timeline for this widget") @Parameter(title: "Account") - var account: AppAccountEntity? + var account: AppAccountEntity @Parameter(title: "Timeline") - var timeline: TimelineFilterEntity? + var timeline: TimelineFilterEntity } extension LatestPostsWidgetConfiguration {