-
Notifications
You must be signed in to change notification settings - Fork 19
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
Check favorite sessions in Schedule View #41
base: main
Are you sure you want to change the base?
Changes from 6 commits
875b195
33888d9
08a2b0d
c32c5bf
cf49338
5a32df4
846098f
23983b5
a7a611b
0e8b403
daa7fa7
1a5419a
35b4d14
f2622b8
b648df2
a929586
4e279e4
1db51b5
d3a49ab
04cefc0
d3b9901
cfb2fa3
77b7a09
0e3b9f8
6cca9bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ public struct Schedule { | |
case onAppear | ||
case disclosureTapped(Session) | ||
case mapItemTapped | ||
case favoriteIconTapped(Session) | ||
} | ||
} | ||
|
||
|
@@ -104,6 +105,23 @@ public struct Schedule { | |
#elseif os(visionOS) | ||
return .run { _ in await openURL(url) } | ||
#endif | ||
case let .view(.favoriteIconTapped(session)): | ||
switch state.selectedDay { | ||
case .day1: | ||
state.day1 = update(state.day1!, togglingFavoriteOf: session) | ||
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. I think saving 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.
Thank you. 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. To create save method for Further background...
Therefore, I resulted in it's better to create 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. Sorry, I realized that it's better to use 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. |
||
case .day2: | ||
state.day2 = update(state.day2!, togglingFavoriteOf: session) | ||
case .day3: | ||
state.workshop = update(state.workshop!, togglingFavoriteOf: session) | ||
} | ||
let day1 = state.day1! | ||
let day2 = state.day2! | ||
let workshop = state.workshop! | ||
return .run { _ in | ||
try? dataClient.saveDay1(day1) | ||
try? dataClient.saveDay2(day2) | ||
try? dataClient.saveWorkshop(workshop) | ||
} | ||
case let .fetchResponse(.success(response)): | ||
state.day1 = response.day1 | ||
state.day2 = response.day2 | ||
|
@@ -122,6 +140,12 @@ public struct Schedule { | |
.forEach(\.path, action: \.path) | ||
.ifLet(\.$destination, action: \.destination) | ||
} | ||
|
||
private func update(_ conference: Conference, togglingFavoriteOf session: Session) -> Conference { | ||
var newValue = conference | ||
newValue.toggleFavorite(of: session) | ||
return newValue | ||
} | ||
} | ||
|
||
@ViewAction(for: Schedule.self) | ||
|
@@ -288,6 +312,22 @@ public struct ScheduleView: View { | |
} | ||
} | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
|
||
favoriteIcon(for: session) | ||
.onTapGesture { | ||
send(.favoriteIconTapped(session)) | ||
} | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func favoriteIcon(for session: Session) -> some View { | ||
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. These logic should put in Reducer so that we can write test easily. 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. I'm sorry that I can't image which part of logic to put in Reducer. Now I implemented 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. I moved these logic to 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. Please remove this method if you have moved. 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. Sorry for my lack of explanation. |
||
if let isFavorited = session.isFavorited, isFavorited { | ||
Image(systemName: "star.fill") | ||
.foregroundColor(.yellow) | ||
} else { | ||
Image(systemName: "star") | ||
.foregroundColor(.gray) | ||
} | ||
} | ||
|
||
|
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.
It's better to create UserDefaultsClient instead of DataClient since this will be changed to ApiClient for example.
Also, favorite data is better to store in Document folder instead of User Default. What do you think?
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.
I agree for reading UserDefaults documentation saying
Because favorite data are for saving app's state resulting in user operations, rather than customizing app's behavior.
So I will create FileClient or something... I'm thinking appropriate name that explains what it does, not how it does.
If you have any idea, please tell me.
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.
@d-date I created
FileClient
in 23983b5 and changed save/load area to Document in 0e8b403.I'll change failed test and create new test for star icon behavior from now.