diff --git a/Sources/SpeziChat/ChatView.swift b/Sources/SpeziChat/ChatView.swift index b4a29a5..d9a1363 100644 --- a/Sources/SpeziChat/ChatView.swift +++ b/Sources/SpeziChat/ChatView.swift @@ -112,7 +112,9 @@ public struct ChatView: View { } private var exportEnabled: Bool { - exportFormat != nil && !chat.isEmpty + exportFormat != nil && chat.contains(where: { + $0.role == .assistant || $0.role == .user // Only show export toolbar item if there are visible messages + }) } diff --git a/Sources/SpeziChat/Models/ChatEntity+Alignment.swift b/Sources/SpeziChat/Models/ChatEntity+Alignment.swift new file mode 100644 index 0000000..06128a4 --- /dev/null +++ b/Sources/SpeziChat/Models/ChatEntity+Alignment.swift @@ -0,0 +1,29 @@ +// +// This source file is part of the Stanford Spezi open source project +// +// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md) +// +// SPDX-License-Identifier: MIT +// + +import Foundation + + +extension ChatEntity { + /// Indicates if a ``ChatEntity`` is displayed in a leading or trailing position within a SwiftUI `View`. + enum Alignment { + case leading + case trailing + } + + + /// Dependent on the ``ChatEntity/Role``, display a ``ChatEntity`` in a leading or trailing position. + var alignment: Alignment { + switch self.role { + case .user: + return .trailing + default: + return .leading + } + } +} diff --git a/Sources/SpeziChat/Models/ChatEntity.swift b/Sources/SpeziChat/Models/ChatEntity.swift index 1afa5cf..28564c0 100644 --- a/Sources/SpeziChat/Models/ChatEntity.swift +++ b/Sources/SpeziChat/Models/ChatEntity.swift @@ -30,12 +30,6 @@ public struct ChatEntity: Codable, Equatable, Hashable { } } - /// Indicates if a ``ChatEntity`` is displayed in a leading or trailing position within a SwiftUI `View`. - enum Alignment { - case leading - case trailing - } - /// ``ChatEntity/Role`` associated with the ``ChatEntity``. public let role: Role @@ -45,17 +39,6 @@ public struct ChatEntity: Codable, Equatable, Hashable { public let date: Date - /// Dependent on the ``ChatEntity/Role``, display a ``ChatEntity`` in a leading or trailing position. - var alignment: Alignment { - switch self.role { - case .user: - return .trailing - default: - return .leading - } - } - - /// Creates a ``ChatEntity`` which is the building block of a Spezi ``Chat``. /// - Parameters: /// - role: ``ChatEntity/Role`` associated with the ``ChatEntity``.