Fix warnings + better recently used tags

This commit is contained in:
Thomas Ricouard 2024-01-06 11:21:07 +01:00
parent bb55154b75
commit 8c8c551686
11 changed files with 41 additions and 25 deletions

View file

@ -15,7 +15,14 @@ struct RecenTagsSettingView: View {
var body: some View {
Form {
ForEach(tags) { tag in
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])

View file

@ -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))

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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()
}
}
}

View file

@ -11,3 +11,9 @@ import SwiftUI
self.lastUse = Date()
}
}
extension RecentTag {
public var formattedDate: String {
DateFormatterCache.shared.createdAtRelativeFormatter.localizedString(for: lastUse, relativeTo: Date())
}
}

View file

@ -32,10 +32,15 @@ extension StatusEditorAutoCompleteView {
viewModel.selectHashtagSuggestion(tag: tag.title)
}
} label: {
VStack(alignment: .leading) {
Text("#\(tag.title)")
.font(.scaledFootnote)
.fontWeight(.bold)
.foregroundColor(theme.labelColor)
Text(tag.formattedDate)
.font(.scaledFootnote)
.foregroundStyle(theme.tintColor)
}
}
Spacer()
}

View file

@ -29,6 +29,9 @@ extension StatusEditorAutoCompleteView {
.font(.scaledFootnote)
.fontWeight(.bold)
.foregroundColor(theme.labelColor)
Text(tag.formattedDate)
.font(.scaledFootnote)
.foregroundStyle(theme.tintColor)
}
}
}

View file

@ -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)
}
}
}

View file

@ -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 {