From 8c8c55168686e29b88da6c95a2cc5e1b2c655ab0 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sat, 6 Jan 2024 11:21:07 +0100 Subject: [PATCH] Fix warnings + better recently used tags --- .../App/Tabs/Settings/RecenTagsSettingView.swift | 9 ++++++++- .../AccountsList/AccountsListViewModel.swift | 4 ++-- .../Account/Edit/EditAccountViewModel.swift | 4 ++-- .../DesignSystem/Views/AccountPopoverView.swift | 2 +- .../Sources/DesignSystem/Views/AvatarView.swift | 2 +- .../MediaUI/MediaUITransferableImage.swift | 6 +++--- .../Sources/Models/SwiftData/RecentTag.swift | 6 ++++++ .../Components/AutoComplete/ExpandedView.swift | 13 +++++++++---- .../Components/AutoComplete/RecentTagsView.swift | 3 +++ .../StatusEditorAutoCompleteView.swift | 15 +++++---------- .../Sources/Timeline/actors/TimelineCache.swift | 2 +- 11 files changed, 41 insertions(+), 25 deletions(-) diff --git a/IceCubesApp/App/Tabs/Settings/RecenTagsSettingView.swift b/IceCubesApp/App/Tabs/Settings/RecenTagsSettingView.swift index 7b394b53..ec9aabdb 100644 --- a/IceCubesApp/App/Tabs/Settings/RecenTagsSettingView.swift +++ b/IceCubesApp/App/Tabs/Settings/RecenTagsSettingView.swift @@ -15,7 +15,14 @@ struct RecenTagsSettingView: View { var body: some View { Form { ForEach(tags) { tag in - Text("#\(tag.title)") + VStack(alignment: .leading) { + Text("#\(tag.title)") + .font(.scaledBody) + .foregroundColor(.primary) + Text(tag.formattedDate) + .font(.scaledFootnote) + .foregroundStyle(.secondary) + } }.onDelete { indexes in if let index = indexes.first { context.delete(tags[index]) diff --git a/Packages/Account/Sources/Account/AccountsList/AccountsListViewModel.swift b/Packages/Account/Sources/Account/AccountsList/AccountsListViewModel.swift index 01331a77..1d5f2787 100644 --- a/Packages/Account/Sources/Account/AccountsList/AccountsListViewModel.swift +++ b/Packages/Account/Sources/Account/AccountsList/AccountsListViewModel.swift @@ -61,12 +61,12 @@ public enum AccountsListMode { let link: LinkHandler? switch mode { case let .followers(accountId): - var account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId)) + let account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId)) totalCount = account.followersCount (accounts, link) = try await client.getWithLink(endpoint: Accounts.followers(id: accountId, maxId: nil)) case let .following(accountId): - var account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId)) + let account: Account = try await client.get(endpoint: Accounts.accounts(id: accountId)) totalCount = account.followingCount (accounts, link) = try await client.getWithLink(endpoint: Accounts.following(id: accountId, maxId: nil)) diff --git a/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift b/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift index 6de3d7c7..de5e41ca 100644 --- a/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift +++ b/Packages/Account/Sources/Account/Edit/EditAccountViewModel.swift @@ -52,9 +52,9 @@ import Status Task { if let data = await getItemImageData(item: item) { if isChangingAvatar { - await uploadAvatar(data: data) + _ = await uploadAvatar(data: data) } else if isChangingHeader { - await uploadHeader(data: data) + _ = await uploadHeader(data: data) } await fetchAccount() isChangingAvatar = false diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/AccountPopoverView.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/AccountPopoverView.swift index 3aebf929..0d5cc7d5 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/AccountPopoverView.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/AccountPopoverView.swift @@ -122,7 +122,7 @@ struct AccountPopoverView: View { } private var adaptiveConfig: AvatarView.FrameConfig { - var cornerRadius: CGFloat = if config == .badge || theme.avatarShape == .circle { + let cornerRadius: CGFloat = if config == .badge || theme.avatarShape == .circle { config.width / 2 } else { config.cornerRadius diff --git a/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift b/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift index 99b1d76d..89f15b15 100644 --- a/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift +++ b/Packages/DesignSystem/Sources/DesignSystem/Views/AvatarView.swift @@ -21,7 +21,7 @@ public struct AvatarView: View { } private var adaptiveConfig: FrameConfig { - var cornerRadius: CGFloat = if config == .badge || theme.avatarShape == .circle { + let cornerRadius: CGFloat = if config == .badge || theme.avatarShape == .circle { config.width / 2 } else { config.cornerRadius diff --git a/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift b/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift index 9779431a..f4336e9e 100644 --- a/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift +++ b/Packages/MediaUI/Sources/MediaUI/MediaUITransferableImage.swift @@ -5,8 +5,8 @@ import UIKit struct MediaUIImageTransferable: Codable, Transferable { let url: URL - func fetchAsImage() async -> Image { - let data = try? await URLSession.shared.data(from: url).0 + func fetchAsImage() -> Image { + let data = try? Data(contentsOf: url) guard let data, let uiimage = UIImage(data: data) else { return Image(systemName: "photo") } @@ -15,7 +15,7 @@ struct MediaUIImageTransferable: Codable, Transferable { static var transferRepresentation: some TransferRepresentation { ProxyRepresentation { media in - await media.fetchAsImage() + media.fetchAsImage() } } } diff --git a/Packages/Models/Sources/Models/SwiftData/RecentTag.swift b/Packages/Models/Sources/Models/SwiftData/RecentTag.swift index 0b33bcbb..2b6d8250 100644 --- a/Packages/Models/Sources/Models/SwiftData/RecentTag.swift +++ b/Packages/Models/Sources/Models/SwiftData/RecentTag.swift @@ -11,3 +11,9 @@ import SwiftUI self.lastUse = Date() } } + +extension RecentTag { + public var formattedDate: String { + DateFormatterCache.shared.createdAtRelativeFormatter.localizedString(for: lastUse, relativeTo: Date()) + } +} diff --git a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift index 30ba44cc..419d1cc0 100644 --- a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/ExpandedView.swift @@ -32,10 +32,15 @@ extension StatusEditorAutoCompleteView { viewModel.selectHashtagSuggestion(tag: tag.title) } } label: { - Text("#\(tag.title)") - .font(.scaledFootnote) - .fontWeight(.bold) - .foregroundColor(theme.labelColor) + VStack(alignment: .leading) { + Text("#\(tag.title)") + .font(.scaledFootnote) + .fontWeight(.bold) + .foregroundColor(theme.labelColor) + Text(tag.formattedDate) + .font(.scaledFootnote) + .foregroundStyle(theme.tintColor) + } } Spacer() } diff --git a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/RecentTagsView.swift b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/RecentTagsView.swift index db62371a..67ab9d05 100644 --- a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/RecentTagsView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/RecentTagsView.swift @@ -29,6 +29,9 @@ extension StatusEditorAutoCompleteView { .font(.scaledFootnote) .fontWeight(.bold) .foregroundColor(theme.labelColor) + Text(tag.formattedDate) + .font(.scaledFootnote) + .foregroundStyle(theme.tintColor) } } } diff --git a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift index 180a1be5..35614ae0 100644 --- a/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/AutoComplete/StatusEditorAutoCompleteView.swift @@ -28,7 +28,11 @@ struct StatusEditorAutoCompleteView: View { if !viewModel.mentionsSuggestions.isEmpty { Self.MentionsView(viewModel: viewModel) } else { - suggestionsTagView + if viewModel.showRecentsTagsInline { + Self.RecentTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded) + } else { + Self.RemoteTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded) + } } } .padding(.horizontal, .layoutPadding) @@ -54,13 +58,4 @@ struct StatusEditorAutoCompleteView: View { .background(.thinMaterial) } } - - @ViewBuilder - private var suggestionsTagView: some View { - if viewModel.showRecentsTagsInline { - Self.RecentTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded) - } else { - Self.RemoteTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded) - } - } } diff --git a/Packages/Timeline/Sources/Timeline/actors/TimelineCache.swift b/Packages/Timeline/Sources/Timeline/actors/TimelineCache.swift index 37ad3953..de2deab5 100644 --- a/Packages/Timeline/Sources/Timeline/actors/TimelineCache.swift +++ b/Packages/Timeline/Sources/Timeline/actors/TimelineCache.swift @@ -71,7 +71,7 @@ public actor TimelineCache { } func setLatestSeenStatuses(_ statuses: [Status], for client: Client, filter: String) { - var statuses = statuses.sorted(by: { $0.createdAt.asDate > $1.createdAt.asDate }) + let statuses = statuses.sorted(by: { $0.createdAt.asDate > $1.createdAt.asDate }) if filter == "Home" { UserDefaults.standard.set(statuses.map{ $0.id }, forKey: "timeline-last-seen-\(client.id)") } else {