Skip to content

Commit def5fb0

Browse files
authored
Rewrite LiveTranslationFeature to TCA (#97)
* ♻️ rename LiveTranslationView and create LiveTranslation * ♻️ almost all implementation without handleResponseChat and handleResponseTranslation * 🎉 complete state and action reducer * ♻️ try to replace TCA version * 🚧 remove old files * 🐛 fix translation bug * ✨ add reload button * ♻️ format * add #91 changes * resolved package * ♻️ rewrite send action to call function * ♻️ use liveValue directly * ♻️ implement BuildConfig
1 parent ec86d1d commit def5fb0

File tree

8 files changed

+684
-465
lines changed

8 files changed

+684
-465
lines changed

MyLibrary/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MyLibrary/Package.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ let package = Package(
4242
"trySwiftFeature",
4343
]
4444
),
45+
.target(
46+
name: "BuildConfig",
47+
dependencies: [
48+
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
49+
]
50+
),
4551
.target(
4652
name: "DataClient",
4753
dependencies: [
@@ -69,6 +75,7 @@ let package = Package(
6975
.target(
7076
name: "LiveTranslationFeature",
7177
dependencies: [
78+
"BuildConfig",
7279
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
7380
.product(name: "rtt-sdk", package: "rtt_sdk"),
7481
]

MyLibrary/Sources/AppFeature/AppView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public struct AppReducer {
1313
@ObservableState
1414
public struct State: Equatable {
1515
var schedule = Schedule.State()
16+
var liveTranslation = LiveTranslation.State()
1617
var guidance = Guidance.State()
1718
var sponsors = SponsorsList.State()
1819
var trySwift = TrySwift.State()
@@ -24,6 +25,7 @@ public struct AppReducer {
2425

2526
public enum Action {
2627
case schedule(Schedule.Action)
28+
case liveTranslation(LiveTranslation.Action)
2729
case guidance(Guidance.Action)
2830
case sponsors(SponsorsList.Action)
2931
case trySwift(TrySwift.Action)
@@ -35,6 +37,9 @@ public struct AppReducer {
3537
Scope(state: \.schedule, action: \.schedule) {
3638
Schedule()
3739
}
40+
Scope(state: \.liveTranslation, action: \.liveTranslation) {
41+
LiveTranslation()
42+
}
3843
Scope(state: \.guidance, action: \.guidance) {
3944
Guidance()
4045
}
@@ -60,7 +65,7 @@ public struct AppView: View {
6065
.tabItem {
6166
Label(String(localized: "Schedule", bundle: .module), systemImage: "calendar")
6267
}
63-
LiveTranslationView()
68+
LiveTranslationView(store: store.scope(state: \.liveTranslation, action: \.liveTranslation))
6469
.tabItem {
6570
Label(String(localized: "Translation", bundle: .module), systemImage: "text.bubble")
6671
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Dependencies
2+
import Foundation
3+
import DependenciesMacros
4+
5+
@DependencyClient
6+
public struct BuildConfig {
7+
public var liveTranslationRoomNumber: () -> String = { "" }
8+
}
9+
10+
extension DependencyValues {
11+
public var buildConfig: BuildConfig {
12+
get { self[BuildConfig.self] }
13+
set { self[BuildConfig.self] = newValue }
14+
}
15+
}
16+
17+
extension BuildConfig: DependencyKey {
18+
public static let liveValue: Self = Self(
19+
liveTranslationRoomNumber: {
20+
ProcessInfo.processInfo.environment["LIVE_TRANSLATION_KEY"]
21+
?? (Bundle.main.infoDictionary?["Live translation room number"] as? String) ?? ""
22+
}
23+
)
24+
}

0 commit comments

Comments
 (0)