Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-2598 Space sharing | Remove "stop share" button #1131

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ struct SpaceShareView: View {
.task {
await model.startParticipantsTask()
}
.task {
await model.startSpaceViewTask()
}
.task {
await model.onAppear()
}
Expand Down Expand Up @@ -82,8 +85,10 @@ struct SpaceShareView: View {
Button(Loc.SpaceShare.moreInfo) {
model.onMoreInfoTap()
}
Button(Loc.SpaceShare.StopSharing.action, role: .destructive) {
model.onStopSharing()
if model.canStopShare {
Button(Loc.SpaceShare.StopSharing.action, role: .destructive) {
model.onStopSharing()
}
}
} label: {
IconView(icon: .asset(.X24.more))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ final class SpaceShareViewModel: ObservableObject {
private var activeWorkspaceStorage: ActiveWorkpaceStorageProtocol
@Injected(\.deepLinkParser)
private var deppLinkParser: DeepLinkParserProtocol
@Injected(\.workspaceStorage)
private var workspaceStorage: WorkspacesStorageProtocol

private var onMoreInfo: () -> Void
private var participants: [Participant] = []
private lazy var workspaceInfo = activeWorkspaceStorage.workspaceInfo
private var spaceView: SpaceView?

var accountSpaceId: String { workspaceInfo.accountSpaceId }

var accountSpaceId: String { activeWorkspaceStorage.workspaceInfo.accountSpaceId }
@Published var rows: [SpaceShareParticipantViewModel] = []
@Published var inviteLink: URL?
@Published var shareInviteLink: URL?
Expand All @@ -35,6 +40,7 @@ final class SpaceShareViewModel: ObservableObject {
@Published var removeParticipantAlertModel: SpaceParticipantRemoveViewModel?
@Published var showDeleteLinkAlert = false
@Published var showStopSharingAlert = false
@Published var canStopShare = false

nonisolated init(onMoreInfo: @escaping () -> Void) {
self.onMoreInfo = onMoreInfo
Expand All @@ -46,6 +52,12 @@ final class SpaceShareViewModel: ObservableObject {
}
}

func startSpaceViewTask() async {
for await spaceView in workspaceStorage.spaceViewPublisher(spaceId: accountSpaceId).values {
canStopShare = spaceView.canStopShare
}
}

func onAppear() async {
do {
let invite = try await workspaceService.getCurrentInvite(spaceId: accountSpaceId)
Expand Down Expand Up @@ -96,7 +108,7 @@ final class SpaceShareViewModel: ObservableObject {
private func updateParticipant(items: [Participant]) {
participants = items.sorted { $0.sortingWeight > $1.sortingWeight }
rows = participants.map { participant in
let isYou = activeWorkspaceStorage.workspaceInfo.profileObjectID == participant.identityProfileLink
let isYou = workspaceInfo.profileObjectID == participant.identityProfileLink
return SpaceShareParticipantViewModel(
id: participant.id,
icon: participant.icon?.icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ extension SpaceView {
accountStatus == .spaceJoining
}

var canStopShare: Bool {
isShared
}

var isActive: Bool {
localStatus == .ok && accountStatus != .spaceRemoving && accountStatus != .spaceDeleted
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ extension WorkspacesStorageProtocol {
.removeDuplicates()
.eraseToAnyPublisher()
}

func spaceViewPublisher(spaceId: String) -> AnyPublisher<SpaceView, Never> {
allWorkspsacesPublisher.compactMap { $0.first { $0.targetSpaceId == spaceId } }
.removeDuplicates()
.eraseToAnyPublisher()
}
}

@MainActor
Expand Down
Loading