Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to TCA 1.0 #379

Merged
merged 32 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3d8b320
Rename `EffectTask` with `Effect`
Jimmy-Prime Mar 15, 2024
88fac74
Rename `ReducerProtocol` with `Reducer`
Jimmy-Prime Mar 15, 2024
52fd6c8
Fix 'init(value:)' is deprecated
Jimmy-Prime Mar 15, 2024
0026c04
Fix 'fireAndForget' is deprecated
Jimmy-Prime Mar 15, 2024
90c262a
Fix 'init(initialState:reducer:prepareDependencies:)' is deprecated
Jimmy-Prime Mar 15, 2024
ebb2387
Fix 'init(_:)' is deprecated
Jimmy-Prime Mar 16, 2024
253056d
Fix 'binding(_:fileID:line:)'
Jimmy-Prime Mar 16, 2024
53c4574
Fix 'eraseToEffect()' is deprecated
Jimmy-Prime Mar 16, 2024
fdbbbc4
Fix 'cancel(ids:)' is deprecated
Jimmy-Prime Mar 16, 2024
6f04b56
Merge pull request #368 from Jimmy-Prime/jimmy/fix-tca-warnings
chihchy Apr 4, 2024
76abb24
Enforce code style
chihchy Apr 11, 2024
6842553
Update code level contributors
chihchy Apr 11, 2024
4aedf46
Fix most warnings
Jimmy-Prime Apr 19, 2024
6407b4a
pr fix: Update Task.sleep call
Jimmy-Prime May 25, 2024
4c4163b
pr fix: Remove CancelID.teardown
Jimmy-Prime May 25, 2024
69f316b
Merge pull request #372 from Jimmy-Prime/jimmy/fix-most-warnings
chihchy May 27, 2024
a1b0463
Add async response for Request
Jimmy-Prime May 25, 2024
4f34187
Fix deprecation
Jimmy-Prime May 25, 2024
438d56e
Remove deprecated symbol
Jimmy-Prime May 25, 2024
3e7f279
TCA 1.0
Jimmy-Prime May 28, 2024
015e787
Fix bug: nesting binding is not matched
Jimmy-Prime May 28, 2024
093504c
Fix deprecated symbol
Jimmy-Prime May 28, 2024
0f475cc
Merge pull request #376 from Jimmy-Prime/jimmy/fix-publisher-deprecated
chihchy May 30, 2024
fd7805a
Resolve warnings & enforce code style
chihchy May 30, 2024
557a1b7
Update CI
chihchy May 30, 2024
033d8bc
Stop ignoring generated files in git
chihchy May 30, 2024
0de6620
Merge pull request #377 from EhPanda-Team/issue/resolve-warnings-and-…
chihchy May 30, 2024
856c492
Add MainActor attribution to avoid crashes
chihchy Jul 10, 2024
895b6d4
Add folder shortcuts
chihchy Jul 10, 2024
ca18060
Update Package.resolved version
chihchy Jul 10, 2024
4463781
Bump version to 2.7.5
chihchy Jul 10, 2024
0358bd5
Enforce code style
chihchy Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix deprecation
  • Loading branch information
