Skip to content

Commit

Permalink
feat: 🎸 invite friend shared text
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun committed Nov 29, 2023
1 parent 660a11c commit 0cec85a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions Packages/GodPackage/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ let package = Package(
.product(name: "ProfileImage", package: "UIComponentPackage"),
.product(name: "ContactsClient", package: "CupertinoPackage"),
.product(name: "AnalyticsClient", package: "DependencyPackage"),
.product(name: "ShareLinkClient", package: "DependencyPackage"),
.product(name: "ShareLinkBuilder", package: "DependencyPackage"),
.product(name: "UIPasteboardClient", package: "CupertinoPackage"),
.product(name: "UIApplicationClient", package: "CupertinoPackage"),
Expand Down Expand Up @@ -198,6 +199,7 @@ let package = Package(
.product(name: "ProfileImage", package: "UIComponentPackage"),
.product(name: "RoundedCorner", package: "UIComponentPackage"),
.product(name: "AnalyticsClient", package: "DependencyPackage"),
.product(name: "ShareLinkClient", package: "DependencyPackage"),
.product(name: "ShareLinkBuilder", package: "DependencyPackage"),
], resources: [.copy("Invited.json")]),
.target(name: "LaunchFeature", dependencies: [
Expand Down Expand Up @@ -237,6 +239,7 @@ let package = Package(
.product(name: "ActivityView", package: "UIComponentPackage"),
.product(name: "StringHelpers", package: "DependencyPackage"),
.product(name: "ContactsClient", package: "CupertinoPackage"),
.product(name: "ShareLinkClient", package: "DependencyPackage"),
.product(name: "ShareLinkBuilder", package: "DependencyPackage"),
.product(name: "UIPasteboardClient", package: "CupertinoPackage"),
.product(name: "UserDefaultsClient", package: "CupertinoPackage"),
Expand All @@ -251,6 +254,7 @@ let package = Package(
.product(name: "GodClient", package: "DependencyPackage"),
.product(name: "Styleguide", package: "UIComponentPackage"),
.product(name: "AnalyticsClient", package: "DependencyPackage"),
.product(name: "ShareLinkClient", package: "DependencyPackage"),
.product(name: "ShareLinkBuilder", package: "DependencyPackage"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
Expand Down Expand Up @@ -297,6 +301,7 @@ let package = Package(
.product(name: "Constants", package: "DependencyPackage"),
.product(name: "GodClient", package: "DependencyPackage"),
.product(name: "AnalyticsClient", package: "DependencyPackage"),
.product(name: "ShareLinkClient", package: "DependencyPackage"),
.product(name: "ShareLinkBuilder", package: "DependencyPackage"),
.product(name: "UIPasteboardClient", package: "CupertinoPackage"),
.product(name: "UIApplicationClient", package: "CupertinoPackage"),
Expand Down
23 changes: 13 additions & 10 deletions Packages/GodPackage/Sources/InviteFriendFeature/InviteFriend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ComposableArchitecture
import God
import GodClient
import Lottie
import ShareLinkClient
import ShareLinkBuilder
import Styleguide
import SwiftUI
Expand Down Expand Up @@ -51,7 +52,7 @@ public struct InviteFriendLogic {
}

public struct State: Equatable {
var shareURL = URL(string: "https://godapp.jp")!
var sharedText = ""
var remainingInvitationCount: Int {
invites.filter { !$0 }.count
}
Expand All @@ -69,6 +70,7 @@ public struct InviteFriendLogic {
case whyFriendsButtonTapped
case inviteFriendButtonTapped
case currentUserResponse(TaskResult<God.CurrentUserQuery.Data>)
case generateSharedTextResponse(Result<String, Error>)
case onCompletion(CompletionWithItems)
case binding(BindingAction<State>)
case receivedActivity(ReceivedActivityLogic.Action)
Expand All @@ -82,6 +84,7 @@ public struct InviteFriendLogic {

@Dependency(\.godClient) var godClient
@Dependency(\.analytics) var analytics
@Dependency(\.shareLink.generateSharedText) var generateSharedText

enum Cancel {
case currentUser
Expand Down Expand Up @@ -135,14 +138,14 @@ public struct InviteFriendLogic {

case let .currentUserResponse(.success(data)):
state.receivedActivity = .init(currentUser: data.currentUser)
guard let username = data.currentUser.username
else { return .none }
state.shareURL = ShareLinkBuilder.buildGodLink(
path: .invite,
username: username,
source: .share,
medium: .requiredInvite
)
return .run { send in
await send(.generateSharedTextResponse(Result {
try await generateSharedText(.invite, .share, .requiredInvite)
}))
}

case let .generateSharedTextResponse(.success(text)):
state.sharedText = text
return .none

case let .onCompletion(completion):
Expand Down Expand Up @@ -301,7 +304,7 @@ public struct InviteFriendView: View {
store: store.scope(state: \.$destination.activity, action: \.destination.activity)
) { _ in
ActivityView(
activityItems: [viewStore.shareURL],
activityItems: [viewStore.sharedText],
applicationActivities: nil
) { activityType, result, _, _ in
store.send(
Expand Down

0 comments on commit 0cec85a

Please sign in to comment.