Skip to content

Commit

Permalink
Migrate TCA to 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
chihchy committed Jul 10, 2024
1 parent 07a28ef commit 8acab4d
Show file tree
Hide file tree
Showing 45 changed files with 270 additions and 203 deletions.
6 changes: 3 additions & 3 deletions EhPanda.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2475,7 +2475,7 @@
repositoryURL = "https://github.com/pointfreeco/swift-composable-architecture.git";
requirement = {
kind = exactVersion;
version = 1.0.0;
version = 1.4.2;
};
};
ABAC82FC26BC4866009F5026 /* XCRemoteSwiftPackageReference "SwiftyOpenCC" */ = {
Expand All @@ -2490,8 +2490,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/pointfreeco/swiftui-navigation.git";
requirement = {
kind = exactVersion;
version = 1.0.0;
kind = upToNextMajorVersion;
minimumVersion = 1.0.0;
};
};
ABC4A0772751B40E00968A4F /* XCRemoteSwiftPackageReference "Kingfisher" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture.git",
"state" : {
"revision" : "195284b94b799b326729640453f547f08892293a",
"version" : "1.0.0"
"revision" : "eddc1869b37ce42e3b34e72b1e1355d049e73970",
"version" : "1.4.2"
}
},
{
Expand Down Expand Up @@ -150,8 +150,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "303e5c5c36d6a558407d364878df131c3546fad8",
"version" : "510.0.2"
"revision" : "64889f0c732f210a935a0ad7cda38f77f876262d",
"version" : "509.1.1"
}
},
{
Expand All @@ -168,8 +168,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swiftui-navigation.git",
"state" : {
"revision" : "f5bcdac5b6bb3f826916b14705f37a3937c2fd34",
"version" : "1.0.0"
"revision" : "b7c9a79f6f6b1fefb87d3e5a83a9c2fe7cdc9720",
"version" : "1.5.0"
}
},
{
Expand Down
28 changes: 6 additions & 22 deletions EhPanda/App/Tools/Extensions/SwiftUINavigation_Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension NavigationLink {
self.init(
title,
destination: Binding(unwrapping: value).map(destination),
isActive: value.isPresent()
isActive: .init(value)
)
}
init<Enum, Case, WrappedDestination>(
Expand All @@ -34,32 +34,16 @@ extension NavigationLink {
}

extension View {
@MainActor
@ViewBuilder
func sheet<Enum, Case, Content>(
unwrapping enum: Binding<Enum?>,
case casePath: AnyCasePath<Enum, Case>,
onDismiss: (() -> Void)? = nil,
isEnabled: Bool,
@ViewBuilder content: @escaping (Binding<Case>) -> Content
) -> some View
where Content: View {
if isEnabled {
sheet(unwrapping: `enum`, case: casePath, onDismiss: onDismiss, content: content)
} else {
self
}
}
func confirmationDialog<Enum, Case, A: View>(
message: String,
unwrapping enum: Binding<Enum?>,
case casePath: AnyCasePath<Enum, Case>,
@ViewBuilder actions: @escaping (Case) -> A
) -> some View {
self.confirmationDialog(
title: { _ in Text("") },
item: `enum`.case(casePath),
titleVisibility: .hidden,
unwrapping: `enum`.case(casePath),
title: { _ in Text("") },
actions: actions,
message: { _ in Text(message) }
)
Expand All @@ -72,13 +56,13 @@ extension View {
@ViewBuilder actions: @escaping (Case) -> A
) -> some View {
self.confirmationDialog(
title: { _ in Text("") },
titleVisibility: .hidden,
unwrapping: {
item: {
let unwrapping = `enum`.case(casePath)
let isMatched = `case` == unwrapping.wrappedValue
return isMatched ? unwrapping : .constant(nil)
}(),
titleVisibility: .hidden,
title: { _ in Text("") },
actions: actions,
message: { _ in Text(message) }
)
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/DataFlow/AppDelegateReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import SwiftUI
import SwiftyBeaver
import ComposableArchitecture

struct AppDelegateReducer: Reducer {
@Reducer
struct AppDelegateReducer {
struct State: Equatable {
var migrationState = MigrationReducer.State()
}
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/DataFlow/AppLockReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import SwiftUI
import ComposableArchitecture

struct AppLockReducer: Reducer {
@Reducer
struct AppLockReducer {
struct State: Equatable {
@BindingState var blurRadius: Double = 0
var becameInactiveDate: Date?
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/DataFlow/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import SwiftUI
import ComposableArchitecture

struct AppReducer: Reducer {
@Reducer
struct AppReducer {
struct State: Equatable {
var appDelegateState = AppDelegateReducer.State()
@BindingState var appRouteState = AppRouteReducer.State()
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/DataFlow/AppRouteReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import SwiftUI
import TTProgressHUD
import ComposableArchitecture

struct AppRouteReducer: Reducer {
@Reducer
struct AppRouteReducer {
@CasePathable
enum Route: Equatable, Hashable {
case hud
case setting
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/View/Detail/Archives/ArchivesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Foundation
import TTProgressHUD
import ComposableArchitecture

struct ArchivesReducer: Reducer {
@Reducer
struct ArchivesReducer {
enum Route {
case messageHUD
case communicatingHUD
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/View/Detail/Comments/CommentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Foundation
import TTProgressHUD
import ComposableArchitecture

struct CommentsReducer: Reducer {
@Reducer
struct CommentsReducer {
@CasePathable
enum Route: Equatable {
case hud
case detail(String)
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/View/Detail/DetailReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import SwiftUI
import Foundation
import ComposableArchitecture

struct DetailReducer: Reducer {
@Reducer
struct DetailReducer {
@CasePathable
enum Route: Equatable {
case reading
case archives(URL, URL)
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import ComposableArchitecture

struct DetailSearchReducer: Reducer {
@Reducer
struct DetailSearchReducer {
@CasePathable
enum Route: Equatable {
case filters
case quickSearch
Expand Down
31 changes: 17 additions & 14 deletions EhPanda/View/Detail/DetailSearch/DetailSearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct DetailSearchView: View {
}

var body: some View {
let content =
GenericList(
galleries: viewStore.galleries,
setting: setting,
Expand All @@ -44,20 +45,6 @@ struct DetailSearchView: View {
tagTranslator.lookup(word: $0, returnOriginal: !setting.translatesTags)
}
)
.sheet(
unwrapping: viewStore.$route,
case: /DetailSearchReducer.Route.detail,
isEnabled: DeviceUtil.isPad
) { route in
NavigationView {
DetailView(
store: store.scope(state: \.detailState, action: DetailSearchReducer.Action.detail),
gid: route.wrappedValue, user: user, setting: $setting,
blurRadius: blurRadius, tagTranslator: tagTranslator
)
}
.autoBlur(radius: blurRadius).environment(\.inSheet, true).navigationViewStyle(.stack)
}
.sheet(unwrapping: viewStore.$route, case: /DetailSearchReducer.Route.quickSearch) { _ in
QuickSearchView(
store: store.scope(state: \.quickDetailSearchState, action: DetailSearchReducer.Action.quickSearch)
Expand Down Expand Up @@ -92,6 +79,22 @@ struct DetailSearchView: View {
.background(navigationLink)
.toolbar(content: toolbar)
.navigationTitle(viewStore.lastKeyword)

if DeviceUtil.isPad {
content
.sheet(unwrapping: viewStore.$route, case: /DetailSearchReducer.Route.detail) { route in
NavigationView {
DetailView(
store: store.scope(state: \.detailState, action: DetailSearchReducer.Action.detail),
gid: route.wrappedValue, user: user, setting: $setting,
blurRadius: blurRadius, tagTranslator: tagTranslator
)
}
.autoBlur(radius: blurRadius).environment(\.inSheet, true).navigationViewStyle(.stack)
}
} else {
content
}
}

@ViewBuilder private var navigationLink: some View {
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/View/Detail/GalleryInfos/GalleryInfosReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import TTProgressHUD
import ComposableArchitecture

struct GalleryInfosReducer: Reducer {
@Reducer
struct GalleryInfosReducer {
enum Route {
case hud
}
Expand Down
3 changes: 2 additions & 1 deletion EhPanda/View/Detail/Previews/PreviewsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import Foundation
import ComposableArchitecture

struct PreviewsReducer: Reducer {
@Reducer
struct PreviewsReducer {
enum Route {
case reading
}
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/View/Detail/Torrents/TorrentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import Foundation
import TTProgressHUD
import ComposableArchitecture

struct TorrentsReducer: Reducer {
@Reducer
struct TorrentsReducer {
@CasePathable
enum Route: Equatable {
case hud
case share(URL)
Expand Down
4 changes: 3 additions & 1 deletion EhPanda/View/Favorites/FavoritesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import SwiftUI
import IdentifiedCollections
import ComposableArchitecture

struct FavoritesReducer: Reducer {
@Reducer
struct FavoritesReducer {
@CasePathable
enum Route: Equatable {
case quickSearch
case detail(String)
Expand Down
31 changes: 17 additions & 14 deletions EhPanda/View/Favorites/FavoritesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct FavoritesView: View {

var body: some View {
NavigationView {
let content =
ZStack {
if CookieUtil.didLogin {
GenericList(
Expand All @@ -55,20 +56,6 @@ struct FavoritesView: View {
NotLoginView(action: { viewStore.send(.onNotLoginViewButtonTapped) })
}
}
.sheet(
unwrapping: viewStore.$route,
case: /FavoritesReducer.Route.detail,
isEnabled: DeviceUtil.isPad
) { route in
NavigationView {
DetailView(
store: store.scope(state: \.detailState, action: FavoritesReducer.Action.detail),
gid: route.wrappedValue, user: user, setting: $setting,
blurRadius: blurRadius, tagTranslator: tagTranslator
)
}
.autoBlur(radius: blurRadius).environment(\.inSheet, true).navigationViewStyle(.stack)
}
.sheet(unwrapping: viewStore.$route, case: /FavoritesReducer.Route.quickSearch) { _ in
QuickSearchView(
store: store.scope(state: \.quickSearchState, action: FavoritesReducer.Action.quickSearch)
Expand Down Expand Up @@ -99,6 +86,22 @@ struct FavoritesView: View {
.background(navigationLink)
.toolbar(content: toolbar)
.navigationTitle(navigationTitle)

if DeviceUtil.isPad {
content
.sheet(unwrapping: viewStore.$route, case: /FavoritesReducer.Route.detail) { route in
NavigationView {
DetailView(
store: store.scope(state: \.detailState, action: FavoritesReducer.Action.detail),
gid: route.wrappedValue, user: user, setting: $setting,
blurRadius: blurRadius, tagTranslator: tagTranslator
)
}
.autoBlur(radius: blurRadius).environment(\.inSheet, true).navigationViewStyle(.stack)
}
} else {
content
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion EhPanda/View/Home/Frontpage/FrontpageReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import ComposableArchitecture

struct FrontpageReducer: Reducer {
@Reducer
struct FrontpageReducer {
@CasePathable
enum Route: Equatable {
case filters
case detail(String)
Expand Down
Loading

0 comments on commit 8acab4d

Please sign in to comment.