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 { var body: some View {
Form { Form {
ForEach(tags) { tag in 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 }.onDelete { indexes in
if let index = indexes.first { if let index = indexes.first {
context.delete(tags[index]) context.delete(tags[index])

View file

@ -61,12 +61,12 @@ public enum AccountsListMode {
let link: LinkHandler? let link: LinkHandler?
switch mode { switch mode {
case let .followers(accountId): 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 totalCount = account.followersCount
(accounts, link) = try await client.getWithLink(endpoint: Accounts.followers(id: accountId, (accounts, link) = try await client.getWithLink(endpoint: Accounts.followers(id: accountId,
maxId: nil)) maxId: nil))
case let .following(accountId): 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 totalCount = account.followingCount
(accounts, link) = try await client.getWithLink(endpoint: Accounts.following(id: accountId, (accounts, link) = try await client.getWithLink(endpoint: Accounts.following(id: accountId,
maxId: nil)) maxId: nil))

View file

@ -52,9 +52,9 @@ import Status
Task { Task {
if let data = await getItemImageData(item: item) { if let data = await getItemImageData(item: item) {
if isChangingAvatar { if isChangingAvatar {
await uploadAvatar(data: data) _ = await uploadAvatar(data: data)
} else if isChangingHeader { } else if isChangingHeader {
await uploadHeader(data: data) _ = await uploadHeader(data: data)
} }
await fetchAccount() await fetchAccount()
isChangingAvatar = false isChangingAvatar = false

View file

@ -122,7 +122,7 @@ struct AccountPopoverView: View {
} }
private var adaptiveConfig: AvatarView.FrameConfig { 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 config.width / 2
} else { } else {
config.cornerRadius config.cornerRadius

View file

@ -21,7 +21,7 @@ public struct AvatarView: View {
} }
private var adaptiveConfig: FrameConfig { 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 config.width / 2
} else { } else {
config.cornerRadius config.cornerRadius

View file

@ -5,8 +5,8 @@ import UIKit
struct MediaUIImageTransferable: Codable, Transferable { struct MediaUIImageTransferable: Codable, Transferable {
let url: URL let url: URL
func fetchAsImage() async -> Image { func fetchAsImage() -> Image {
let data = try? await URLSession.shared.data(from: url).0 let data = try? Data(contentsOf: url)
guard let data, let uiimage = UIImage(data: data) else { guard let data, let uiimage = UIImage(data: data) else {
return Image(systemName: "photo") return Image(systemName: "photo")
} }
@ -15,7 +15,7 @@ struct MediaUIImageTransferable: Codable, Transferable {
static var transferRepresentation: some TransferRepresentation { static var transferRepresentation: some TransferRepresentation {
ProxyRepresentation { media in ProxyRepresentation { media in
await media.fetchAsImage() media.fetchAsImage()
} }
} }
} }

View file

@ -11,3 +11,9 @@ import SwiftUI
self.lastUse = Date() 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) viewModel.selectHashtagSuggestion(tag: tag.title)
} }
} label: { } label: {
Text("#\(tag.title)") VStack(alignment: .leading) {
.font(.scaledFootnote) Text("#\(tag.title)")
.fontWeight(.bold) .font(.scaledFootnote)
.foregroundColor(theme.labelColor) .fontWeight(.bold)
.foregroundColor(theme.labelColor)
Text(tag.formattedDate)
.font(.scaledFootnote)
.foregroundStyle(theme.tintColor)
}
} }
Spacer() Spacer()
} }

View file

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

View file

@ -28,7 +28,11 @@ struct StatusEditorAutoCompleteView: View {
if !viewModel.mentionsSuggestions.isEmpty { if !viewModel.mentionsSuggestions.isEmpty {
Self.MentionsView(viewModel: viewModel) Self.MentionsView(viewModel: viewModel)
} else { } else {
suggestionsTagView if viewModel.showRecentsTagsInline {
Self.RecentTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded)
} else {
Self.RemoteTagsView(viewModel: viewModel, isTagSuggestionExpanded: $isTagSuggestionExpanded)
}
} }
} }
.padding(.horizontal, .layoutPadding) .padding(.horizontal, .layoutPadding)
@ -54,13 +58,4 @@ struct StatusEditorAutoCompleteView: View {
.background(.thinMaterial) .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) { 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" { if filter == "Home" {
UserDefaults.standard.set(statuses.map{ $0.id }, forKey: "timeline-last-seen-\(client.id)") UserDefaults.standard.set(statuses.map{ $0.id }, forKey: "timeline-last-seen-\(client.id)")
} else { } else {