Skip to content

Commit

Permalink
Resolve compiler warnings [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
chihchy committed Jan 27, 2024
1 parent 99906b7 commit 2ef7db8
Show file tree
Hide file tree
Showing 26 changed files with 237 additions and 235 deletions.
2 changes: 1 addition & 1 deletion EhPanda/DataFlow/AppDelegateReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct AppDelegateReducer: ReducerProtocol {
cookieClient.syncExCookies().fireAndForget(),
cookieClient.ignoreOffensive().fireAndForget(),
cookieClient.fulfillAnotherHostField().fireAndForget(),
.init(value: .migration(.prepareDatabase))
.send(.migration(.prepareDatabase))
)

case .removeExpiredImageURLs:
Expand Down
8 changes: 4 additions & 4 deletions EhPanda/DataFlow/AppLockReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ struct AppLockReducer: ReducerProtocol {
Date.now.timeIntervalSince(date) >= Double(threshold)
{
return .merge(
.init(value: .authorize),
.init(value: .lockApp(blurRadius))
.send(.authorize),
.send(.lockApp(blurRadius))
)
} else {
return .init(value: .unlockApp)
return .send(.unlockApp)
}

case .onBecomeInactive(let blurRadius):
Expand All @@ -67,7 +67,7 @@ struct AppLockReducer: ReducerProtocol {
.map(Action.authorizeDone)

case .authorizeDone(let isSucceeded):
return isSucceeded ? .init(value: .unlockApp) : .none
return isSucceeded ? .send(.unlockApp) : .none
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions EhPanda/DataFlow/AppReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ struct AppReducer: ReducerProtocol {
Reduce { state, action in
switch action {
case .binding(\.appRouteState.$route):
return state.appRouteState.route == nil ? .init(value: .appRoute(.clearSubStates)) : .none
return state.appRouteState.route == nil ? .send(.appRoute(.clearSubStates)) : .none

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

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

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

default:
return .none
}

case .appDelegate(.migration(.onDatabasePreparationSuccess)):
return .merge(
.init(value: .appDelegate(.removeExpiredImageURLs)),
.init(value: .setting(.loadUserSettings))
.send(.appDelegate(.removeExpiredImageURLs)),
.send(.setting(.loadUserSettings))
)

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

Expand All @@ -94,10 +94,10 @@ struct AppReducer: ReducerProtocol {

case .appLock(.unlockApp):
var effects: [EffectTask<Action>] = [
.init(value: .setting(.fetchGreeting))
.send(.setting(.fetchGreeting))
]
if state.settingState.setting.detectsLinksFromClipboard {
effects.append(.init(value: .appRoute(.detectClipboardURL)))
effects.append(.send(.appRoute(.detectClipboardURL)))
}
return .merge(effects)

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

Expand All @@ -150,12 +150,12 @@ struct AppReducer: ReducerProtocol {
case .home(.watched(.onNotLoginViewButtonTapped)), .favorites(.onNotLoginViewButtonTapped):
var effects: [EffectTask<Action>] = [
.fireAndForget({ hapticsClient.generateFeedback(.soft) }),
.init(value: .tabBar(.setTabBarItemType(.setting)))
.send(.tabBar(.setTabBarItemType(.setting)))
]
effects.append(.init(value: .setting(.setNavigation(.account))))
effects.append(.send(.setting(.setNavigation(.account))))
if !cookieClient.didLogin {
effects.append(
.init(value: .setting(.account(.setNavigation(.login))))
.send(.setting(.account(.setNavigation(.login))))
.delay(
for: .milliseconds(deviceClient.isPad() ? 1200 : 200),
scheduler: DispatchQueue.main
Expand All @@ -180,15 +180,15 @@ struct AppReducer: ReducerProtocol {
let blurRadius = state.settingState.setting.backgroundBlurRadius
if threshold >= 0 {
state.appLockState.becameInactiveDate = .distantPast
effects.append(.init(value: .appLock(.onBecomeActive(threshold, blurRadius))))
effects.append(.send(.appLock(.onBecomeActive(threshold, blurRadius))))
}
if state.settingState.setting.detectsLinksFromClipboard {
effects.append(.init(value: .appRoute(.detectClipboardURL)))
effects.append(.send(.appRoute(.detectClipboardURL)))
}
return effects.isEmpty ? .none : .merge(effects)

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

case .setting:
return .none
Expand Down
28 changes: 14 additions & 14 deletions EhPanda/DataFlow/AppRouteReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@ struct AppRouteReducer: ReducerProtocol {
Reduce { state, action in
switch action {
case .binding(\.$route):
return state.route == nil ? .init(value: .clearSubStates) : .none
return state.route == nil ? .send(.clearSubStates) : .none

case .binding:
return .none

case .setNavigation(let route):
state.route = route
return route == nil ? .init(value: .clearSubStates) : .none
return route == nil ? .send(.clearSubStates) : .none

case .setHUDConfig(let config):
state.hudConfig = config
return .none

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

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

Expand All @@ -101,32 +101,32 @@ struct AppRouteReducer: ReducerProtocol {
let (isGalleryImageURL, _, _) = urlClient.analyzeURL(url)
let gid = urlClient.parseGalleryID(url)
guard databaseClient.fetchGallery(gid: gid) == nil else {
return .init(value: .handleGalleryLink(url))
return .send(.handleGalleryLink(url))
.delay(for: .milliseconds(delay + 250), scheduler: DispatchQueue.main).eraseToEffect()
}
return .init(value: .fetchGallery(url, isGalleryImageURL))
return .send(.fetchGallery(url, isGalleryImageURL))
.delay(for: .milliseconds(delay), scheduler: DispatchQueue.main).eraseToEffect()

case .handleGalleryLink(let url):
let (_, pageIndex, commentID) = urlClient.analyzeURL(url)
let gid = urlClient.parseGalleryID(url)
var effects = [EffectTask<Action>]()
state.detailState = .init()
effects.append(.init(value: .detail(.fetchDatabaseInfos(gid))))
effects.append(.send(.detail(.fetchDatabaseInfos(gid))))
if let pageIndex = pageIndex {
effects.append(.init(value: .updateReadingProgress(gid, pageIndex)))
effects.append(.send(.updateReadingProgress(gid, pageIndex)))
effects.append(
.init(value: .detail(.setNavigation(.reading)))
.send(.detail(.setNavigation(.reading)))
.delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect()
)
} else if let commentID = commentID {
state.detailState.commentsState?.scrollCommentID = commentID
effects.append(
.init(value: .detail(.setNavigation(.comments(url))))
.send(.detail(.setNavigation(.comments(url))))
.delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect()
)
}
effects.append(.init(value: .setNavigation(.detail(gid))))
effects.append(.send(.setNavigation(.detail(gid))))
return .merge(effects)

case .updateReadingProgress(let gid, let progress):
Expand All @@ -145,16 +145,16 @@ struct AppRouteReducer: ReducerProtocol {
case .success(let gallery):
return .merge(
databaseClient.cacheGalleries([gallery]).fireAndForget(),
.init(value: .handleGalleryLink(url))
.send(.handleGalleryLink(url))
)
case .failure:
return .init(value: .setHUDConfig(.error))
return .send(.setHUDConfig(.error))
.delay(for: .milliseconds(500), scheduler: DispatchQueue.main).eraseToEffect()
}

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

Expand Down
6 changes: 3 additions & 3 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: ReducerProtocol {
}
state.hathArchives = archive.hathArchives
if let galleryPoints = galleryPoints, let credits = credits {
return .init(value: .syncGalleryFunds(galleryPoints, credits))
return .send(.syncGalleryFunds(galleryPoints, credits))
} else if cookieClient.isSameAccount {
return .init(value: .fetchArchiveFunds(gid, galleryURL))
return .send(.fetchArchiveFunds(gid, galleryURL))
} else {
return .none
}
Expand All @@ -103,7 +103,7 @@ struct ArchivesReducer: ReducerProtocol {

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

Expand Down
Loading

0 comments on commit 2ef7db8

Please sign in to comment.