Skip to content

Commit

Permalink
Enforce code style
Browse files Browse the repository at this point in the history
  • Loading branch information
chihchy committed Jul 10, 2024
1 parent 4463781 commit 0358bd5
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 239 deletions.
4 changes: 1 addition & 3 deletions EhPanda/App/Tools/Extensions/Reducer_Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ extension Reducer {
style: UIImpactFeedbackGenerator.FeedbackStyle = .light
) -> some Reducer<State, Action> {
onBecomeNonNil(unwrapping: `enum`, case: casePath) { _, _ in
.run { _ in
hapticsClient.generateFeedback(style)
}
.run(operation: { _ in hapticsClient.generateFeedback(style) })
}
}

Expand Down
28 changes: 7 additions & 21 deletions EhPanda/DataFlow/AppDelegateReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,17 @@ struct AppDelegateReducer: Reducer {
switch action {
case .onLaunchFinish:
return .merge(
.run { _ in
libraryClient.initializeLogger()
},
.run { _ in
libraryClient.initializeWebImage()
},
.run { _ in
cookieClient.removeYay()
},
.run { _ in
cookieClient.syncExCookies()
},
.run { _ in
cookieClient.ignoreOffensive()
},
.run { _ in
cookieClient.fulfillAnotherHostField()
},
.run(operation: { _ in libraryClient.initializeLogger() }),
.run(operation: { _ in libraryClient.initializeWebImage() }),
.run(operation: { _ in cookieClient.removeYay() }),
.run(operation: { _ in cookieClient.syncExCookies() }),
.run(operation: { _ in cookieClient.ignoreOffensive() }),
.run(operation: { _ in cookieClient.fulfillAnotherHostField() }),
.send(.migration(.prepareDatabase))
)

case .removeExpiredImageURLs:
return .run { _ in
await databaseClient.removeExpiredImageURLs()
}
return .run(operation: { _ in await databaseClient.removeExpiredImageURLs() })

case .migration:
return .none
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/DataFlow/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ struct AppReducer: Reducer {

case .tabBar(.setTabBarItemType(let type)):
var effects = [Effect<Action>]()
let hapticEffect: Effect<Action> = .run { _ in
hapticsClient.generateFeedback(.soft)
}
let hapticEffect: Effect<Action> = .run(operation: { _ in hapticsClient.generateFeedback(.soft) })
if type == state.tabBarState.tabBarItemType {
switch type {
case .home:
Expand Down Expand Up @@ -155,9 +153,7 @@ struct AppReducer: Reducer {

case .home(.watched(.onNotLoginViewButtonTapped)), .favorites(.onNotLoginViewButtonTapped):
var effects: [Effect<Action>] = [
.run { _ in
hapticsClient.generateFeedback(.soft)
},
.run(operation: { _ in hapticsClient.generateFeedback(.soft) }),
.send(.tabBar(.setTabBarItemType(.setting)))
]
effects.append(.send(.setting(.setNavigation(.account))))
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/DataFlow/AppRouteReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ struct AppRouteReducer: Reducer {
guard currentChangeCount != userDefaultsClient
.getValue(.clipboardChangeCount) else { return .none }
var effects: [Effect<Action>] = [
.run { _ in
userDefaultsClient.setValue(currentChangeCount, .clipboardChangeCount)
}
.run(operation: { _ in userDefaultsClient.setValue(currentChangeCount, .clipboardChangeCount) })
]
if let url = clipboardClient.url() {
effects.append(.send(.handleDeepLink(url)))
Expand Down Expand Up @@ -159,9 +157,7 @@ struct AppRouteReducer: Reducer {
switch result {
case .success(let gallery):
return .merge(
.run { _ in
await databaseClient.cacheGalleries([gallery])
},
.run(operation: { _ in await databaseClient.cacheGalleries([gallery]) }),
.send(.handleGalleryLink(url))
)
case .failure:
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Detail/Comments/CommentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ struct CommentsReducer: Reducer {

case .handleCommentLink(let url):
guard urlClient.checkIfHandleable(url) else {
return .run { _ in
await uiApplicationClient.openURL(url)
}
return .run(operation: { _ in await uiApplicationClient.openURL(url) })
}
let (isGalleryImageURL, _, _) = urlClient.analyzeURL(url)
let gid = urlClient.parseGalleryID(url)
Expand Down Expand Up @@ -246,9 +244,7 @@ struct CommentsReducer: Reducer {
switch result {
case .success(let gallery):
return .merge(
.run { _ in
await databaseClient.cacheGalleries([gallery])
},
.run(operation: { _ in await databaseClient.cacheGalleries([gallery]) }),
.send(.handleGalleryLink(url))
)
case .failure:
Expand Down
28 changes: 7 additions & 21 deletions EhPanda/View/Detail/DetailReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,11 @@ struct DetailReducer: Reducer {

case .toggleShowFullTitle:
state.showsFullTitle.toggle()
return .run { _ in
hapticsClient.generateFeedback(.soft)
}
return .run(operation: { _ in hapticsClient.generateFeedback(.soft) })

case .toggleShowUserRating:
state.showsUserRating.toggle()
return .run { _ in
hapticsClient.generateFeedback(.soft)
}
return .run(operation: { _ in hapticsClient.generateFeedback(.soft) })

case .setCommentContent(let content):
state.commentContent = content
Expand All @@ -194,9 +190,7 @@ struct DetailReducer: Reducer {
state.updateRating(value: value)
return .merge(
.send(.rateGallery),
.run { _ in
hapticsClient.generateFeedback(.soft)
},
.run(operation: { _ in hapticsClient.generateFeedback(.soft) }),
.run { send in
try await Task.sleep(for: .seconds(1))
await send(.confirmRatingDone)
Expand All @@ -214,9 +208,7 @@ struct DetailReducer: Reducer {

case .syncGalleryDetail:
guard let detail = state.galleryDetail else { return .none }
return .run { _ in
await databaseClient.cacheGalleryDetail(detail)
}
return .run(operation: { _ in await databaseClient.cacheGalleryDetail(detail) })

case .syncGalleryPreviewURLs:
return .run { [state] _ in
Expand All @@ -230,9 +222,7 @@ struct DetailReducer: Reducer {
}

case .syncGreeting(let greeting):
return .run { _ in
await databaseClient.updateGreeting(greeting)
}
return .run(operation: { _ in await databaseClient.updateGreeting(greeting) })

case .syncPreviewConfig(let config):
return .run { [state] _ in
Expand Down Expand Up @@ -381,14 +371,10 @@ struct DetailReducer: Reducer {
if case .success = result {
return .merge(
.send(.fetchGalleryDetail),
.run { _ in
hapticsClient.generateNotificationFeedback(.success)
}
.run(operation: { _ in hapticsClient.generateNotificationFeedback(.success) })
)
}
return .run { _ in
hapticsClient.generateNotificationFeedback(.error)
}
return .run(operation: { _ in hapticsClient.generateNotificationFeedback(.error) })

case .reading(.onPerformDismiss):
return .send(.setNavigation(nil))
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ struct DetailSearchReducer: Reducer {
}
state.pageNumber = pageNumber
state.galleries = galleries
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.loadingState = .failed(error)
}
Expand Down Expand Up @@ -156,9 +154,7 @@ struct DetailSearchReducer: Reducer {
state.insertGalleries(galleries)

var effects: [Effect<Action>] = [
.run { _ in
await databaseClient.cacheGalleries(galleries)
}
.run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
]
if galleries.isEmpty, pageNumber.hasNextPage() {
effects.append(.send(.fetchMoreGalleries))
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Detail/GalleryInfos/GalleryInfosReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ struct GalleryInfosReducer: Reducer {
case .copyText(let text):
state.route = .hud
return .merge(
.run { _ in
clipboardClient.saveText(text)
},
.run { _ in
hapticsClient.generateNotificationFeedback(.success)
}
.run(operation: { _ in clipboardClient.saveText(text) }),
.run(operation: { _ in hapticsClient.generateNotificationFeedback(.success) })
)
}
}
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Detail/Torrents/TorrentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,8 @@ struct TorrentsReducer: Reducer {
case .copyText(let magnetURL):
state.route = .hud
return .merge(
.run { _ in
clipboardClient.saveText(magnetURL)
},
.run { _ in
hapticsClient.generateNotificationFeedback(.success)
}
.run(operation: { _ in clipboardClient.saveText(magnetURL) }),
.run(operation: { _ in hapticsClient.generateNotificationFeedback(.success) })
)

case .presentTorrentActivity(let hash, let data):
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Favorites/FavoritesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ struct FavoritesReducer: Reducer {
state.rawPageNumber[targetFavIndex] = pageNumber
state.rawGalleries[targetFavIndex] = galleries
state.sortOrder = sortOrder
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.rawLoadingState[targetFavIndex] = .failed(error)
}
Expand Down Expand Up @@ -169,9 +167,7 @@ struct FavoritesReducer: Reducer {
state.sortOrder = sortOrder

var effects: [Effect<Action>] = [
.run { _ in
await databaseClient.cacheGalleries(galleries)
}
.run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
]
if galleries.isEmpty, pageNumber.hasNextPage() {
effects.append(.send(.fetchMoreGalleries))
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Home/Frontpage/FrontpageReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ struct FrontpageReducer: Reducer {
}
state.pageNumber = pageNumber
state.galleries = galleries
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.loadingState = .failed(error)
}
Expand Down Expand Up @@ -139,9 +137,7 @@ struct FrontpageReducer: Reducer {
state.insertGalleries(galleries)

var effects: [Effect<Action>] = [
.run { _ in
await databaseClient.cacheGalleries(galleries)
}
.run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
]
if galleries.isEmpty, pageNumber.hasNextPage() {
effects.append(.send(.fetchMoreGalleries))
Expand Down
4 changes: 1 addition & 3 deletions EhPanda/View/Home/History/HistoryReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ struct HistoryReducer: Reducer {

case .clearHistoryGalleries:
return .merge(
.run { _ in
await databaseClient.clearHistoryGalleries()
},
.run(operation: { _ in await databaseClient.clearHistoryGalleries() }),
.run { send in
try await Task.sleep(for: .milliseconds(200))
await send(.fetchGalleries)
Expand Down
12 changes: 3 additions & 9 deletions EhPanda/View/Home/HomeReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ struct HomeReducer: Reducer {
return .none
}
state.setPopularGalleries(galleries)
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.popularLoadingState = .failed(error)
}
Expand All @@ -195,9 +193,7 @@ struct HomeReducer: Reducer {
return .none
}
state.setFrontpageGalleries(galleries)
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.frontpageLoadingState = .failed(error)
}
Expand All @@ -220,9 +216,7 @@ struct HomeReducer: Reducer {
return .none
}
state.toplistsGalleries[index] = galleries
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.toplistsLoadingState[index] = .failed(error)
}
Expand Down
4 changes: 1 addition & 3 deletions EhPanda/View/Home/Popular/PopularReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ struct PopularReducer: Reducer {
return .none
}
state.galleries = galleries
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.loadingState = .failed(error)
}
Expand Down
16 changes: 4 additions & 12 deletions EhPanda/View/Home/Toplists/ToplistsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,13 @@ struct ToplistsReducer: Reducer {
guard let index = Int(state.jumpPageIndex),
let pageNumber = state.pageNumber,
index > 0, index <= pageNumber.maximum + 1 else {
return .run { _ in
hapticsClient.generateNotificationFeedback(.error)
}
return .run(operation: { _ in hapticsClient.generateNotificationFeedback(.error) })
}
return .send(.fetchGalleries(index - 1))

case .presentJumpPageAlert:
state.jumpPageAlertPresented = true
return .run { _ in
hapticsClient.generateFeedback(.light)
}
return .run(operation: { _ in hapticsClient.generateFeedback(.light) })

case .setJumpPageAlertFocused(let isFocused):
state.jumpPageAlertFocused = isFocused
Expand Down Expand Up @@ -166,9 +162,7 @@ struct ToplistsReducer: Reducer {
}
state.rawPageNumber[type] = pageNumber
state.rawGalleries[type] = galleries
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.rawLoadingState[type] = .failed(error)
}
Expand Down Expand Up @@ -198,9 +192,7 @@ struct ToplistsReducer: Reducer {
state.insertGalleries(type: type, galleries: galleries)

var effects: [Effect<Action>] = [
.run { _ in
await databaseClient.cacheGalleries(galleries)
}
.run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
]
if galleries.isEmpty, pageNumber.hasNextPage() {
effects.append(.send(.fetchMoreGalleries))
Expand Down
8 changes: 2 additions & 6 deletions EhPanda/View/Home/Watched/WatchedReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ struct WatchedReducer: Reducer {
}
state.pageNumber = pageNumber
state.galleries = galleries
return .run { _ in
await databaseClient.cacheGalleries(galleries)
}
return .run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
case .failure(let error):
state.loadingState = .failed(error)
}
Expand Down Expand Up @@ -152,9 +150,7 @@ struct WatchedReducer: Reducer {
state.insertGalleries(galleries)

var effects: [Effect<Action>] = [
.run { _ in
await databaseClient.cacheGalleries(galleries)
}
.run(operation: { _ in await databaseClient.cacheGalleries(galleries) })
]
if galleries.isEmpty, pageNumber.hasNextPage() {
effects.append(.send(.fetchMoreGalleries))
Expand Down
Loading

0 comments on commit 0358bd5

Please sign in to comment.