Jimmy-Prime committed May 28, 2024
commit 4f341871eb23aba53575462b000b6188ebf1d00d
6 changes: 4 additions & 2 deletions EhPanda/DataFlow/AppRouteReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ struct AppRouteReducer: Reducer {

case .fetchGallery(let url, let isGalleryImageURL):
state.route = .hud
return GalleryReverseRequest(url: url, isGalleryImageURL: isGalleryImageURL)
.effect.map({ Action.fetchGalleryDone(url, $0) })
return .run { send in
let response = await GalleryReverseRequest(url: url, isGalleryImageURL: isGalleryImageURL).response()
await send(Action.fetchGalleryDone(url, response))
}

case .fetchGalleryDone(let url, let result):
state.route = nil
Expand Down
27 changes: 18 additions & 9 deletions EhPanda/View/Detail/Archives/ArchivesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ struct ArchivesReducer: Reducer {
case .fetchArchive(let gid, let galleryURL, let archiveURL):
guard state.loadingState != .loading else { return .none }
state.loadingState = .loading
return GalleryArchiveRequest(archiveURL: archiveURL)
.effect.map({ Action.fetchArchiveDone(gid, galleryURL, $0) })
.cancellable(id: CancelID.fetchArchive)
return .run { send in
let response = await GalleryArchiveRequest(archiveURL: archiveURL).response()
await send(Action.fetchArchiveDone(gid, galleryURL, response))
}
.cancellable(id: CancelID.fetchArchive)

case .fetchArchiveDone(let gid, let galleryURL, let result):
state.loadingState = .idle
Expand All @@ -99,8 +101,11 @@ struct ArchivesReducer: Reducer {

case .fetchArchiveFunds(let gid, let galleryURL):
guard let galleryURL = galleryURL.replaceHost(to: Defaults.URL.ehentai.host) else { return .none }
return GalleryArchiveFundsRequest(gid: gid, galleryURL: galleryURL)
.effect.map(Action.fetchArchiveFundsDone).cancellable(id: CancelID.fetchArchiveFunds)
return .run { send in
let response = await GalleryArchiveFundsRequest(gid: gid, galleryURL: galleryURL).response()
await send(Action.fetchArchiveFundsDone(response))
}
.cancellable(id: CancelID.fetchArchiveFunds)

case .fetchArchiveFundsDone(let result):
if case .success(let (galleryPoints, credits)) = result {
Expand All @@ -113,10 +118,14 @@ struct ArchivesReducer: Reducer {
state.route != .communicatingHUD
else { return .none }
state.route = .communicatingHUD
return SendDownloadCommandRequest(
archiveURL: archiveURL, resolution: selectedArchive.resolution.parameter
)
.effect.map(Action.fetchDownloadResponseDone).cancellable(id: CancelID.fetchDownloadResponse)
return .run {send in
let response = await SendDownloadCommandRequest(
archiveURL: archiveURL,
resolution: selectedArchive.resolution.parameter
).response()
await send(Action.fetchDownloadResponseDone(response))
}
.cancellable(id: CancelID.fetchDownloadResponse)

case .fetchDownloadResponseDone(let result):
state.route = .messageHUD
Expand Down
44 changes: 31 additions & 13 deletions EhPanda/View/Detail/Comments/CommentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,50 @@ struct CommentsReducer: Reducer {
case .postComment(let galleryURL, let commentID):
guard !state.commentContent.isEmpty else { return .none }
if let commentID = commentID {
return EditGalleryCommentRequest(
commentID: commentID, content: state.commentContent, galleryURL: galleryURL
)
.effect.map(Action.performCommentActionDone).cancellable(id: CancelID.postComment)
return .run { [commentContent = state.commentContent] send in
let response = await EditGalleryCommentRequest(
commentID: commentID,
content: commentContent,
galleryURL: galleryURL
).response()
await send(Action.performCommentActionDone(response))
}
.cancellable(id: CancelID.postComment)
} else {
return CommentGalleryRequest(content: state.commentContent, galleryURL: galleryURL)
.effect.map(Action.performCommentActionDone).cancellable(id: CancelID.postComment)
return .run { [commentContent = state.commentContent] send in
let response = await CommentGalleryRequest(content: commentContent, galleryURL: galleryURL).response()
await send(Action.performCommentActionDone(response))
}
.cancellable(id: CancelID.postComment)
}

case .voteComment(let gid, let token, let apiKey, let commentID, let vote):
guard let gid = Int(gid), let commentID = Int(commentID),
let apiuid = Int(cookieClient.apiuid)
else { return .none }
return VoteGalleryCommentRequest(
apiuid: apiuid, apikey: apiKey, gid: gid, token: token,
commentID: commentID, commentVote: vote
)
.effect.map(Action.performCommentActionDone).cancellable(id: CancelID.voteComment)
return .run { send in
let response = await VoteGalleryCommentRequest(
apiuid: apiuid,
apikey: apiKey,
gid: gid,
token: token,
commentID: commentID,
commentVote: vote
).response()
await send(Action.performCommentActionDone(response))
}
.cancellable(id: CancelID.voteComment)

case .performCommentActionDone:
return .none

case .fetchGallery(let url, let isGalleryImageURL):
state.route = .hud
return GalleryReverseRequest(url: url, isGalleryImageURL: isGalleryImageURL)
.effect.map({ Action.fetchGalleryDone(url, $0) }).cancellable(id: CancelID.fetchGallery)
return .run { send in
let response = await GalleryReverseRequest(url: url, isGalleryImageURL: isGalleryImageURL).response()
await send(Action.fetchGalleryDone(url, response))
}
.cancellable(id: CancelID.fetchGallery)

case .fetchGalleryDone(let url, let result):
state.route = nil
Expand Down
67 changes: 48 additions & 19 deletions EhPanda/View/Detail/DetailReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ struct DetailReducer: Reducer {
}
return .merge(
.send(.saveGalleryHistory),
.run { [state] send in
guard let dbState = await databaseClient.fetchGalleryState(gid: state.gallery.id) else { return }
.run { [galleryID = state.gallery.id] send in
guard let dbState = await databaseClient.fetchGalleryState(gid: galleryID) else { return }
await send(.fetchDatabaseInfosDone(dbState))
}
.cancellable(id: CancelID.fetchDatabaseInfos)
Expand All @@ -278,8 +278,11 @@ struct DetailReducer: Reducer {
let galleryURL = state.gallery.galleryURL
else { return .none }
state.loadingState = .loading
return GalleryDetailRequest(gid: state.gallery.id, galleryURL: galleryURL)
.effect.map(Action.fetchGalleryDetailDone).cancellable(id: CancelID.fetchGalleryDetail)
return .run { [galleryID = state.gallery.id] send in
let response = await GalleryDetailRequest(gid: galleryID, galleryURL: galleryURL).response()
await send(Action.fetchGalleryDetailDone(response))
}
.cancellable(id: CancelID.fetchGalleryDetail)

case .fetchGalleryDetailDone(let result):
state.loadingState = .idle
Expand Down Expand Up @@ -315,32 +318,58 @@ struct DetailReducer: Reducer {
case .rateGallery:
guard let apiuid = Int(cookieClient.apiuid), let gid = Int(state.gallery.id)
else { return .none }
return RateGalleryRequest(
apiuid: apiuid, apikey: state.apiKey, gid: gid,
token: state.gallery.token, rating: state.userRating
)
.effect.map(Action.anyGalleryOpsDone).cancellable(id: CancelID.rateGallery)
return .run { [state] send in
let response = await RateGalleryRequest(
apiuid: apiuid,
apikey: state.apiKey,
gid: gid,
token: state.gallery.token,
rating: state.userRating
).response()
await send(Action.anyGalleryOpsDone(response))
}.cancellable(id: CancelID.rateGallery)

case .favorGallery(let favIndex):
return FavorGalleryRequest(gid: state.gallery.id, token: state.gallery.token, favIndex: favIndex)
.effect.map(Action.anyGalleryOpsDone).cancellable(id: CancelID.favorGallery)
return .run { [state] send in
let response = await FavorGalleryRequest(
gid: state.gallery.id,
token: state.gallery.token,
favIndex: favIndex
).response()
await send(Action.anyGalleryOpsDone(response))
}
.cancellable(id: CancelID.favorGallery)

case .unfavorGallery:
return UnfavorGalleryRequest(gid: state.gallery.id).effect.map(Action.anyGalleryOpsDone)
.cancellable(id: CancelID.unfavorGallery)
return .run { [galleryID = state.gallery.id] send in
let response = await UnfavorGalleryRequest(gid: galleryID).response()
await send(Action.anyGalleryOpsDone(response))
}
.cancellable(id: CancelID.unfavorGallery)

case .postComment(let galleryURL):
guard !state.commentContent.isEmpty else { return .none }
return CommentGalleryRequest(content: state.commentContent, galleryURL: galleryURL)
.effect.map(Action.anyGalleryOpsDone).cancellable(id: CancelID.postComment)
return .run { [commentContent = state.commentContent] send in
let response = await CommentGalleryRequest(content: commentContent, galleryURL: galleryURL).response()
await send(Action.anyGalleryOpsDone(response))
}
.cancellable(id: CancelID.postComment)

case .voteTag(let tag, let vote):
guard let apiuid = Int(cookieClient.apiuid), let gid = Int(state.gallery.id)
else { return .none }
return VoteGalleryTagRequest(
apiuid: apiuid, apikey: state.apiKey, gid: gid, token: state.gallery.token, tag: tag, vote: vote
)
.effect.map(Action.anyGalleryOpsDone).cancellable(id: CancelID.voteTag)
return .run { [state] send in
let response = await VoteGalleryTagRequest(
apiuid: apiuid,
apikey: state.apiKey,
gid: gid,
token: state.gallery.token,
tag: tag,
vote: vote
).response()
await send(Action.anyGalleryOpsDone(response))
}
.cancellable(id: CancelID.voteTag)

case .anyGalleryOpsDone(let result):
if case .success = result {
Expand Down
15 changes: 10 additions & 5 deletions EhPanda/View/Detail/DetailSearch/DetailSearchReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ struct DetailSearchReducer: Reducer {
state.loadingState = .loading
state.pageNumber.resetPages()
let filter = databaseClient.fetchFilterSynchronously(range: .search)
return SearchGalleriesRequest(keyword: state.lastKeyword, filter: filter).effect
.map(Action.fetchGalleriesDone).cancellable(id: CancelID.fetchGalleries)
return .run { [lastKeyword = state.lastKeyword] send in
let response = await SearchGalleriesRequest(keyword: lastKeyword, filter: filter).response()
await send(Action.fetchGalleriesDone(response))
}
.cancellable(id: CancelID.fetchGalleries)

case .fetchGalleriesDone(let result):
state.loadingState = .idle
Expand Down Expand Up @@ -136,9 +139,11 @@ struct DetailSearchReducer: Reducer {
else { return .none }
state.footerLoadingState = .loading
let filter = databaseClient.fetchFilterSynchronously(range: .search)
return MoreSearchGalleriesRequest(keyword: state.lastKeyword, filter: filter, lastID: lastID).effect
.map(Action.fetchMoreGalleriesDone)
.cancellable(id: CancelID.fetchMoreGalleries)
return .run { [lastKeyword = state.lastKeyword] send in
let response = await MoreSearchGalleriesRequest(keyword: lastKeyword, filter: filter, lastID: lastID).response()
await send(Action.fetchMoreGalleriesDone(response))
}
.cancellable(id: CancelID.fetchMoreGalleries)

case .fetchMoreGalleriesDone(let result):
state.footerLoadingState = .idle
Expand Down
7 changes: 5 additions & 2 deletions EhPanda/View/Detail/Previews/PreviewsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,11 @@ struct PreviewsReducer: Reducer {
else { return .none }
state.loadingState = .loading
let pageNum = state.previewConfig.pageNumber(index: index)
return GalleryPreviewURLsRequest(galleryURL: galleryURL, pageNum: pageNum)
.effect.map(Action.fetchPreviewURLsDone).cancellable(id: CancelID.fetchPreviewURLs)
return .run { send in
let response = await GalleryPreviewURLsRequest(galleryURL: galleryURL, pageNum: pageNum).response()
await send(Action.fetchPreviewURLsDone(response))
}
.cancellable(id: CancelID.fetchPreviewURLs)

case .fetchPreviewURLsDone(let result):
state.loadingState = .idle
Expand Down
14 changes: 10 additions & 4 deletions EhPanda/View/Detail/Torrents/TorrentsReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ struct TorrentsReducer: Reducer {
return .none

case .fetchTorrent(let hash, let torrentURL):
return DataRequest(url: torrentURL).effect.map({ Action.fetchTorrentDone(hash, $0) })
.cancellable(id: CancelID.fetchTorrent)
return .run { send in
let response = await DataRequest(url: torrentURL).response()
await send(Action.fetchTorrentDone(hash, response))
}
.cancellable(id: CancelID.fetchTorrent)

case .teardown:
return .merge(CancelID.allCases.map(Effect.cancel(id:)))
Expand All @@ -89,8 +92,11 @@ struct TorrentsReducer: Reducer {
case .fetchGalleryTorrents(let gid, let token):
guard state.loadingState != .loading else { return .none }
state.loadingState = .loading
return GalleryTorrentsRequest(gid: gid, token: token)
.effect.map(Action.fetchGalleryTorrentsDone).cancellable(id: CancelID.fetchGalleryTorrents)
return .run { send in
let response = await GalleryTorrentsRequest(gid: gid, token: token).response()
await send(Action.fetchGalleryTorrentsDone(response))
}
.cancellable(id: CancelID.fetchGalleryTorrents)

case .fetchGalleryTorrentsDone(let result):
state.loadingState = .idle
Expand Down
26 changes: 15 additions & 11 deletions EhPanda/View/Favorites/FavoritesReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ struct FavoritesReducer: Reducer {
} else {
state.rawPageNumber[state.index]?.resetPages()
}
return FavoritesGalleriesRequest(
favIndex: state.index, keyword: state.keyword, sortOrder: sortOrder
)
.effect.map { [index = state.index] result in Action.fetchGalleriesDone(index, result) }
return .run { [state] send in
let response = await FavoritesGalleriesRequest(
favIndex: state.index, keyword: state.keyword, sortOrder: sortOrder
).response()
await send(Action.fetchGalleriesDone(state.index, response))
}

case .fetchGalleriesDone(let targetFavIndex, let result):
state.rawLoadingState[targetFavIndex] = .idle
Expand Down Expand Up @@ -146,13 +148,15 @@ struct FavoritesReducer: Reducer {
let lastItemTimestamp = pageNumber.lastItemTimestamp
else { return .none }
state.rawFooterLoadingState[state.index] = .loading
return MoreFavoritesGalleriesRequest(
favIndex: state.index,
lastID: lastID,
lastTimestamp: lastItemTimestamp,
keyword: state.keyword
)
.effect.map { [index = state.index] result in Action.fetchMoreGalleriesDone(index, result) }
return .run { [state] send in
let response = await MoreFavoritesGalleriesRequest(
favIndex: state.index,
lastID: lastID,
lastTimestamp: lastItemTimestamp,
keyword: state.keyword
).response()
await send(Action.fetchMoreGalleriesDone(state.index, response))
}

case .fetchMoreGalleriesDone(let targetFavIndex, let result):
state.rawFooterLoadingState[targetFavIndex] = .idle
Expand Down
Loading