Checkpoint

This commit is contained in:
Thomas Ricouard 2023-09-17 07:53:32 +02:00
parent 886f314ea8
commit e882a15785
24 changed files with 81 additions and 80 deletions

View file

@ -21,7 +21,7 @@ struct IceCubesApp: App {
@StateObject private var userPreferences = UserPreferences.shared
@State private var pushNotificationsService = PushNotificationsService.shared
@State private var watcher = StreamWatcher()
@StateObject private var quickLook = QuickLook()
@State private var quickLook = QuickLook()
@StateObject private var theme = Theme.shared
@State private var sidebarRouterPath = RouterPath()
@ -45,7 +45,7 @@ struct IceCubesApp: App {
}
.environment(appAccountsManager)
.environment(appAccountsManager.currentClient)
.environmentObject(quickLook)
.environment(quickLook)
.environment(currentAccount)
.environment(currentInstance)
.environmentObject(userPreferences)

View file

@ -12,7 +12,7 @@ struct PushNotificationsView: View {
@Environment(AppAccountsManager.self) private var appAccountsManager
@Environment(PushNotificationsService.self) private var pushNotifications
@StateObject public var subscription: PushNotificationSubscriptionSettings
@State public var subscription: PushNotificationSubscriptionSettings
var body: some View {
Form {

View file

@ -12,7 +12,7 @@ struct AccountDetailHeaderView: View {
}
@EnvironmentObject private var theme: Theme
@EnvironmentObject private var quickLook: QuickLook
@Environment(QuickLook.self) private var quickLook
@Environment(RouterPath.self) private var routerPath
@Environment(CurrentAccount.self) private var currentAccount
@Environment(\.redactionReasons) private var reasons

View file

@ -10,14 +10,14 @@ public struct ConversationDetailView: View {
static let bottomAnchor = "bottom"
}
@EnvironmentObject private var quickLook: QuickLook
@Environment(QuickLook.self) private var quickLook
@Environment(RouterPath.self) private var routerPath
@Environment(CurrentAccount.self) private var currentAccount
@Environment(Client.self) private var client
@EnvironmentObject private var theme: Theme
@Environment(StreamWatcher.self) private var watcher
@StateObject private var viewModel: ConversationDetailViewModel
@State private var viewModel: ConversationDetailViewModel
@FocusState private var isMessageFieldFocused: Bool
@ -25,7 +25,7 @@ public struct ConversationDetailView: View {
@State private var didAppear: Bool = false
public init(conversation: Conversation) {
_viewModel = StateObject(wrappedValue: .init(conversation: conversation))
_viewModel = .init(initialValue: .init(conversation: conversation))
}
public var body: some View {

View file

@ -4,16 +4,16 @@ import Network
import SwiftUI
@MainActor
class ConversationDetailViewModel: ObservableObject {
@Observable class ConversationDetailViewModel {
var client: Client?
var conversation: Conversation
@Published var isLoadingMessages: Bool = true
@Published var messages: [Status] = []
var isLoadingMessages: Bool = true
var messages: [Status] = []
@Published var isSendingMessage: Bool = false
@Published var newMessageText: String = ""
var isSendingMessage: Bool = false
var newMessageText: String = ""
init(conversation: Conversation) {
self.conversation = conversation

View file

@ -6,7 +6,7 @@ import NukeUI
import SwiftUI
struct ConversationMessageView: View {
@EnvironmentObject private var quickLook: QuickLook
@Environment(QuickLook.self) private var quickLook
@Environment(RouterPath.self) private var routerPath
@Environment(CurrentAccount.self) private var currentAccount
@Environment(Client.self) private var client

View file

@ -12,7 +12,7 @@ struct ConversationsListRow: View {
@Environment(CurrentAccount.self) private var currentAccount
@Binding var conversation: Conversation
@ObservedObject var viewModel: ConversationsListViewModel
var viewModel: ConversationsListViewModel
var body: some View {
Button {

View file

@ -12,7 +12,7 @@ public struct ConversationsListView: View {
@Environment(Client.self) private var client
@EnvironmentObject private var theme: Theme
@StateObject private var viewModel = ConversationsListViewModel()
@State private var viewModel = ConversationsListViewModel()
public init() {}

View file

@ -3,13 +3,13 @@ import Network
import SwiftUI
@MainActor
class ConversationsListViewModel: ObservableObject {
@Observable class ConversationsListViewModel {
var client: Client?
@Published var isLoadingFirstPage: Bool = true
@Published var isLoadingNextPage: Bool = false
@Published var conversations: [Conversation] = []
@Published var isError: Bool = false
var isLoadingFirstPage: Bool = true
var isLoadingNextPage: Bool = false
var conversations: [Conversation] = []
var isError: Bool = false
var nextPage: LinkHandler?

View file

@ -1,7 +1,7 @@
import Combine
import UIKit
public class SceneDelegate: NSObject, ObservableObject, UIWindowSceneDelegate {
@Observable public class SceneDelegate: NSObject, UIWindowSceneDelegate {
public var window: UIWindow?
public var windowWidth: CGFloat {

View file

@ -163,14 +163,14 @@ extension Data {
}
@MainActor
public class PushNotificationSubscriptionSettings: ObservableObject {
@Published public var isEnabled: Bool = true
@Published public var isFollowNotificationEnabled: Bool = true
@Published public var isFavoriteNotificationEnabled: Bool = true
@Published public var isReblogNotificationEnabled: Bool = true
@Published public var isMentionNotificationEnabled: Bool = true
@Published public var isPollNotificationEnabled: Bool = true
@Published public var isNewPostsNotificationEnabled: Bool = true
@Observable public class PushNotificationSubscriptionSettings {
public var isEnabled: Bool = true
public var isFollowNotificationEnabled: Bool = true
public var isFavoriteNotificationEnabled: Bool = true
public var isReblogNotificationEnabled: Bool = true
public var isMentionNotificationEnabled: Bool = true
public var isPollNotificationEnabled: Bool = true
public var isNewPostsNotificationEnabled: Bool = true
public let account: PushAccount

View file

@ -3,8 +3,8 @@ import Combine
import SwiftUI
@MainActor
public class QuickLook: ObservableObject {
@Published public var url: URL? {
@Observable public class QuickLook {
public var url: URL? {
didSet {
if url == nil {
cleanup(urls: urls)
@ -12,9 +12,9 @@ public class QuickLook: ObservableObject {
}
}
@Published public private(set) var urls: [URL] = []
@Published public private(set) var isPreparing: Bool = false
@Published public private(set) var latestError: Error?
public private(set) var urls: [URL] = []
public private(set) var isPreparing: Bool = false
public private(set) var latestError: Error?
public init() {}

View file

@ -12,7 +12,7 @@ public struct StatusDetailView: View {
@Environment(Client.self) private var client
@Environment(RouterPath.self) private var routerPath
@StateObject private var viewModel: StatusDetailViewModel
@State private var viewModel: StatusDetailViewModel
@State private var isLoaded: Bool = false
@State private var statusHeight: CGFloat = 0
@ -22,15 +22,15 @@ public struct StatusDetailView: View {
@AccessibilityFocusState private var initialFocusBugWorkaround: Bool
public init(statusId: String) {
_viewModel = StateObject(wrappedValue: { .init(statusId: statusId) }())
_viewModel = .init(wrappedValue: .init(statusId: statusId))
}
public init(status: Status) {
_viewModel = StateObject(wrappedValue: { .init(status: status) }())
_viewModel = .init(wrappedValue: .init(status: status))
}
public init(remoteStatusURL: URL) {
_viewModel = StateObject(wrappedValue: { .init(remoteStatusURL: remoteStatusURL) }())
_viewModel = .init(wrappedValue: .init(remoteStatusURL: remoteStatusURL))
}
public var body: some View {

View file

@ -5,7 +5,7 @@ import Network
import SwiftUI
@MainActor
class StatusDetailViewModel: ObservableObject {
@Observable class StatusDetailViewModel {
public var statusId: String?
public var remoteStatusURL: URL?
@ -16,10 +16,10 @@ class StatusDetailViewModel: ObservableObject {
case loading, display(statuses: [Status], date: Date), error(error: Error)
}
@Published var state: State = .loading
@Published var isLoadingContext = true
@Published var title: LocalizedStringKey = ""
@Published var scrollToId: String?
var state: State = .loading
var isLoadingContext = true
var title: LocalizedStringKey = ""
var scrollToId: String?
init(statusId: String) {
state = .loading

View file

@ -12,7 +12,7 @@ struct StatusEditorAccessoryView: View {
@Environment(\.colorScheme) private var colorScheme
@FocusState<Bool>.Binding var isSpoilerTextFocused: Bool
@ObservedObject var viewModel: StatusEditorViewModel
var viewModel: StatusEditorViewModel
@State private var isDraftsSheetDisplayed: Bool = false
@State private var isLanguageSheetDisplayed: Bool = false
@ -24,6 +24,7 @@ struct StatusEditorAccessoryView: View {
@State private var isCameraPickerPresented: Bool = false
var body: some View {
@Bindable var viewModel = viewModel
VStack(spacing: 0) {
Divider()
HStack {

View file

@ -5,7 +5,7 @@ import SwiftUI
struct StatusEditorAutoCompleteView: View {
@EnvironmentObject private var theme: Theme
@ObservedObject var viewModel: StatusEditorViewModel
var viewModel: StatusEditorViewModel
var body: some View {
if !viewModel.mentionsSuggestions.isEmpty || !viewModel.tagsSuggestions.isEmpty {

View file

@ -8,7 +8,7 @@ struct StatusEditorMediaEditView: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject private var theme: Theme
@Environment(CurrentInstance.self) private var currentInstance
@ObservedObject var viewModel: StatusEditorViewModel
var viewModel: StatusEditorViewModel
let container: StatusEditorMediaContainer
@State private var imageDescription: String = ""

View file

@ -8,7 +8,7 @@ import SwiftUI
struct StatusEditorMediaView: View {
@EnvironmentObject private var theme: Theme
@Environment(CurrentInstance.self) private var currentInstance
@ObservedObject var viewModel: StatusEditorViewModel
var viewModel: StatusEditorViewModel
@State private var editingContainer: StatusEditorMediaContainer?
@State private var isErrorDisplayed: Bool = false

View file

@ -14,13 +14,13 @@ struct StatusEditorPollView: View {
@EnvironmentObject private var theme: Theme
@Environment(CurrentInstance.self) private var currentInstance
@ObservedObject var viewModel: StatusEditorViewModel
var viewModel: StatusEditorViewModel
@Binding var showPoll: Bool
var body: some View {
@Bindable var viewModel = viewModel
let count = viewModel.pollOptions.count
VStack {
ForEach(0 ..< count, id: \.self) { index in
VStack {

View file

@ -20,14 +20,14 @@ public struct StatusEditorView: View {
@Environment(RouterPath.self) private var routerPath
@Environment(\.dismiss) private var dismiss
@StateObject private var viewModel: StatusEditorViewModel
@State private var viewModel: StatusEditorViewModel
@FocusState private var isSpoilerTextFocused: Bool
@State private var isDismissAlertPresented: Bool = false
@State private var isLanguageConfirmPresented = false
public init(mode: StatusEditorViewModel.Mode) {
_viewModel = StateObject(wrappedValue: .init(mode: mode))
_viewModel = .init(initialValue: .init(mode: mode))
}
public var body: some View {

View file

@ -8,7 +8,7 @@ import PhotosUI
import SwiftUI
@MainActor
public class StatusEditorViewModel: NSObject, ObservableObject {
@Observable public class StatusEditorViewModel: NSObject {
var mode: Mode
var client: Client?
@ -50,7 +50,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
return textView.markedTextRange
}
@Published var statusText = NSMutableAttributedString(string: "") {
var statusText = NSMutableAttributedString(string: "") {
didSet {
let range = selectedRange
processText()
@ -73,18 +73,18 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
private var itemsProvider: [NSItemProvider]?
@Published var backupStatusText: NSAttributedString?
var backupStatusText: NSAttributedString?
@Published var showPoll: Bool = false
@Published var pollVotingFrequency = PollVotingFrequency.oneVote
@Published var pollDuration = Duration.oneDay
@Published var pollOptions: [String] = ["", ""]
var showPoll: Bool = false
var pollVotingFrequency = PollVotingFrequency.oneVote
var pollDuration = Duration.oneDay
var pollOptions: [String] = ["", ""]
@Published var spoilerOn: Bool = false
@Published var spoilerText: String = ""
var spoilerOn: Bool = false
var spoilerText: String = ""
@Published var isPosting: Bool = false
@Published var selectedMedias: [PhotosPickerItem] = [] {
var isPosting: Bool = false
var selectedMedias: [PhotosPickerItem] = [] {
didSet {
if selectedMedias.count > 4 {
selectedMedias = selectedMedias.prefix(4).map { $0 }
@ -94,16 +94,16 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
}
}
@Published var isMediasLoading: Bool = false
var isMediasLoading: Bool = false
@Published var mediasImages: [StatusEditorMediaContainer] = []
@Published var replyToStatus: Status?
@Published var embeddedStatus: Status?
var mediasImages: [StatusEditorMediaContainer] = []
var replyToStatus: Status?
var embeddedStatus: Status?
@Published var customEmojis: [Emoji] = []
var customEmojis: [Emoji] = []
@Published var postingError: String?
@Published var showPostingErrorAlert: Bool = false
var postingError: String?
var showPostingErrorAlert: Bool = false
var canPost: Bool {
statusText.length > 0 || !mediasImages.isEmpty
@ -123,11 +123,11 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
return !modifiedStatusText.isEmpty && !mode.isInShareExtension
}
@Published var visibility: Models.Visibility = .pub
var visibility: Models.Visibility = .pub
@Published var mentionsSuggestions: [Account] = []
@Published var tagsSuggestions: [Tag] = []
@Published var selectedLanguage: String?
var mentionsSuggestions: [Account] = []
var tagsSuggestions: [Tag] = []
var selectedLanguage: String?
var hasExplicitlySelectedLanguage: Bool = false
private var currentSuggestionRange: NSRange?

View file

@ -14,7 +14,7 @@ public struct StatusRowView: View {
@Environment(\.accessibilityVoiceOverEnabled) private var accessibilityVoiceOverEnabled
@Environment(\.isStatusFocused) private var isFocused
@EnvironmentObject private var quickLook: QuickLook
@Environment(QuickLook.self) private var quickLook
@EnvironmentObject private var theme: Theme
@State var viewModel: StatusRowViewModel

View file

@ -8,9 +8,9 @@ struct StatusRowContextMenu: View {
@Environment(\.displayScale) var displayScale
@Environment(Client.self) private var client
@EnvironmentObject private var sceneDelegate: SceneDelegate
@Environment(SceneDelegate.self) private var sceneDelegate
@EnvironmentObject private var preferences: UserPreferences
@Environment(CurrentAccount.self) private var account
@Environment(CurrentAccount.self) private var account
@Environment(CurrentInstance.self) private var currentInstance
@Environment(StatusDataController.self) private var statusDataController
@ -89,8 +89,8 @@ struct StatusRowContextMenu: View {
.environmentObject(preferences)
.environment(account)
.environment(currentInstance)
.environmentObject(SceneDelegate())
.environmentObject(QuickLook())
.environment(SceneDelegate())
.environment(QuickLook())
.environment(viewModel.client)
.preferredColorScheme(Theme.shared.selectedScheme == .dark ? .dark : .light)
.foregroundColor(Theme.shared.labelColor)

View file

@ -11,9 +11,9 @@ public struct StatusRowMediaPreviewView: View {
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
@Environment(\.isCompact) private var isCompact: Bool
@EnvironmentObject var sceneDelegate: SceneDelegate
@Environment(SceneDelegate.self) private var sceneDelegate
@EnvironmentObject private var preferences: UserPreferences
@EnvironmentObject private var quickLook: QuickLook
@Environment(QuickLook.self) private var quickLook
@EnvironmentObject private var theme: Theme
public let attachments: [MediaAttachment]