Files
element-x-ios/ElementX/Sources/Screens/HealthChatMemberDirectoryScreen/View/HealthChatMemberDirectoryScreen.swift
T
joel.poyet c0f167ccf7 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
2026-10-19 09:17:31 +02:00

166 lines
6.4 KiB
Swift

//
// 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())
}
}