Skip to content

Instantly share code, notes, and snippets.

@apatronl
Last active September 20, 2024 22:20
Show Gist options
  • Save apatronl/d2264c81ee3c655612c0b38b12d34a92 to your computer and use it in GitHub Desktop.
Save apatronl/d2264c81ee3c655612c0b38b12d34a92 to your computer and use it in GitHub Desktop.
struct ChatView: View {
@Bindable private var viewModel: ChatViewModel = ChatViewModel()
var body: some View {
NavigationStack {
VStack {
ChatMessagesList(viewModel: viewModel)
HStack {
MessageTextField(draftMessage: $viewModel.draftMessage)
SendMessageButton {
viewModel.sendMessage()
}
.disabled(!viewModel.canSendMessage)
}
.padding(8)
}
.navigationTitle("Chat")
.toolbar {
Button(
action: {
// Trigger translation
viewModel.triggerTranslation()
},
label: {
Image(systemName: "translate")
}
)
}
}
.translationTask(viewModel.translationConfiguration) { session in
// Translate all messages
await viewModel.translateAllMessages(using: session)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment