From bf49a4558c80017736850002a8ffb62f330fab69 Mon Sep 17 00:00:00 2001 From: Louis Lac Date: Tue, 21 Feb 2023 18:52:30 +0100 Subject: [PATCH] Singularize enum type names (#978) --- IceCubesApp/App/AppRouter.swift | 4 ++-- IceCubesApp/App/Tabs/Settings/SupportAppView.swift | 6 +++--- .../Account/Sources/Account/AccountDetailView.swift | 4 ++-- .../{MutingDurations.swift => MutingDuration.swift} | 2 +- Packages/Env/Sources/Env/Router.swift | 10 +++++----- Packages/Network/Sources/Network/OpenAIClient.swift | 4 ++-- ...ditorAIPrompts.swift => StatusEditorAIPrompt.swift} | 4 ++-- .../Editor/Components/StatusEditorAccessoryView.swift | 2 +- .../Sources/Status/Editor/StatusEditorViewModel.swift | 2 +- .../Status/Row/Subviews/StatusRowActionsView.swift | 6 +++--- .../Status/Row/Subviews/StatusRowSwipeView.swift | 2 +- 11 files changed, 23 insertions(+), 23 deletions(-) rename Packages/Account/Sources/Account/{MutingDurations.swift => MutingDuration.swift} (94%) rename Packages/Status/Sources/Status/Editor/Components/{StatusEditorAIPrompts.swift => StatusEditorAIPrompt.swift} (85%) diff --git a/IceCubesApp/App/AppRouter.swift b/IceCubesApp/App/AppRouter.swift index d801434a..b5172df3 100644 --- a/IceCubesApp/App/AppRouter.swift +++ b/IceCubesApp/App/AppRouter.swift @@ -13,7 +13,7 @@ import Timeline @MainActor extension View { func withAppRouter() -> some View { - navigationDestination(for: RouterDestinations.self) { destination in + navigationDestination(for: RouterDestination.self) { destination in switch destination { case let .accountDetail(id): AccountDetailView(accountId: id) @@ -47,7 +47,7 @@ extension View { } } - func withSheetDestinations(sheetDestinations: Binding) -> some View { + func withSheetDestinations(sheetDestinations: Binding) -> some View { sheet(item: sheetDestinations) { destination in switch destination { case let .replyToStatusEditor(status): diff --git a/IceCubesApp/App/Tabs/Settings/SupportAppView.swift b/IceCubesApp/App/Tabs/Settings/SupportAppView.swift index b2641614..468e46aa 100644 --- a/IceCubesApp/App/Tabs/Settings/SupportAppView.swift +++ b/IceCubesApp/App/Tabs/Settings/SupportAppView.swift @@ -5,7 +5,7 @@ import Shimmer import SwiftUI struct SupportAppView: View { - enum Tips: String, CaseIterable { + enum Tip: String, CaseIterable { case one, two, three, four init(productId: String) { @@ -86,7 +86,7 @@ struct SupportAppView: View { .shimmering() } else { ForEach(products, id: \.productIdentifier) { product in - let tip = Tips(productId: product.productIdentifier) + let tip = Tip(productId: product.productIdentifier) HStack { VStack(alignment: .leading) { Text(tip.title) @@ -141,7 +141,7 @@ struct SupportAppView: View { }) .onAppear { loadingProducts = true - Purchases.shared.getProducts(Tips.allCases.map { $0.productId }) { products in + Purchases.shared.getProducts(Tip.allCases.map { $0.productId }) { products in self.products = products.sorted(by: { $0.price < $1.price }) withAnimation { loadingProducts = false diff --git a/Packages/Account/Sources/Account/AccountDetailView.swift b/Packages/Account/Sources/Account/AccountDetailView.swift index 0963c63c..36e9685e 100644 --- a/Packages/Account/Sources/Account/AccountDetailView.swift +++ b/Packages/Account/Sources/Account/AccountDetailView.swift @@ -218,7 +218,7 @@ public struct AccountDetailView: View { private var listsListView: some View { Group { ForEach(currentAccount.sortedLists) { list in - NavigationLink(value: RouterDestinations.list(list: list)) { + NavigationLink(value: RouterDestination.list(list: list)) { Text(list.title) .font(.scaledHeadline) .foregroundColor(theme.labelColor) @@ -346,7 +346,7 @@ public struct AccountDetailView: View { } } else { Menu { - ForEach(MutingDurations.allCases, id: \.rawValue) { duration in + ForEach(MutingDuration.allCases, id: \.rawValue) { duration in Button(duration.description) { Task { do { diff --git a/Packages/Account/Sources/Account/MutingDurations.swift b/Packages/Account/Sources/Account/MutingDuration.swift similarity index 94% rename from Packages/Account/Sources/Account/MutingDurations.swift rename to Packages/Account/Sources/Account/MutingDuration.swift index 090b7736..1fee99d3 100644 --- a/Packages/Account/Sources/Account/MutingDurations.swift +++ b/Packages/Account/Sources/Account/MutingDuration.swift @@ -1,6 +1,6 @@ import SwiftUI -enum MutingDurations: Int, CaseIterable { +enum MutingDuration: Int, CaseIterable { case infinite = 0 case fiveMinutes = 300 case thirtyMinutes = 1800 diff --git a/Packages/Env/Sources/Env/Router.swift b/Packages/Env/Sources/Env/Router.swift index f27f39c2..7e9e1009 100644 --- a/Packages/Env/Sources/Env/Router.swift +++ b/Packages/Env/Sources/Env/Router.swift @@ -3,7 +3,7 @@ import Models import Network import SwiftUI -public enum RouterDestinations: Hashable { +public enum RouterDestination: Hashable { case accountDetail(id: String) case accountDetailWithAccount(account: Account) case accountSettingsWithAccount(account: Account, appAccount: AppAccount) @@ -20,7 +20,7 @@ public enum RouterDestinations: Hashable { case accountsList(accounts: [Account]) } -public enum SheetDestinations: Identifiable { +public enum SheetDestination: Identifiable { case newStatusEditor(visibility: Models.Visibility) case editStatusEditor(status: Status) case replyToStatusEditor(status: Status) @@ -64,12 +64,12 @@ public class RouterPath: ObservableObject { public var client: Client? public var urlHandler: ((URL) -> OpenURLAction.Result)? - @Published public var path: [RouterDestinations] = [] - @Published public var presentedSheet: SheetDestinations? + @Published public var path: [RouterDestination] = [] + @Published public var presentedSheet: SheetDestination? public init() {} - public func navigate(to: RouterDestinations) { + public func navigate(to: RouterDestination) { path.append(to) } diff --git a/Packages/Network/Sources/Network/OpenAIClient.swift b/Packages/Network/Sources/Network/OpenAIClient.swift index 8103499f..f269ca06 100644 --- a/Packages/Network/Sources/Network/OpenAIClient.swift +++ b/Packages/Network/Sources/Network/OpenAIClient.swift @@ -43,7 +43,7 @@ public struct OpenAIClient { } } - public enum Prompts { + public enum Prompt { case correct(input: String) case shorten(input: String) case emphasize(input: String) @@ -89,7 +89,7 @@ public struct OpenAIClient { public init() {} - public func request(_ prompt: Prompts) async throws -> Response { + public func request(_ prompt: Prompt) async throws -> Response { do { let jsonData = try encoder.encode(prompt.request) var request = URLRequest(url: endpoint) diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAIPrompts.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAIPrompt.swift similarity index 85% rename from Packages/Status/Sources/Status/Editor/Components/StatusEditorAIPrompts.swift rename to Packages/Status/Sources/Status/Editor/Components/StatusEditorAIPrompt.swift index 907ed4a2..c199ad37 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAIPrompts.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAIPrompt.swift @@ -2,7 +2,7 @@ import Foundation import Network import SwiftUI -enum StatusEditorAIPrompts: CaseIterable { +enum StatusEditorAIPrompt: CaseIterable { case correct, fit, emphasize @ViewBuilder @@ -17,7 +17,7 @@ enum StatusEditorAIPrompts: CaseIterable { } } - func toRequestPrompt(text: String) -> OpenAIClient.Prompts { + func toRequestPrompt(text: String) -> OpenAIClient.Prompt { switch self { case .correct: return .correct(input: text) diff --git a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift index 541518d1..384e7481 100644 --- a/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift +++ b/Packages/Status/Sources/Status/Editor/Components/StatusEditorAccessoryView.swift @@ -124,7 +124,7 @@ struct StatusEditorAccessoryView: View { private var AIMenu: some View { Menu { - ForEach(StatusEditorAIPrompts.allCases, id: \.self) { prompt in + ForEach(StatusEditorAIPrompt.allCases, id: \.self) { prompt in Button { Task { isLoadingAIRequest = true diff --git a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift index b5dc7a6d..964ae5ea 100644 --- a/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift +++ b/Packages/Status/Sources/Status/Editor/StatusEditorViewModel.swift @@ -483,7 +483,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject { // MARK: - OpenAI Prompt - func runOpenAI(prompt: OpenAIClient.Prompts) async { + func runOpenAI(prompt: OpenAIClient.Prompt) async { do { let client = OpenAIClient() let response = try await client.request(prompt) diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift index ab745ffc..f8eb3cfa 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowActionsView.swift @@ -14,7 +14,7 @@ struct StatusRowActionsView: View { } @MainActor - enum Actions: CaseIterable { + enum Action: CaseIterable { case respond, boost, favorite, bookmark, share func iconName(viewModel: StatusRowViewModel, privateBoost: Bool = false) -> String { @@ -69,7 +69,7 @@ struct StatusRowActionsView: View { var body: some View { VStack(spacing: 12) { HStack { - ForEach(Actions.allCases, id: \.self) { action in + ForEach(Action.allCases, id: \.self) { action in if action == .share { if let urlString = viewModel.status.reblog?.url ?? viewModel.status.url, let url = URL(string: urlString) @@ -107,7 +107,7 @@ struct StatusRowActionsView: View { } } - private func handleAction(action: Actions) { + private func handleAction(action: Action) { Task { if viewModel.isRemote, viewModel.localStatusId == nil || viewModel.localStatus == nil { guard await viewModel.fetchRemoteStatus() else { diff --git a/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift b/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift index 4105a121..0672d84e 100644 --- a/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift +++ b/Packages/Status/Sources/Status/Row/Subviews/StatusRowSwipeView.swift @@ -85,7 +85,7 @@ struct StatusRowSwipeView: View { } @ViewBuilder - private func makeSwipeButtonForRouterPath(action: StatusAction, destination: SheetDestinations) -> some View { + private func makeSwipeButtonForRouterPath(action: StatusAction, destination: SheetDestination) -> some View { Button { HapticManager.shared.fireHaptic(of: .notification(.success)) viewModel.routerPath.presentedSheet = destination