Add a member directory tab (#11)

* Add HealthChat API and extended profile services

Expose OpenID tokens and homeserver credentials from the client proxy, and
add fork-only services for the HealthChat member directory backend
(api.healthchat.ch) plus a service that reads MSC4133 extended profile
fields directly from the homeserver. Groundwork for the members tab and
the profile screens.

Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS

* Show extended profile details on the profile screens

Add a UserProfileScreenHook that lets the fork inject an extra Form
section below the header of the user profile and room member details
screens. The HealthChat implementation loads the MSC4133 extended
profile fields and renders them with tappable phone/email/website
links, hiding the section entirely for profiles without any fields.

Strings live in a new fork-only HealthChat.strings table (de/en/fr,
generated as HealthChatL10n via SwiftGen) since Untranslated.strings
pins the English bundle.

Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS

* Add a member directory tab

Add a HomeTabsHook that lets the fork append an extra tab to the home
tab bar, and a HealthChat members flow behind it: a directory of all
approved members from the HealthChat API with server-side search,
pending-approval and error states, chat shortcuts and pushed member
profiles. Chats and calls are handed back to the session flow via the
hook's actions publisher.

Claude-Session: https://claude.ai/code/session_013qdTbAWsZj2quQzEkagXaS
This commit is contained in:
2026-09-22 17:03:28 +02:00
parent 352d25f2bb
commit 93149f1cbd
33 changed files with 954 additions and 1 deletions
@@ -7,3 +7,6 @@
"common_practice_name" = "Praxisname / Firmenname";
"common_specialty" = "Fachgebiet";
"common_website" = "Webseite";
"screen_member_directory_pending_approval" = "Ihr Konto wird derzeit geprüft. Sie erhalten Zugriff auf das Mitgliederverzeichnis, sobald Ihr Konto freigegeben wurde.";
"screen_member_directory_search_placeholder" = "Name, Praxis, Ort oder Fachgebiet";
"screen_member_directory_title" = "Mitglieder";
@@ -7,3 +7,6 @@
"common_practice_name" = "Practice name";
"common_specialty" = "Speciality";
"common_website" = "Website";
"screen_member_directory_pending_approval" = "Your account is being reviewed. You’ll get access to the member directory once it has been approved.";
"screen_member_directory_search_placeholder" = "Name, practice, city or speciality";
"screen_member_directory_title" = "Members";
@@ -7,3 +7,6 @@
"common_practice_name" = "Nom de l’entreprise";
"common_specialty" = "Spécialisation";
"common_website" = "Site web";
"screen_member_directory_pending_approval" = "Votre compte est en cours de vérification. Vous aurez accès à l’annuaire des membres dès qu’il aura été approuvé.";
"screen_member_directory_search_placeholder" = "Nom, cabinet, ville ou spécialisation";
"screen_member_directory_title" = "Membres";
+3
View File
@@ -46,6 +46,9 @@ final nonisolated class AppHooks: AppHooksProtocol {
@AppHook(default: DefaultExtendedProfileSectionHook())
var extendedProfileSectionHook: ExtendedProfileSectionHookProtocol
@AppHook(default: DefaultHomeTabsHook())
var homeTabsHook: HomeTabsHookProtocol
@AppHook(default: DefaultDeveloperOptionsScreenHook())
var developerOptionsScreenHook: DeveloperOptionsScreenHookProtocol
@@ -17,6 +17,7 @@ extension AppHooks {
registerAppSettingsHook(HealthChatAppSettingsHook())
registerCompoundHook(HealthChatCompoundHook())
registerExtendedProfileSectionHook(HealthChatExtendedProfileSectionHook())
registerHomeTabsHook(HealthChatHomeTabsHook())
#endif
}
}
@@ -0,0 +1,37 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
import SwiftUI
#if IS_MAIN_APP
// Conforming to the nonisolated hook protocol would infer nonisolated, but the
// flow it retains is main-actor state — the hook's requirement is @MainActor anyway.
@MainActor
final class HealthChatHomeTabsHook: HomeTabsHookProtocol {
private var membersFlowCoordinator: HealthChatMembersFlowCoordinator?
// Constructed during hook registration, before the main actor is reachable.
nonisolated init() { }
func makeExtraTab(flowParameters: CommonFlowParameters)
-> (tab: NavigationTabCoordinator<UserSessionFlowCoordinator.HomeTab>.Tab, actions: AnyPublisher<ExtraHomeTabAction, Never>)? {
let flowCoordinator = HealthChatMembersFlowCoordinator(flowParameters: flowParameters)
membersFlowCoordinator = flowCoordinator
flowCoordinator.start()
let details = NavigationTabCoordinator<UserSessionFlowCoordinator.HomeTab>
.TabDetails(tag: .members,
title: HealthChatL10n.screenMemberDirectoryTitle,
icon: \.userProfile,
selectedIcon: \.userProfileSolid)
return (tab: .init(coordinator: flowCoordinator.navigationStackCoordinator, details: details),
actions: flowCoordinator.actionsPublisher)
}
}
#endif
@@ -0,0 +1,29 @@
//
// Copyright 2026 Element Creations Ltd.
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
import SwiftUI
/// Actions an extra tab can ask the session flow to perform on its behalf.
enum ExtraHomeTabAction {
case presentRoom(roomID: String)
case presentCall(roomID: String, isVoiceCall: Bool)
}
nonisolated protocol HomeTabsHookProtocol: Sendable {
/// An extra tab appended after the standard tabs, or nil for none.
/// The hook keeps ownership of the tab's flow.
@MainActor func makeExtraTab(flowParameters: CommonFlowParameters)
-> (tab: NavigationTabCoordinator<UserSessionFlowCoordinator.HomeTab>.Tab, actions: AnyPublisher<ExtraHomeTabAction, Never>)?
}
struct DefaultHomeTabsHook: HomeTabsHookProtocol {
func makeExtraTab(flowParameters: CommonFlowParameters)
-> (tab: NavigationTabCoordinator<UserSessionFlowCoordinator.HomeTab>.Tab, actions: AnyPublisher<ExtraHomeTabAction, Never>)? {
nil
}
}
@@ -0,0 +1,125 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
import SwiftState
import SwiftUI
/// The flow behind the HealthChat "Members" tab: the member directory with
/// pushed member profiles. Chats and calls are handed off to the session flow.
final class HealthChatMembersFlowCoordinator {
private let flowParameters: CommonFlowParameters
let navigationStackCoordinator: NavigationStackCoordinator
private var cancellables = Set<AnyCancellable>()
enum State: StateType {
/// The state machine hasn't started.
case initial
/// The member directory at the root of the tab.
case memberDirectory
/// A member's profile pushed on top of the directory.
case memberProfile
}
enum Event: EventType {
/// The flow is being started.
case start
/// Request presentation of a member's profile.
case showMemberProfile
/// The member profile has been dismissed.
case dismissedMemberProfile
}
private let stateMachine: StateMachine<State, Event>
private let actionsSubject: PassthroughSubject<ExtraHomeTabAction, Never> = .init()
var actionsPublisher: AnyPublisher<ExtraHomeTabAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(flowParameters: CommonFlowParameters) {
self.flowParameters = flowParameters
navigationStackCoordinator = NavigationStackCoordinator()
stateMachine = StateMachine(state: .initial)
configureStateMachine()
}
func start() {
stateMachine.tryEvent(.start)
}
// MARK: - Private
private func configureStateMachine() {
stateMachine.addRoutes(event: .start, transitions: [.initial => .memberDirectory]) { [weak self] _ in
self?.presentMemberDirectory()
}
stateMachine.addRoutes(event: .showMemberProfile, transitions: [.memberDirectory => .memberProfile])
stateMachine.addRoutes(event: .dismissedMemberProfile, transitions: [.memberProfile => .memberDirectory])
stateMachine.addErrorHandler { context in
fatalError("Unexpected transition from `\(context.fromState)` to `\(context.toState)` for event `\(String(describing: context.event))`.")
}
}
private func presentMemberDirectory() {
let userSession = flowParameters.userSession
let apiService = HealthChatAPIService(tokenProvider: HealthChatOpenIDTokenProvider(clientProxy: userSession.clientProxy))
let coordinator = HealthChatMemberDirectoryScreenCoordinator(parameters: .init(apiService: apiService,
clientProxy: userSession.clientProxy,
mediaProvider: userSession.mediaProvider,
userIndicatorController: flowParameters.userIndicatorController))
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .selectMember(let userID):
presentMemberProfile(userID: userID)
case .presentRoom(let roomID):
actionsSubject.send(.presentRoom(roomID: roomID))
}
}
.store(in: &cancellables)
navigationStackCoordinator.setRootCoordinator(coordinator)
}
private func presentMemberProfile(userID: String) {
let parameters = UserProfileScreenCoordinatorParameters(userID: userID,
isPresentedModally: false,
userSession: flowParameters.userSession,
userIndicatorController: flowParameters.userIndicatorController,
analytics: flowParameters.analytics,
appSettings: flowParameters.appSettings,
appHooks: flowParameters.appHooks)
let coordinator = UserProfileScreenCoordinator(parameters: parameters)
coordinator.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .openDirectChat(let roomID):
actionsSubject.send(.presentRoom(roomID: roomID))
case .startCall(let roomProxy, let isVoiceCall):
actionsSubject.send(.presentCall(roomID: roomProxy.id, isVoiceCall: isVoiceCall))
case .dismiss:
navigationStackCoordinator.pop()
}
}
.store(in: &cancellables)
stateMachine.tryEvent(.showMemberProfile)
navigationStackCoordinator.push(coordinator) { [weak self] in
self?.stateMachine.tryEvent(.dismissedMemberProfile)
}
}
}
@@ -20,7 +20,7 @@ enum UserSessionFlowCoordinatorAction {
}
class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
enum HomeTab: Hashable { case chats, spaces, search }
enum HomeTab: Hashable { case chats, spaces, search, members }
private let navigationRootCoordinator: NavigationRootCoordinator
private let navigationTabCoordinator: NavigationTabCoordinator<HomeTab>
@@ -44,6 +44,8 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
private let searchTabNavigationStackCoordinator: NavigationStackCoordinator?
private let searchTabDetails: NavigationTabCoordinator<HomeTab>.TabDetails?
private let extraTabActions: AnyPublisher<ExtraHomeTabAction, Never>?
private var settingsFlowCoordinator: SettingsFlowCoordinator?
enum State: StateType {
@@ -128,6 +130,14 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
if let searchTabNavigationStackCoordinator, let searchTabDetails {
tabs.append(.init(coordinator: searchTabNavigationStackCoordinator, details: searchTabDetails))
}
if let extraTab = flowParameters.appHooks.homeTabsHook.makeExtraTab(flowParameters: flowParameters) {
tabs.append(extraTab.tab)
extraTabActions = extraTab.actions
} else {
extraTabActions = nil
}
navigationTabCoordinator.setTabs(tabs)
stateMachine = flowParameters.stateMachineFactory.makeUserSessionFlowStateMachine(state: .initial)
@@ -228,6 +238,17 @@ class UserSessionFlowCoordinator: FlowCoordinatorProtocol {
// swiftlint:disable:next function_body_length
private func setupObservers() {
extraTabActions?
.sink { [weak self] action in
switch action {
case .presentRoom(let roomID):
self?.handleAppRoute(.room(roomID: roomID, via: []), animated: true)
case .presentCall(let roomID, let isVoiceCall):
self?.handleAppRoute(.call(roomID: roomID, isVoiceCall: isVoiceCall), animated: true)
}
}
.store(in: &cancellables)
chatsTabFlowCoordinator.actionsPublisher
.sink { [weak self] action in
guard let self else { return }
@@ -26,6 +26,12 @@ internal nonisolated enum HealthChatL10n {
internal static var commonSpecialty: String { return HealthChatL10n.tr("HealthChat", "common_specialty") }
/// Website
internal static var commonWebsite: String { return HealthChatL10n.tr("HealthChat", "common_website") }
/// Your account is being reviewed. You’ll get access to the member directory once it has been approved.
internal static var screenMemberDirectoryPendingApproval: String { return HealthChatL10n.tr("HealthChat", "screen_member_directory_pending_approval") }
/// Name, practice, city or speciality
internal static var screenMemberDirectorySearchPlaceholder: String { return HealthChatL10n.tr("HealthChat", "screen_member_directory_search_placeholder") }
/// Members
internal static var screenMemberDirectoryTitle: String { return HealthChatL10n.tr("HealthChat", "screen_member_directory_title") }
}
// swiftlint:enable explicit_type_interface function_parameter_count identifier_name line_length
// swiftlint:enable nesting type_body_length type_name vertical_whitespace_opening_braces
@@ -57,6 +57,7 @@ enum TestablePreviewsDictionary {
"FullscreenDialog_Previews" : FullscreenDialog_Previews.self,
"GalleryRoomTimelineView_Previews" : GalleryRoomTimelineView_Previews.self,
"HealthChatExtendedProfileSection_Previews" : HealthChatExtendedProfileSection_Previews.self,
"HealthChatMemberDirectoryScreen_Previews" : HealthChatMemberDirectoryScreen_Previews.self,
"HighlightedTimelineItemModifier_Previews" : HighlightedTimelineItemModifier_Previews.self,
"HomeScreenEmptyStateView_Previews" : HomeScreenEmptyStateView_Previews.self,
"HomeScreenInviteCell_Previews" : HomeScreenInviteCell_Previews.self,
@@ -0,0 +1,56 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
import SwiftUI
struct HealthChatMemberDirectoryScreenCoordinatorParameters {
let apiService: HealthChatAPIServiceProtocol
let clientProxy: ClientProxyProtocol
let mediaProvider: MediaProviderProtocol
let userIndicatorController: UserIndicatorControllerProtocol
}
enum HealthChatMemberDirectoryScreenCoordinatorAction {
case selectMember(userID: String)
case presentRoom(roomID: String)
}
final class HealthChatMemberDirectoryScreenCoordinator: CoordinatorProtocol {
private let viewModel: HealthChatMemberDirectoryScreenViewModelProtocol
private var cancellables = Set<AnyCancellable>()
private let actionsSubject: PassthroughSubject<HealthChatMemberDirectoryScreenCoordinatorAction, Never> = .init()
var actionsPublisher: AnyPublisher<HealthChatMemberDirectoryScreenCoordinatorAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(parameters: HealthChatMemberDirectoryScreenCoordinatorParameters) {
viewModel = HealthChatMemberDirectoryScreenViewModel(apiService: parameters.apiService,
clientProxy: parameters.clientProxy,
mediaProvider: parameters.mediaProvider,
userIndicatorController: parameters.userIndicatorController)
}
func start() {
viewModel.actionsPublisher.sink { [weak self] action in
guard let self else { return }
switch action {
case .selectMember(let userID):
actionsSubject.send(.selectMember(userID: userID))
case .presentRoom(let roomID):
actionsSubject.send(.presentRoom(roomID: roomID))
}
}
.store(in: &cancellables)
}
func toPresentable() -> AnyView {
AnyView(HealthChatMemberDirectoryScreen(context: viewModel.context))
}
}
@@ -0,0 +1,41 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Foundation
enum HealthChatMemberDirectoryScreenViewModelAction {
case selectMember(userID: String)
case presentRoom(roomID: String)
}
nonisolated enum HealthChatMemberDirectoryScreenContent: Equatable {
case loading
case members([HealthChatMember])
case pendingApproval(message: String)
case failure
}
struct HealthChatMemberDirectoryScreenViewState: BindableState {
var content: HealthChatMemberDirectoryScreenContent = .loading
var bindings = HealthChatMemberDirectoryScreenViewStateBindings()
}
struct HealthChatMemberDirectoryScreenViewStateBindings {
var searchQuery = ""
var alertInfo: AlertInfo<HealthChatMemberDirectoryScreenAlertType>?
}
enum HealthChatMemberDirectoryScreenAlertType: Hashable {
case failedStartingChat
}
enum HealthChatMemberDirectoryScreenViewAction {
case retry
case selectMember(HealthChatMember)
case startChat(HealthChatMember)
}
@@ -0,0 +1,132 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import AsyncAlgorithms
import Combine
import SwiftUI
typealias HealthChatMemberDirectoryScreenViewModelType = StateStoreViewModelV2<HealthChatMemberDirectoryScreenViewState, HealthChatMemberDirectoryScreenViewAction>
class HealthChatMemberDirectoryScreenViewModel: HealthChatMemberDirectoryScreenViewModelType, HealthChatMemberDirectoryScreenViewModelProtocol {
private let apiService: HealthChatAPIServiceProtocol
private let clientProxy: ClientProxyProtocol
private let userIndicatorController: UserIndicatorControllerProtocol
private var searchQueryObservationTask: Task<Void, Never>?
// periphery:ignore - auto cancels when reassigned
@CancellableTask private var fetchTask: Task<Void, Never>?
private let actionsSubject: PassthroughSubject<HealthChatMemberDirectoryScreenViewModelAction, Never> = .init()
var actionsPublisher: AnyPublisher<HealthChatMemberDirectoryScreenViewModelAction, Never> {
actionsSubject.eraseToAnyPublisher()
}
init(apiService: HealthChatAPIServiceProtocol,
clientProxy: ClientProxyProtocol,
mediaProvider: MediaProviderProtocol,
userIndicatorController: UserIndicatorControllerProtocol) {
self.apiService = apiService
self.clientProxy = clientProxy
self.userIndicatorController = userIndicatorController
super.init(initialViewState: HealthChatMemberDirectoryScreenViewState(), mediaProvider: mediaProvider)
fetchMembers()
// The stream replays the current query, which the initial fetch above already covers.
let searchQueryStream = context.observe(\.viewState.bindings.searchQuery)
.debounce(for: .milliseconds(300))
.removeDuplicates()
.dropFirst()
searchQueryObservationTask = Task { [weak self] in
for await _ in searchQueryStream {
self?.fetchMembers()
}
}
}
isolated deinit {
searchQueryObservationTask?.cancel()
}
// MARK: - Public
override func process(viewAction: HealthChatMemberDirectoryScreenViewAction) {
switch viewAction {
case .retry:
state.content = .loading
fetchMembers()
case .selectMember(let member):
actionsSubject.send(.selectMember(userID: member.userID))
case .startChat(let member):
Task { await startChat(with: member) }
}
}
// MARK: - Private
private func fetchMembers() {
fetchTask = Task { [weak self] in
guard let self else { return }
let searchQuery = state.bindings.searchQuery
let result = await apiService.members(searchQuery: searchQuery.isEmpty ? nil : searchQuery)
guard !Task.isCancelled else { return }
switch result {
case .success(let response) where !response.isApproved:
state.content = .pendingApproval(message: response.pendingMessage ?? HealthChatL10n.screenMemberDirectoryPendingApproval)
case .success(let response):
state.content = .members(response.users)
case .failure:
state.content = .failure
}
}
}
private func startChat(with member: HealthChatMember) async {
switch clientProxy.directRoomForUserID(member.userID) {
case .success(let roomID?):
actionsSubject.send(.presentRoom(roomID: roomID))
case .success(nil):
showLoadingIndicator()
defer { hideLoadingIndicator() }
switch await clientProxy.createDirectRoom(with: member.userID, expectedRoomName: member.displayName) {
case .success(let roomID):
actionsSubject.send(.presentRoom(roomID: roomID))
case .failure:
state.bindings.alertInfo = .init(id: .failedStartingChat,
title: L10n.commonError,
message: L10n.screenStartChatErrorStartingChat)
}
case .failure:
state.bindings.alertInfo = .init(id: .failedStartingChat,
title: L10n.commonError,
message: L10n.screenStartChatErrorStartingChat)
}
}
// MARK: User Indicators
private var loadingIndicatorIdentifier: String {
"\(Self.self)-Loading"
}
private func showLoadingIndicator() {
userIndicatorController.submitIndicator(UserIndicator(id: loadingIndicatorIdentifier,
type: .modal(progress: .indeterminate, interactiveDismissDisabled: false, allowsInteraction: false),
title: L10n.commonLoading,
persistent: true),
delay: .milliseconds(100))
}
private func hideLoadingIndicator() {
userIndicatorController.retractIndicatorWithId(loadingIndicatorIdentifier)
}
}
@@ -0,0 +1,14 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Combine
@MainActor
protocol HealthChatMemberDirectoryScreenViewModelProtocol {
var actionsPublisher: AnyPublisher<HealthChatMemberDirectoryScreenViewModelAction, Never> { get }
var context: HealthChatMemberDirectoryScreenViewModelType.Context { get }
}
@@ -0,0 +1,165 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Compound
import SwiftUI
struct HealthChatMemberDirectoryScreen: View {
@Bindable var context: HealthChatMemberDirectoryScreenViewModel.Context
var body: some View {
content
.navigationTitle(HealthChatL10n.screenMemberDirectoryTitle)
.navigationBarTitleDisplayMode(.inline)
.background(Color.compound.bgCanvasDefault.ignoresSafeArea())
.searchController(query: $context.searchQuery,
placeholder: HealthChatL10n.screenMemberDirectorySearchPlaceholder)
.alert(item: $context.alertInfo)
}
// MARK: - Private
@ViewBuilder
private var content: some View {
switch context.viewState.content {
case .loading:
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
case .pendingApproval(let message):
statusView(icon: \.time, message: message)
case .failure:
failureView
case .members(let members) where members.isEmpty:
statusView(icon: \.search, message: L10n.commonNoResults)
case .members(let members):
memberList(members)
}
}
private func memberList(_ members: [HealthChatMember]) -> some View {
Form {
Section {
ForEach(members) { member in
HealthChatMemberListRow(member: member, mediaProvider: context.mediaProvider) {
context.send(viewAction: .selectMember(member))
} startChatAction: {
context.send(viewAction: .startChat(member))
}
}
}
}
.compoundList()
}
private var failureView: some View {
VStack(spacing: 16) {
statusContent(icon: \.error, message: L10n.commonSomethingWentWrong)
Button(L10n.actionRetry) {
context.send(viewAction: .retry)
}
.buttonStyle(.compound(.secondary, size: .medium))
.fixedSize()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(16)
}
private func statusView(icon: KeyPath<CompoundIcons, Image>, message: String) -> some View {
statusContent(icon: icon, message: message)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(16)
}
private func statusContent(icon: KeyPath<CompoundIcons, Image>, message: String) -> some View {
VStack(spacing: 16) {
BigIcon(icon: icon)
Text(message)
.font(.compound.bodyLG)
.foregroundColor(.compound.textSecondary)
.multilineTextAlignment(.center)
}
}
}
// MARK: - Previews
struct HealthChatMemberDirectoryScreen_Previews: PreviewProvider, TestablePreview {
static let loadedViewModel = makeViewModel(configuration: .members)
static let pendingViewModel = makeViewModel(configuration: .pendingApproval)
static let failureViewModel = makeViewModel(configuration: .failure)
static var previews: some View {
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: loadedViewModel.context)
}
.snapshotPreferences(expect: loadedViewModel.context.observe(\.viewState.content).map { $0 != .loading })
.previewDisplayName("Members")
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: pendingViewModel.context)
}
.snapshotPreferences(expect: pendingViewModel.context.observe(\.viewState.content).map { $0 != .loading })
.previewDisplayName("Pending approval")
ElementNavigationStack {
HealthChatMemberDirectoryScreen(context: failureViewModel.context)
}
.snapshotPreferences(expect: failureViewModel.context.observe(\.viewState.content).map { $0 != .loading })
.previewDisplayName("Failure")
}
enum PreviewConfiguration {
case members
case pendingApproval
case failure
}
static func makeViewModel(configuration: PreviewConfiguration) -> HealthChatMemberDirectoryScreenViewModel {
let apiService = HealthChatAPIServiceMock()
switch configuration {
case .members:
let members = try? JSONDecoder().decode([HealthChatMember].self, from: Data("""
[
{
"userId": "@alice:healthchat.ch",
"displayName": "Dr. Alice Alpha",
"specialty": "Physiotherapie",
"practiceName": "Praxis Alpha",
"businessCity": "Zürich"
},
{
"userId": "@bob:healthchat.ch",
"displayName": "Bob Beta",
"specialty": "Ergotherapie",
"businessCity": "Basel"
},
{
"userId": "@carol:healthchat.ch",
"displayName": "Dr. Carol Gamma"
}
]
""".utf8))
apiService.membersSearchQueryReturnValue = .success(.init(users: members ?? [],
isApproved: true,
pendingMessage: nil))
case .pendingApproval:
apiService.membersSearchQueryReturnValue = .success(.init(users: [],
isApproved: false,
pendingMessage: "Ihr Konto wird derzeit geprüft. Sie erhalten Zugriff auf das Mitgliederverzeichnis, sobald Ihr Konto freigegeben wurde."))
case .failure:
apiService.membersSearchQueryReturnValue = .failure(.networkFailure)
}
return HealthChatMemberDirectoryScreenViewModel(apiService: apiService,
clientProxy: ClientProxyMock(.init()),
mediaProvider: MediaProviderMock(.init()),
userIndicatorController: UserIndicatorControllerMock())
}
}
@@ -0,0 +1,65 @@
//
// Copyright 2026 Novaloop AG
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
// Please see LICENSE files in the repository root for full details.
//
import Compound
import SwiftUI
struct HealthChatMemberListRow: View {
let member: HealthChatMember
let mediaProvider: MediaProviderProtocol?
let selectAction: () -> Void
let startChatAction: () -> Void
private var subtitle: String {
[member.specialty, member.practiceName, member.businessCity]
.compactMap { $0 }
.joined(separator: " · ")
}
var body: some View {
ListRow(kind: .custom {
HStack(spacing: 12) {
Button(action: selectAction) {
HStack(spacing: 12) {
LoadableAvatarImage(url: member.avatarURL,
name: member.displayName,
contentID: member.userID,
avatarSize: .user(on: .startChat),
mediaProvider: mediaProvider)
VStack(alignment: .leading, spacing: 2) {
Text(member.displayName ?? member.userID)
.font(.compound.bodyLGSemibold)
.foregroundColor(.compound.textPrimary)
.lineLimit(1)
if !subtitle.isEmpty {
Text(subtitle)
.font(.compound.bodySM)
.foregroundColor(.compound.textSecondary)
.lineLimit(2)
}
}
Spacer()
}
.contentShape(Rectangle())
}
.buttonStyle(.plain)
Button(action: startChatAction) {
CompoundIcon(\.chat)
.foregroundColor(.compound.iconAccentTertiary)
}
.buttonStyle(.borderless)
.accessibilityLabel(L10n.actionStartChat)
}
.padding(.horizontal, ListRowPadding.horizontal)
.padding(.vertical, 8)
})
}
}