mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Add share link in start chat flow (#926)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// Copyright 2023 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MatrixUserShareLink<Label: View>: View {
|
||||
private let permalink: URL?
|
||||
private let label: Label
|
||||
|
||||
init(userID: String, @ViewBuilder label: () -> Label) {
|
||||
self.label = label()
|
||||
permalink = try? PermalinkBuilder.permalinkTo(userIdentifier: userID)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if let permalink {
|
||||
ShareLink(item: L10n.inviteFriendsText(InfoPlistReader.main.bundleDisplayName, permalink.absoluteString)) {
|
||||
label
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct MatrixUserPermalink_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
MatrixUserShareLink(userID: "@someone:somewhere.org") {
|
||||
Label("Share", systemImage: "square.and.arrow.up")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,9 +71,6 @@ struct HomeScreenViewState: BindableState {
|
||||
var rooms: [HomeScreenRoom] = []
|
||||
var roomListMode: HomeScreenRoomListMode = .skeletons
|
||||
|
||||
/// The URL that will be shared when inviting friends to use the app.
|
||||
let invitePermalink: URL?
|
||||
|
||||
var hasPendingInvitations = false
|
||||
var hasUnreadPendingInvitations = false
|
||||
|
||||
|
||||
@@ -40,8 +40,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
|
||||
allRoomsSummaryProvider = userSession.clientProxy.allRoomsSummaryProvider
|
||||
invitesSummaryProvider = userSession.clientProxy.invitesSummaryProvider
|
||||
|
||||
let invitePermalink = try? PermalinkBuilder.permalinkTo(userIdentifier: userSession.userID)
|
||||
super.init(initialViewState: HomeScreenViewState(userID: userSession.userID, invitePermalink: invitePermalink),
|
||||
super.init(initialViewState: HomeScreenViewState(userID: userSession.userID),
|
||||
imageProvider: userSession.mediaProvider)
|
||||
|
||||
userSession.callbacks
|
||||
|
||||
@@ -139,10 +139,8 @@ struct HomeScreen: View {
|
||||
}
|
||||
}
|
||||
Section {
|
||||
if let permalink = context.viewState.invitePermalink {
|
||||
ShareLink(item: permalink) {
|
||||
Label(L10n.actionInvite, systemImage: "square.and.arrow.up")
|
||||
}
|
||||
MatrixUserShareLink(userID: context.viewState.userID) {
|
||||
Label(L10n.actionInvite, systemImage: "square.and.arrow.up")
|
||||
}
|
||||
Button(action: feedback) {
|
||||
Label(L10n.commonReportABug, systemImage: "questionmark.circle")
|
||||
|
||||
@@ -28,6 +28,7 @@ enum StartChatScreenViewModelAction {
|
||||
}
|
||||
|
||||
struct StartChatScreenViewState: BindableState {
|
||||
let userID: String
|
||||
var bindings = StartChatScreenViewStateBindings()
|
||||
var usersSection: UserDiscoverySection = .init(type: .suggestions, users: [])
|
||||
|
||||
@@ -50,6 +51,5 @@ struct StartChatScreenViewStateBindings {
|
||||
enum StartChatScreenViewAction {
|
||||
case close
|
||||
case createRoom
|
||||
case inviteFriends
|
||||
case selectUser(UserProfile)
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
|
||||
self.userSession = userSession
|
||||
self.userIndicatorController = userIndicatorController
|
||||
self.userDiscoveryService = userDiscoveryService
|
||||
super.init(initialViewState: StartChatScreenViewState(), imageProvider: userSession.mediaProvider)
|
||||
super.init(initialViewState: StartChatScreenViewState(userID: userSession.userID), imageProvider: userSession.mediaProvider)
|
||||
|
||||
setupBindings()
|
||||
}
|
||||
@@ -47,8 +47,6 @@ class StartChatScreenViewModel: StartChatScreenViewModelType, StartChatScreenVie
|
||||
actionsSubject.send(.close)
|
||||
case .createRoom:
|
||||
actionsSubject.send(.createRoom)
|
||||
case .inviteFriends:
|
||||
break
|
||||
case .selectUser(let user):
|
||||
showLoadingIndicator()
|
||||
Task {
|
||||
|
||||
@@ -74,7 +74,7 @@ struct StartChatScreen: View {
|
||||
|
||||
private var inviteFriendsSection: some View {
|
||||
Section {
|
||||
Button(action: inviteFriends) {
|
||||
MatrixUserShareLink(userID: context.viewState.userID) {
|
||||
Label(L10n.actionInviteFriendsToApp(InfoPlistReader.main.bundleDisplayName), systemImage: "square.and.arrow.up")
|
||||
}
|
||||
.buttonStyle(FormButtonStyle())
|
||||
@@ -121,10 +121,6 @@ struct StartChatScreen: View {
|
||||
context.send(viewAction: .createRoom)
|
||||
}
|
||||
|
||||
private func inviteFriends() {
|
||||
context.send(viewAction: .inviteFriends)
|
||||
}
|
||||
|
||||
private func close() {
|
||||
context.send(viewAction: .close)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user