-
Notifications
You must be signed in to change notification settings - Fork 49
Fix crash when clicking Ignore/Report without login #42
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,15 +59,25 @@ struct FeedDetailActions { | |
var id: String | ||
|
||
func execute(in store: Store) async { | ||
// Check if user is logged in | ||
guard AccountState.hasSignIn() else { | ||
Toast.show("请先登录") | ||
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能收藏主题")) | ||
return | ||
} | ||
|
||
let state = store.appState.feedDetailStates[id] | ||
let hadStared = state?.model.headerInfo?.hadStared ?? false | ||
Toast.show(hadStared ? "取消收藏" : "收藏中") | ||
let once = state?.model.once | ||
guard let once = state?.model.once else { | ||
Toast.show("操作失败,请刷新页面") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The error message '操作失败,请刷新页面' is duplicated multiple times. Consider defining this as a constant to ensure consistency and easier maintenance. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
return | ||
} | ||
let headers: Params = Headers.topicReferer(id) | ||
|
||
let result: APIResult<FeedDetailInfo> = await APIService.shared | ||
.htmlGet(endpoint: hadStared ? .unStarTopic(id: id): .starTopic(id: id), | ||
["once": once!], | ||
["once": once], | ||
requestHeaders: headers) | ||
dispatch(StarTopicDone(id: id, hadStared: hadStared, result: result)) | ||
} | ||
|
@@ -86,12 +96,22 @@ struct FeedDetailActions { | |
var id: String | ||
|
||
func execute(in store: Store) async { | ||
// Check if user is logged in | ||
guard AccountState.hasSignIn() else { | ||
Toast.show("请先登录") | ||
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能感谢作者")) | ||
return | ||
} | ||
|
||
Toast.show("发送中") | ||
let state = store.appState.feedDetailStates[id] | ||
let once = state?.model.once | ||
guard let once = state?.model.once else { | ||
Toast.show("操作失败,请刷新页面") | ||
return | ||
} | ||
|
||
let step1Result: APIResult<SimpleModel> = await APIService.shared | ||
.post(endpoint: .thanksAuthor(id: id), ["once": once!]) | ||
.post(endpoint: .thanksAuthor(id: id), ["once": once]) | ||
|
||
var success: Bool = false | ||
var toast = "感谢发送失败" | ||
|
@@ -116,11 +136,21 @@ struct FeedDetailActions { | |
var id: String | ||
|
||
func execute(in store: Store) async { | ||
// Check if user is logged in | ||
guard AccountState.hasSignIn() else { | ||
Toast.show("请先登录") | ||
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能忽略主题")) | ||
return | ||
} | ||
|
||
Toast.show("忽略中") | ||
let state = store.appState.feedDetailStates[id] | ||
let once = state?.model.once | ||
guard let once = state?.model.once else { | ||
Toast.show("操作失败,请刷新页面") | ||
return | ||
} | ||
let result: APIResult<FeedInfo> = await APIService.shared | ||
.htmlGet(endpoint: .ignoreTopic(id: id), ["once": once!]) | ||
.htmlGet(endpoint: .ignoreTopic(id: id), ["once": once]) | ||
var ignored = false | ||
if case let .success(result) = result { | ||
ignored = result?.isValid() ?? false | ||
|
@@ -141,11 +171,22 @@ struct FeedDetailActions { | |
var id: String | ||
|
||
func execute(in store: Store) async { | ||
// Check if user is logged in | ||
guard AccountState.hasSignIn() else { | ||
Toast.show("请先登录") | ||
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能举报主题")) | ||
return | ||
} | ||
|
||
Toast.show("举报中") | ||
let state = store.appState.feedDetailStates[id]! | ||
guard let state = store.appState.feedDetailStates[id], | ||
let reportLink = state.model.reportLink else { | ||
Toast.show("操作失败,请刷新页面") | ||
return | ||
} | ||
|
||
let result: APIResult<DailyInfo> = await APIService.shared | ||
.htmlGet(endpoint: .general(url: state.model.reportLink!), | ||
.htmlGet(endpoint: .general(url: reportLink), | ||
requestHeaders: Headers.TINY_REFERER) | ||
var reported = false | ||
if case let .success(result) = result { | ||
|
@@ -166,10 +207,26 @@ struct FeedDetailActions { | |
var id: String | ||
|
||
func execute(in store: Store) async { | ||
// Check if user is logged in | ||
guard AccountState.hasSignIn() else { | ||
Toast.show("请先登录") | ||
dispatch(LoginActions.ShowLoginPageAction(reason: "需要登录才能回复主题")) | ||
return | ||
} | ||
|
||
Toast.show("回复中") | ||
let state = store.appState.feedDetailStates[id]! | ||
guard let state = store.appState.feedDetailStates[id] else { | ||
Toast.show("操作失败,请刷新页面") | ||
return | ||
} | ||
|
||
guard let once = state.model.once else { | ||
Toast.show("操作失败,请刷新页面") | ||
return | ||
} | ||
|
||
var params: Params = Params() | ||
params["once"] = state.model.once | ||
params["once"] = once | ||
params["content"] = state.replyContent | ||
|
||
let result: APIResult<FeedDetailInfo> = await APIService.shared | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The login prompt logic is duplicated across all actions. Consider extracting this into a shared helper method to reduce code duplication and improve maintainability.
Copilot uses AI. Check for mistakes.