Skip to content

Commit

Permalink
Enforce code style
Browse files Browse the repository at this point in the history
  • Loading branch information
chihchy committed Apr 11, 2024
1 parent 6f04b56 commit 76abb24
Show file tree
Hide file tree
Showing 56 changed files with 183 additions and 242 deletions.
2 changes: 1 addition & 1 deletion EhPanda/App/Tools/Clients/AuthorizationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension AuthorizationClient {
return !LAContext().canEvaluatePolicy(.deviceOwnerAuthentication, error: &error)
},
localAuthroize: { reason in
Effect.publisher {
.publisher {
Future { promise in
let context = LAContext()
var error: NSError?
Expand Down
24 changes: 12 additions & 12 deletions EhPanda/App/Tools/Clients/DatabaseClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct DatabaseClient {
extension DatabaseClient {
static let live: Self = .init(
prepareDatabase: {
Effect.publisher {
.publisher {
Future { promise in
PersistenceController.shared.prepare {
switch $0 {
Expand All @@ -36,7 +36,7 @@ extension DatabaseClient {
}
},
dropDatabase: {
Effect.publisher {
.publisher {
Future { promise in
PersistenceController.shared.rebuild {
switch $0 {
Expand Down Expand Up @@ -217,7 +217,7 @@ extension DatabaseClient {
return entity
}
func fetchAppEnv() -> Effect<AppEnv> {
Effect.publisher {
.publisher {
Future { promise in
DispatchQueue.main.async {
promise(.success(fetchOrCreate(entityType: AppEnvMO.self).toEntity()))
Expand All @@ -231,7 +231,7 @@ extension DatabaseClient {
}
func fetchGalleryState(gid: String) -> Effect<GalleryState> {
guard gid.isValidGID else { return .none }
return Effect.publisher {
return .publisher {
Future { promise in
DispatchQueue.main.async {
promise(.success(
Expand All @@ -243,7 +243,7 @@ extension DatabaseClient {
}
}
func fetchHistoryGalleries(fetchLimit: Int = 0) -> Effect<[Gallery]> {
Effect.publisher {
.publisher {
Future { promise in
DispatchQueue.main.async {
let predicate = NSPredicate(format: "lastOpenDate != nil")
Expand Down Expand Up @@ -290,14 +290,14 @@ extension DatabaseClient {
extension DatabaseClient {
func updateGallery(gid: String, key: String, value: Any?) -> Effect<Never> {
guard gid.isValidGID else { return .none }
return .run(operation: { _ in
return .run { _ in
DispatchQueue.main.async {
update(
entityType: GalleryMO.self, gid: gid, createIfNil: true,
commitChanges: { $0.setValue(value, forKeyPath: key) }
)
}
})
}
}
func updateLastOpenDate(gid: String, date: Date = .now) -> Effect<Never> {
guard gid.isValidGID else { return .none }
Expand Down Expand Up @@ -350,7 +350,7 @@ extension DatabaseClient {
extension DatabaseClient {
func cacheGalleryDetail(_ detail: GalleryDetail) -> Effect<Never> {
guard detail.gid.isValidGID else { return .none }
return .run(operation: { _ in
return .run { _ in
DispatchQueue.main.async {
let storedMO = fetch(
entityType: GalleryDetailMO.self, gid: detail.gid
Expand Down Expand Up @@ -380,22 +380,22 @@ extension DatabaseClient {
}
saveContext()
}
})
}
}
}

// MARK: UpdateGalleryState
extension DatabaseClient {
func updateGalleryState(gid: String, commitChanges: @escaping (GalleryStateMO) -> Void) -> Effect<Never> {
guard gid.isValidGID else { return .none }
return .run(operation: { _ in
return .run { _ in
DispatchQueue.main.async {
update(
entityType: GalleryStateMO.self, gid: gid, createIfNil: true,
commitChanges: commitChanges
)
}
})
}
}
func updateGalleryState(gid: String, key: String, value: Any?) -> Effect<Never> {
guard gid.isValidGID else { return .none }
Expand Down Expand Up @@ -529,7 +529,7 @@ extension DatabaseClient {

// Update User
func updateUserProperty(_ commitChanges: @escaping (inout User) -> Void) -> Effect<Never> {
Effect.publisher {
.publisher {
fetchAppEnv().map(\.user)
.map { (user: User) -> User in
var user = user
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/App/Tools/Clients/ImageClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extension ImageClient {
})
},
saveImageToPhotoLibrary: { (image, isAnimated) in
Effect.publisher {
.publisher {
Future { promise in
DispatchQueue.global(qos: .utility).async {
if let data = image.kf.data(format: isAnimated ? .GIF : .unknown) {
Expand Down
4 changes: 2 additions & 2 deletions EhPanda/App/Tools/Clients/LibraryClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ extension LibraryClient {
})
},
analyzeImageColors: { image in
Effect.publisher {
.publisher {
Future { promise in
image.getColors(quality: .lowest) { colors in
promise(.success(colors))
Expand All @@ -76,7 +76,7 @@ extension LibraryClient {
}
},
calculateWebImageDiskCacheSize: {
Effect.publisher {
.publisher {
Future { promise in
KingfisherManager.shared.cache.calculateDiskStorageSize {
promise(.success(try? $0.get()))
Expand Down
2 changes: 1 addition & 1 deletion EhPanda/DataFlow/AppLockReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct AppLockReducer: Reducer {
Effect.send(.lockApp(blurRadius))
)
} else {
return Effect.send(.unlockApp)
return .send(.unlockApp)
}

case .onBecomeInactive(let blurRadius):
Expand Down
36 changes: 18 additions & 18 deletions EhPanda/DataFlow/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct AppReducer: Reducer {
return state.appRouteState.route == nil ? Effect.send(.appRoute(.clearSubStates)) : .none

case .binding(\.settingState.$setting):
return Effect.send(.setting(.syncSetting))
return .send(.setting(.syncSetting))

case .binding:
return .none
Expand All @@ -62,11 +62,11 @@ struct AppReducer: Reducer {
case .active:
let threshold = state.settingState.setting.autoLockPolicy.rawValue
let blurRadius = state.settingState.setting.backgroundBlurRadius
return Effect.send(.appLock(.onBecomeActive(threshold, blurRadius)))
return .send(.appLock(.onBecomeActive(threshold, blurRadius)))

case .inactive:
let blurRadius = state.settingState.setting.backgroundBlurRadius
return Effect.send(.appLock(.onBecomeInactive(blurRadius)))
return .send(.appLock(.onBecomeInactive(blurRadius)))

default:
return .none
Expand All @@ -85,7 +85,7 @@ struct AppReducer: Reducer {
var effects = [Effect<Action>]()
if deviceClient.isPad() {
state.settingState.route = nil
effects.append(Effect.send(.setting(.clearSubStates)))
effects.append(.send(.setting(.clearSubStates)))
}
return effects.isEmpty ? .none : .merge(effects)

Expand All @@ -97,7 +97,7 @@ struct AppReducer: Reducer {
Effect.send(.setting(.fetchGreeting))
]
if state.settingState.setting.detectsLinksFromClipboard {
effects.append(Effect.send(.appRoute(.detectClipboardURL)))
effects.append(.send(.appRoute(.detectClipboardURL)))
}
return .merge(effects)

Expand All @@ -111,27 +111,27 @@ struct AppReducer: Reducer {
switch type {
case .home:
if state.homeState.route != nil {
effects.append(Effect.send(.home(.setNavigation(nil))))
effects.append(.send(.home(.setNavigation(nil))))
} else {
effects.append(Effect.send(.home(.fetchAllGalleries)))
effects.append(.send(.home(.fetchAllGalleries)))
}
case .favorites:
if state.favoritesState.route != nil {
effects.append(Effect.send(.favorites(.setNavigation(nil))))
effects.append(.send(.favorites(.setNavigation(nil))))
effects.append(hapticEffect)
} else if cookieClient.didLogin {
effects.append(Effect.send(.favorites(.fetchGalleries())))
effects.append(.send(.favorites(.fetchGalleries())))
effects.append(hapticEffect)
}
case .search:
if state.searchRootState.route != nil {
effects.append(Effect.send(.searchRoot(.setNavigation(nil))))
effects.append(.send(.searchRoot(.setNavigation(nil))))
} else {
effects.append(Effect.send(.searchRoot(.fetchDatabaseInfos)))
effects.append(.send(.searchRoot(.fetchDatabaseInfos)))
}
case .setting:
if state.settingState.route != nil {
effects.append(Effect.send(.setting(.setNavigation(nil))))
effects.append(.send(.setting(.setNavigation(nil))))
effects.append(hapticEffect)
}
}
Expand All @@ -140,7 +140,7 @@ struct AppReducer: Reducer {
}
}
if type == .setting && deviceClient.isPad() {
effects.append(Effect.send(.appRoute(.setNavigation(.setting))))
effects.append(.send(.appRoute(.setNavigation(.setting))))
}
return effects.isEmpty ? .none : .merge(effects)

Expand All @@ -152,10 +152,10 @@ struct AppReducer: Reducer {
.run(operation: { _ in hapticsClient.generateFeedback(.soft) }),
Effect.send(.tabBar(.setTabBarItemType(.setting)))
]
effects.append(Effect.send(.setting(.setNavigation(.account))))
effects.append(.send(.setting(.setNavigation(.account))))
if !cookieClient.didLogin {
effects.append(
Effect.publisher {
.publisher {
Effect.send(.setting(.account(.setNavigation(.login))))
.delay(
for: .milliseconds(deviceClient.isPad() ? 1200 : 200),
Expand All @@ -181,15 +181,15 @@ struct AppReducer: Reducer {
let blurRadius = state.settingState.setting.backgroundBlurRadius
if threshold >= 0 {
state.appLockState.becameInactiveDate = .distantPast
effects.append(Effect.send(.appLock(.onBecomeActive(threshold, blurRadius))))
effects.append(.send(.appLock(.onBecomeActive(threshold, blurRadius))))
}
if state.settingState.setting.detectsLinksFromClipboard {
effects.append(Effect.send(.appRoute(.detectClipboardURL)))
effects.append(.send(.appRoute(.detectClipboardURL)))
}
return effects.isEmpty ? .none : .merge(effects)

case .setting(.fetchGreetingDone(let result)):
return Effect.send(.appRoute(.fetchGreetingDone(result)))
return .send(.appRoute(.fetchGreetingDone(result)))

case .setting:
return .none
Expand Down
22 changes: 11 additions & 11 deletions EhPanda/DataFlow/AppRouteReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct AppRouteReducer: Reducer {

case .clearSubStates:
state.detailState = .init()
return Effect.send(.detail(.teardown))
return .send(.detail(.teardown))

case .detectClipboardURL:
let currentChangeCount = clipboardClient.changeCount()
Expand All @@ -85,7 +85,7 @@ struct AppRouteReducer: Reducer {
.setValue(currentChangeCount, .clipboardChangeCount).fireAndForget()
]
if let url = clipboardClient.url() {
effects.append(Effect.send(.handleDeepLink(url)))
effects.append(.send(.handleDeepLink(url)))
}
return .merge(effects)

Expand All @@ -101,12 +101,12 @@ struct AppRouteReducer: Reducer {
let (isGalleryImageURL, _, _) = urlClient.analyzeURL(url)
let gid = urlClient.parseGalleryID(url)
guard databaseClient.fetchGallery(gid: gid) == nil else {
return Effect.publisher {
return .publisher {
Effect.send(.handleGalleryLink(url))
.delay(for: .milliseconds(delay + 250), scheduler: DispatchQueue.main)
}
}
return Effect.publisher {
return .publisher {
Effect.send(.fetchGallery(url, isGalleryImageURL))
.delay(for: .milliseconds(delay), scheduler: DispatchQueue.main)
}
Expand All @@ -116,25 +116,25 @@ struct AppRouteReducer: Reducer {
let gid = urlClient.parseGalleryID(url)
var effects = [Effect<Action>]()
state.detailState = .init()
effects.append(Effect.send(.detail(.fetchDatabaseInfos(gid))))
effects.append(.send(.detail(.fetchDatabaseInfos(gid))))
if let pageIndex = pageIndex {
effects.append(Effect.send(.updateReadingProgress(gid, pageIndex)))
effects.append(.send(.updateReadingProgress(gid, pageIndex)))
effects.append(
Effect.publisher {
.publisher {
Effect.send(.detail(.setNavigation(.reading)))
.delay(for: .milliseconds(500), scheduler: DispatchQueue.main)
}
)
} else if let commentID = commentID {
state.detailState.commentsState?.scrollCommentID = commentID
effects.append(
Effect.publisher {
.publisher {
Effect.send(.detail(.setNavigation(.comments(url))))
.delay(for: .milliseconds(500), scheduler: DispatchQueue.main)
}
)
}
effects.append(Effect.send(.setNavigation(.detail(gid))))
effects.append(.send(.setNavigation(.detail(gid))))
return .merge(effects)

case .updateReadingProgress(let gid, let progress):
Expand All @@ -156,15 +156,15 @@ struct AppRouteReducer: Reducer {
Effect.send(.handleGalleryLink(url))
)
case .failure:
return Effect.publisher {
return .publisher {
Effect.send(Action.setHUDConfig(.error))
.delay(for: .milliseconds(500), scheduler: DispatchQueue.main)
}
}

case .fetchGreetingDone(let result):
if case .success(let greeting) = result, !greeting.gainedNothing {
return Effect.send(.setNavigation(.newDawn(greeting)))
return .send(.setNavigation(.newDawn(greeting)))
}
return .none

Expand Down
10 changes: 6 additions & 4 deletions EhPanda/View/Detail/Archives/ArchivesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ struct ArchivesReducer: Reducer {
}
state.hathArchives = archive.hathArchives
if let galleryPoints = galleryPoints, let credits = credits {
return Effect.send(.syncGalleryFunds(galleryPoints, credits))
return .send(.syncGalleryFunds(galleryPoints, credits))
} else if cookieClient.isSameAccount {
return Effect.send(.fetchArchiveFunds(gid, galleryURL))
return .send(.fetchArchiveFunds(gid, galleryURL))
} else {
return .none
}
Expand All @@ -103,7 +103,7 @@ struct ArchivesReducer: Reducer {

case .fetchArchiveFundsDone(let result):
if case .success(let (galleryPoints, credits)) = result {
return Effect.send(.syncGalleryFunds(galleryPoints, credits))
return .send(.syncGalleryFunds(galleryPoints, credits))
}
return .none

Expand Down Expand Up @@ -140,7 +140,9 @@ struct ArchivesReducer: Reducer {
state.messageHUDConfig = .error
isSuccess = false
}
return .run(operation: { _ in hapticsClient.generateNotificationFeedback(isSuccess ? .success : .error) })
return .run { _ in
hapticsClient.generateNotificationFeedback(isSuccess ? .success : .error)
}
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions EhPanda/View/Detail/Archives/ArchivesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,7 @@ private struct DownloadButton: View {
struct ArchivesView_Previews: PreviewProvider {
static var previews: some View {
ArchivesView(
store: .init(initialState: .init()) {
ArchivesReducer()
},
store: .init(initialState: .init(), reducer: ArchivesReducer.init),
gid: .init(),
user: .init(),
galleryURL: .mock,
Expand Down
Loading

0 comments on commit 76abb24

Please sign in to comment.