NCAssistantTaskDetail.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // NCAssistantTaskDetail.swift
  3. // Nextcloud
  4. //
  5. // Created by Milen on 10.04.24.
  6. // Copyright © 2024 Marino Faggiana. All rights reserved.
  7. //
  8. import SwiftUI
  9. import NextcloudKit
  10. struct NCAssistantTaskDetail: View {
  11. @EnvironmentObject var model: NCAssistantTask
  12. let task: NKTextProcessingTask
  13. var body: some View {
  14. ZStack(alignment: .bottom) {
  15. InputOutputScrollView(task: task)
  16. BottomDetailsBar(task: task)
  17. }
  18. .navigationBarTitleDisplayMode(.inline)
  19. .navigationTitle(NSLocalizedString("_task_details_", comment: ""))
  20. .onAppear {
  21. model.selectTask(task)
  22. }
  23. }
  24. }
  25. #Preview {
  26. let model = NCAssistantTask(controller: nil)
  27. return NCAssistantTaskDetail(task: NKTextProcessingTask(id: 1, type: "OCP\\TextProcessing\\FreePromptTaskType", status: 1, userId: "christine", appId: "assistant", input: "", output: "", identifier: "", completionExpectedAt: 1712666412))
  28. .environmentObject(model)
  29. .onAppear {
  30. model.loadDummyData()
  31. }
  32. }
  33. struct InputOutputScrollView: View {
  34. @EnvironmentObject var model: NCAssistantTask
  35. let task: NKTextProcessingTask
  36. var body: some View {
  37. ScrollView {
  38. VStack(alignment: .leading) {
  39. Text(NSLocalizedString("_input_", comment: "")).font(.headline)
  40. .padding(.top, 10)
  41. Text(model.selectedTask?.input ?? "")
  42. .frame(maxWidth: .infinity, alignment: .topLeading)
  43. .padding()
  44. .background(Color(NCBrandColor.shared.textColor2).opacity(0.1))
  45. .clipShape(.rect(cornerRadius: 8))
  46. Text(NSLocalizedString("_output_", comment: "")).font(.headline)
  47. .padding(.top, 10)
  48. Text(model.selectedTask?.output ?? "")
  49. .frame(maxWidth: .infinity, alignment: .topLeading)
  50. .padding()
  51. .background(Color(NCBrandColor.shared.textColor2).opacity(0.1))
  52. .clipShape(.rect(cornerRadius: 8))
  53. }
  54. .padding(.horizontal)
  55. .padding(.bottom, 80)
  56. }
  57. .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
  58. }
  59. }
  60. struct BottomDetailsBar: View {
  61. @EnvironmentObject var model: NCAssistantTask
  62. let task: NKTextProcessingTask
  63. var body: some View {
  64. VStack(spacing: 0) {
  65. Divider()
  66. HStack(alignment: .bottom) {
  67. Label(
  68. title: {
  69. Text(NSLocalizedString(model.selectedTask?.statusInfo.stringKey ?? "", comment: ""))
  70. }, icon: {
  71. Image(systemName: model.selectedTask?.statusInfo.imageSystemName ?? "")
  72. .renderingMode(.original)
  73. .font(Font.system(.body).weight(.light))
  74. }
  75. )
  76. .frame(maxWidth: .infinity, alignment: .leading)
  77. if let completionExpectedAt = task.completionExpectedAt {
  78. Text(NCUtility().dateDiff(.init(timeIntervalSince1970: TimeInterval(completionExpectedAt))))
  79. .frame(maxWidth: .infinity, alignment: .trailing)
  80. }
  81. }
  82. .padding()
  83. .background(.bar)
  84. .frame(alignment: .bottom)
  85. }
  86. }
  87. }