This commit is contained in:
Thomas Ricouard 2024-08-01 08:58:54 +02:00
parent 2a3da72239
commit a72f290038
38 changed files with 209 additions and 207 deletions

View File

@ -1,4 +1,5 @@
import AppAccount
import AuthenticationServices
import Combine
import DesignSystem
import Env
@ -7,7 +8,6 @@ import Network
import NukeUI
import SafariServices
import SwiftUI
import AuthenticationServices
@MainActor
struct AddAccountView: View {

View File

@ -72,24 +72,24 @@ struct SettingsTabs: View {
}
.navigationDestination(item: $startingPoint) { targetView in
switch targetView {
case .display:
DisplaySettingsView()
case .haptic:
HapticSettingsView()
case .remoteTimelines:
RemoteTimelinesSettingView()
case .tagGroups:
TagsGroupSettingView()
case .recentTags:
RecenTagsSettingView()
case .content:
ContentSettingsView()
case .swipeActions:
SwipeActionsSettingsView()
case .tabAndSidebarEntries:
EmptyView()
case .translation:
TranslationSettingsView()
case .display:
DisplaySettingsView()
case .haptic:
HapticSettingsView()
case .remoteTimelines:
RemoteTimelinesSettingView()
case .tagGroups:
TagsGroupSettingView()
case .recentTags:
RecenTagsSettingView()
case .content:
ContentSettingsView()
case .swipeActions:
SwipeActionsSettingsView()
case .tabAndSidebarEntries:
EmptyView()
case .translation:
TranslationSettingsView()
}
}
}

View File

@ -29,11 +29,11 @@ public struct DefaultListEntityQuery: EntityQuery {
var account
public func entities(for _: [ListEntity.ID]) async throws -> [ListEntity] {
await fetchLists().map{ .init(list: $0 )}
await fetchLists().map { .init(list: $0) }
}
public func suggestedEntities() async throws -> [ListEntity] {
await fetchLists().map{ .init(list: $0 )}
await fetchLists().map { .init(list: $0) }
}
public func defaultResult() async -> ListEntity? {

View File

@ -10,12 +10,12 @@ struct AccountWidgetProvider: AppIntentTimelineProvider {
.init(date: Date(), account: .placeholder(), avatar: nil)
}
func snapshot(for configuration: AccountWidgetConfiguration, in context: Context) async -> AccountWidgetEntry {
func snapshot(for configuration: AccountWidgetConfiguration, in _: Context) async -> AccountWidgetEntry {
let account = await fetchAccount(configuration: configuration)
return .init(date: Date(), account: account, avatar: nil)
}
func timeline(for configuration: AccountWidgetConfiguration, in context: Context) async -> Timeline<AccountWidgetEntry> {
func timeline(for configuration: AccountWidgetConfiguration, in _: Context) async -> Timeline<AccountWidgetEntry> {
let account = await fetchAccount(configuration: configuration)
let images = try? await loadImages(urls: [account.avatar])
return .init(entries: [.init(date: Date(), account: account, avatar: images?.first?.value)],

View File

@ -11,7 +11,6 @@ struct AccountWidgetView: View {
@Environment(\.widgetFamily) var family
@Environment(\.redactionReasons) var redacted
var body: some View {
VStack(alignment: .center, spacing: 4) {
if let avatar = entry.avatar {

View File

@ -138,13 +138,13 @@ public struct AccountDetailContextMenu: View {
}
#if canImport(_Translation_SwiftUI)
if #available(iOS 17.4, *) {
Button {
showTranslateView = true
} label: {
Label("status.action.translate", systemImage: "captions.bubble")
}
if #available(iOS 17.4, *) {
Button {
showTranslateView = true
} label: {
Label("status.action.translate", systemImage: "captions.bubble")
}
}
#endif
if viewModel.relationship?.following == true {

View File

@ -85,14 +85,14 @@ public struct AccountDetailView: View {
Spacer()
Image(systemName: "chevron.right")
}
.onTapGesture {
if let account = viewModel.account {
routerPath.navigate(to: .accountMediaGridView(account: account,
initialMediaStatuses: viewModel.statusesMedias))
}
.onTapGesture {
if let account = viewModel.account {
routerPath.navigate(to: .accountMediaGridView(account: account,
initialMediaStatuses: viewModel.statusesMedias))
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
.listRowBackground(theme.primaryBackgroundColor)
#endif
}
StatusesListView(fetcher: viewModel,

View File

@ -85,7 +85,7 @@ import SwiftUI
private(set) var statuses: [Status] = []
var statusesMedias: [MediaStatus] {
statuses.filter{ !$0.mediaAttachments.isEmpty }.flatMap{ $0.asMediaStatus}
statuses.filter { !$0.mediaAttachments.isEmpty }.flatMap { $0.asMediaStatus }
}
var boosts: [Status] = []

View File

@ -128,7 +128,7 @@ public struct AccountsListView: View {
PlaceholderView(iconName: "person.icloud",
title: "No accounts found",
message: "This list of accounts is empty")
.listRowSeparator(.hidden)
.listRowSeparator(.hidden)
} else {
ForEach(accounts) { account in
if let relationship = relationships.first(where: { $0.id == account.id }) {
@ -139,7 +139,7 @@ public struct AccountsListView: View {
}
}
#if !os(visionOS)
.listRowBackground(theme.primaryBackgroundColor)
.listRowBackground(theme.primaryBackgroundColor)
#endif
switch nextPageState {

View File

@ -99,21 +99,21 @@ public struct EditAccountView: View {
viewModel.isPhotoPickerPresented = true
}
if viewModel.avatar != nil || viewModel.header != nil {
Divider()
Divider()
}
if viewModel.avatar != nil {
Button("account.edit.avatar.delete", role: .destructive) {
Task {
await viewModel.deleteAvatar()
}
Button("account.edit.avatar.delete", role: .destructive) {
Task {
await viewModel.deleteAvatar()
}
}
}
if viewModel.header != nil {
Button("account.edit.header.delete", role: .destructive) {
Task {
await viewModel.deleteHeader()
}
Button("account.edit.header.delete", role: .destructive) {
Task {
await viewModel.deleteHeader()
}
}
}
} label: {
Image(systemName: "photo.badge.plus")

View File

@ -51,19 +51,19 @@ import SwiftUI
didSet {
if let item = mediaPickers.first {
Task {
if isChangingAvatar {
if let data = await getItemImageData(item: item, for: .avatar) {
_ = await uploadAvatar(data: data)
}
isChangingAvatar = false
} else if isChangingHeader {
if let data = await getItemImageData(item: item, for: .header) {
_ = await uploadHeader(data: data)
}
isChangingHeader = false
if isChangingAvatar {
if let data = await getItemImageData(item: item, for: .avatar) {
_ = await uploadAvatar(data: data)
}
await fetchAccount()
mediaPickers = []
isChangingAvatar = false
} else if isChangingHeader {
if let data = await getItemImageData(item: item, for: .header) {
_ = await uploadHeader(data: data)
}
isChangingHeader = false
}
await fetchAccount()
mediaPickers = []
}
}
}
@ -186,26 +186,26 @@ import SwiftUI
}
extension EditAccountViewModel {
private enum ItemType {
case avatar
case header
private enum ItemType {
case avatar
case header
var maxHeight: CGFloat {
switch self {
case .avatar:
400
case .header:
500
}
}
var maxWidth: CGFloat {
switch self {
case .avatar:
400
case .header:
1500
}
}
var maxHeight: CGFloat {
switch self {
case .avatar:
400
case .header:
500
}
}
var maxWidth: CGFloat {
switch self {
case .avatar:
400
case .header:
1500
}
}
}
}

View File

@ -1,10 +1,10 @@
import SwiftUI
import DesignSystem
import NukeUI
import Env
import MediaUI
import Models
import Network
import NukeUI
import SwiftUI
@MainActor
public struct AccountDetailMediaGridView: View {
@ -18,7 +18,7 @@ public struct AccountDetailMediaGridView: View {
public init(account: Account, initialMediaStatuses: [MediaStatus]) {
self.account = account
self.mediaStatuses = initialMediaStatuses
mediaStatuses = initialMediaStatuses
}
public var body: some View {
@ -26,7 +26,8 @@ public struct AccountDetailMediaGridView: View {
LazyVGrid(columns: [.init(.flexible(minimum: 100), spacing: 4),
.init(.flexible(minimum: 100), spacing: 4),
.init(.flexible(minimum: 100), spacing: 4)],
spacing: 4) {
spacing: 4)
{
ForEach(mediaStatuses) { status in
GeometryReader { proxy in
if let url = status.attachment.url {
@ -35,7 +36,7 @@ public struct AccountDetailMediaGridView: View {
case .image:
LazyImage(url: url, transaction: Transaction(animation: .easeIn)) { state in
if let image = state.image {
image
image
.resizable()
.scaledToFill()
.frame(width: proxy.size.width, height: proxy.size.width)
@ -96,21 +97,21 @@ public struct AccountDetailMediaGridView: View {
}
.navigationTitle(account.displayName ?? "")
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
#endif
}
private func fetchNextPage() async throws {
let client = client
let newStatuses: [Status] =
try await client.get(endpoint: Accounts.statuses(id: account.id,
sinceId: mediaStatuses.last?.id,
try await client.get(endpoint: Accounts.statuses(id: account.id,
sinceId: mediaStatuses.last?.id,
tag: nil,
onlyMedia: true,
excludeReplies: true,
excludeReblogs: true,
pinned: nil))
mediaStatuses.append(contentsOf: newStatuses.flatMap{ $0.asMediaStatus })
mediaStatuses.append(contentsOf: newStatuses.flatMap { $0.asMediaStatus })
}
}

View File

@ -3,8 +3,8 @@ import SwiftUI
#if canImport(_Translation_SwiftUI)
import Translation
extension View {
public func addTranslateView(isPresented: Binding<Bool>, text: String) -> some View {
public extension View {
func addTranslateView(isPresented: Binding<Bool>, text: String) -> some View {
if #available(iOS 17.4, *) {
return self.translationPresentation(isPresented: isPresented, text: text)
} else {

View File

@ -137,7 +137,7 @@ public enum SettingsStartingPoint {
public var path: [RouterDestination] = []
public var presentedSheet: SheetDestination?
public static var settingsStartingPoint: SettingsStartingPoint? = nil
public static var settingsStartingPoint: SettingsStartingPoint?
public init() {}

View File

@ -130,10 +130,10 @@ import SwiftUI
}
var newPageResults: SearchResults = try await client.get(endpoint: Search.search(query: searchQuery,
type: type,
offset: offset,
following: nil),
forceVersion: .v2)
type: type,
offset: offset,
following: nil),
forceVersion: .v2)
if type == .accounts {
let relationships: [Relationship] =
try await client.get(endpoint: Accounts.relationships(ids: newPageResults.accounts.map(\.id)))
@ -149,8 +149,6 @@ import SwiftUI
case .statuses:
self.results[searchQuery]?.statuses.append(contentsOf: newPageResults.statuses)
}
} catch {
}
} catch {}
}
}

View File

@ -9,6 +9,7 @@ public struct Card: Codable, Identifiable, Equatable, Hashable {
public var id: String {
url
}
public let name: String
public let url: String
public let account: Account?

View File

@ -79,7 +79,7 @@ public final class Status: AnyStatus, Codable, Identifiable, Equatable, Hashable
}
public var asMediaStatus: [MediaStatus] {
mediaAttachments.map{ .init(status: self, attachment: $0)}
mediaAttachments.map { .init(status: self, attachment: $0) }
}
public init(id: String, content: HTMLString, account: Account, createdAt: ServerDate, editedAt: ServerDate?, reblog: ReblogStatus?, mediaAttachments: [MediaAttachment], mentions: [Mention], repliesCount: Int, reblogsCount: Int, favouritesCount: Int, card: Card?, favourited: Bool?, reblogged: Bool?, pinned: Bool?, bookmarked: Bool?, emojis: [Emoji], url: String?, application: Application?, inReplyToId: String?, inReplyToAccountId: String?, visibility: Visibility, poll: Poll?, spoilerText: HTMLString, filtered: [Filtered]?, sensitive: Bool, language: String?) {

View File

@ -4,7 +4,6 @@ public enum Profile: Endpoint {
case deleteAvatar
case deleteHeader
public func path() -> String {
switch self {
case .deleteAvatar:

View File

@ -58,10 +58,10 @@ public extension StatusEditor {
}
public func compressImageForUpload(
_ image: UIImage,
maxSize: Int = 10 * 1024 * 1024,
maxHeight: Double = 5000,
maxWidth: Double = 5000
_ image: UIImage,
maxSize: Int = 10 * 1024 * 1024,
maxHeight: Double = 5000,
maxWidth: Double = 5000
) async throws -> Data {
var image = image

View File

@ -38,9 +38,9 @@ extension StatusEditor {
generateButton
}
#if canImport(_Translation_SwiftUI)
if #available(iOS 17.4, *), !imageDescription.isEmpty {
translateButton
}
if #available(iOS 17.4, *), !imageDescription.isEmpty {
translateButton
}
#endif
}
.listRowBackground(theme.primaryBackgroundColor)

View File

@ -194,7 +194,7 @@ extension StatusEditor {
}
}
private func makeErrorView(error: ServerError) -> some View {
private func makeErrorView(error _: ServerError) -> some View {
ZStack {
placeholderView
Text("status.editor.error.upload")

View File

@ -155,8 +155,8 @@ import SwiftUI
.init(color: startColor.opacity(0.02), location: 0.15),
.init(color: endColor, location: 0.25),
],
startPoint: .topLeading,
endPoint: .bottomTrailing)
startPoint: .topLeading,
endPoint: .bottomTrailing)
}
public init(status: Status,
@ -379,16 +379,18 @@ import SwiftUI
}
var hasShown = false
#if canImport(_Translation_SwiftUI)
if translation == nil,
#available(iOS 17.4, *) {
showAppleTranslation = true
hasShown = true
}
#endif
#if canImport(_Translation_SwiftUI)
if translation == nil,
#available(iOS 17.4, *)
{
showAppleTranslation = true
hasShown = true
}
#endif
if !hasShown,
translation == nil {
translation == nil
{
if preferredTranslationType == .useDeepl {
deeplTranslationError = true
} else {

View File

@ -95,9 +95,9 @@ struct StatusRowHeaderView: View {
private var dateView: some View {
Text("\(Image(systemName: viewModel.finalStatus.visibility.iconName))\(viewModel.finalStatus.createdAt.relativeFormatted)")
.fixedSize(horizontal: false, vertical: true)
.font(.scaledFootnote)
.foregroundStyle(.secondary)
.lineLimit(1)
.fixedSize(horizontal: false, vertical: true)
.font(.scaledFootnote)
.foregroundStyle(.secondary)
.lineLimit(1)
}
}

View File

@ -280,32 +280,32 @@ struct AltTextButton: View {
.padding(EdgeInsets(top: 5, leading: 7, bottom: 5, trailing: 7))
.background(.thinMaterial)
#if canImport(_Translation_SwiftUI)
.addTranslateView(isPresented: $isDisplayingTranslation, text: text)
.addTranslateView(isPresented: $isDisplayingTranslation, text: text)
#endif
#if os(visionOS)
.clipShape(Capsule())
.clipShape(Capsule())
#endif
.cornerRadius(4)
.padding(theme.statusDisplayStyle == .compact ? 0 : 10)
.alert(
"status.editor.media.image-description",
isPresented: $isDisplayingAlert
) {
Button("alert.button.ok", action: {})
Button("status.action.copy-text", action: { UIPasteboard.general.string = text })
#if canImport(_Translation_SwiftUI)
.cornerRadius(4)
.padding(theme.statusDisplayStyle == .compact ? 0 : 10)
.alert(
"status.editor.media.image-description",
isPresented: $isDisplayingAlert
) {
Button("alert.button.ok", action: {})
Button("status.action.copy-text", action: { UIPasteboard.general.string = text })
#if canImport(_Translation_SwiftUI)
if #available(iOS 17.4, *) {
Button("status.action.translate", action: { isDisplayingTranslation = true })
}
#endif
} message: {
Text(text)
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .bottomTrailing
)
#endif
} message: {
Text(text)
}
.frame(
maxWidth: .infinity,
maxHeight: .infinity,
alignment: .bottomTrailing
)
}
}
}

View File

@ -313,7 +313,8 @@ extension TimelineViewModel: StatusesFetcher {
guard !newStatuses.isEmpty,
isTimelineVisible,
!Task.isCancelled,
initialTimeline == timeline else {
initialTimeline == timeline
else {
canStreamEvents = true
return
}
@ -347,7 +348,8 @@ extension TimelineViewModel: StatusesFetcher {
if let topStatus = topStatus,
visibileStatuses.contains(where: { $0.id == topStatus.id }),
scrollToTopVisible {
scrollToTopVisible
{
updateTimelineWithScrollToTop(newStatuses: newStatuses, statuses: statuses, nextPageState: nextPageState)
} else {
updateTimelineWithAnimation(statuses: statuses, nextPageState: nextPageState)
@ -381,7 +383,7 @@ extension TimelineViewModel: StatusesFetcher {
var allStatuses: [Status] = []
var latestMinId = minId
do {
for _ in 1...maxPages {
for _ in 1 ... maxPages {
if Task.isCancelled { break }
let newStatuses: [Status] = try await client.get(endpoint: timeline.endpoint(