Change timeline icon + move OpenAI icon to the accessory bar

This commit is contained in:
Thomas Ricouard 2023-01-29 15:08:41 +01:00
parent e33def60a3
commit 426d2e15b2
4 changed files with 37 additions and 39 deletions

View file

@ -84,7 +84,7 @@ enum Tab: Int, Identifiable, Hashable {
var iconName: String {
switch self {
case .timeline:
return "rectangle.on.rectangle"
return "rectangle.stack"
case .trending:
return "chart.line.uptrend.xyaxis"
case .local:

View file

@ -27,7 +27,7 @@ public extension ServerFilter.Context {
var iconName: String {
switch self {
case .home:
return "rectangle.on.rectangle"
return "rectangle.stack"
case .notifications:
return "bell"
case .public:

View file

@ -17,6 +17,7 @@ struct StatusEditorAccessoryView: View {
@State private var isLanguageSheetDisplayed: Bool = false
@State private var isCustomEmojisSheetDisplay: Bool = false
@State private var languageSearch: String = ""
@State private var isLoadingAIRequest: Bool = false
var body: some View {
VStack(spacing: 0) {
@ -77,6 +78,10 @@ struct StatusEditorAccessoryView: View {
Image(systemName: "globe")
}
}
if preferences.isOpenAIEnabled {
AIMenu.disabled(!viewModel.canPost)
}
}
.padding(.horizontal, .layoutPadding)
}
@ -110,6 +115,36 @@ struct StatusEditorAccessoryView: View {
Text(isoCode.uppercased())
}
}
private var AIMenu: some View {
Menu {
ForEach(StatusEditorAIPrompts.allCases, id: \.self) { prompt in
Button {
Task {
isLoadingAIRequest = true
await viewModel.runOpenAI(prompt: prompt.toRequestPrompt(text: viewModel.statusText.string))
isLoadingAIRequest = false
}
} label: {
prompt.label
}
}
if let backup = viewModel.backupStatusText {
Button {
viewModel.replaceTextWith(text: backup.string)
viewModel.backupStatusText = nil
} label: {
Label("status.editor.restore-previous", systemImage: "arrow.uturn.right")
}
}
} label: {
if isLoadingAIRequest {
ProgressView()
} else {
Image(systemName: "faxmachine")
}
}
}
private var languageSheetView: some View {
NavigationStack {

View file

@ -22,7 +22,6 @@ public struct StatusEditorView: View {
@FocusState private var isSpoilerTextFocused: Bool
@State private var isDismissAlertPresented: Bool = false
@State private var isLoadingAIRequest: Bool = false
public init(mode: StatusEditorViewModel.Mode) {
_viewModel = StateObject(wrappedValue: .init(mode: mode))
@ -101,12 +100,6 @@ public struct StatusEditorView: View {
Text(viewModel.postingError ?? "")
})
.toolbar {
if preferences.isOpenAIEnabled {
ToolbarItem(placement: .navigationBarTrailing) {
AIMenu
.disabled(!viewModel.canPost)
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
Task {
@ -218,34 +211,4 @@ public struct StatusEditorView: View {
)
}
}
private var AIMenu: some View {
Menu {
ForEach(StatusEditorAIPrompts.allCases, id: \.self) { prompt in
Button {
Task {
isLoadingAIRequest = true
await viewModel.runOpenAI(prompt: prompt.toRequestPrompt(text: viewModel.statusText.string))
isLoadingAIRequest = false
}
} label: {
prompt.label
}
}
if let backup = viewModel.backupStatusText {
Button {
viewModel.replaceTextWith(text: backup.string)
viewModel.backupStatusText = nil
} label: {
Label("status.editor.restore-previous", systemImage: "arrow.uturn.right")
}
}
} label: {
if isLoadingAIRequest {
ProgressView()
} else {
Image(systemName: "faxmachine")
}
}
}
}