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

Feature/navigation update #47

Open
wants to merge 7 commits into
base: feature/mac-support
Choose a base branch
from

Conversation

ZvonimirMedak
Copy link
Collaborator

@ZvonimirMedak ZvonimirMedak commented Jan 21, 2025

Summary

I have update the current state of the UserDefaults tool to match the changes done in the preferences tab, and vice versa. Also, I have updated the macOS navigation so that the users can now pop the view in the NavigationSplitView that's used on macOS instead of being open for no reason.

Changes

The navigation changes are mostly done only for macOS since we needed to provide the selection binding from the SentinelListView.
The preference tab changes only added an onAppear to update the value if needed.
The UserDefaults changes are updating the view onAppear as well.

Type

  • Feature: This pull request introduces a new feature.
  • Bug fix: This pull request fixes a bug.
  • Refactor: This pull request refactors existing code.
  • Documentation: This pull request updates documentation.
  • Other: This pull request makes other changes.

Additional information

  • This pull request introduces a breaking change.

Description

Everything was mentioned in the changes section

Sentinel.updates.mov

Checklist

  • I have performed a self-review of my own code.
  • I have tested my changes, including edge cases.
  • I have added necessary tests for the changes introduced (if applicable).
  • I have updated the documentation to reflect my changes (if applicable).

Additional notes

@ZvonimirMedak ZvonimirMedak added the enhancement New feature or request label Jan 21, 2025
@ZvonimirMedak ZvonimirMedak added this to the 2.0.0 milestone Jan 21, 2025
@ZvonimirMedak ZvonimirMedak self-assigned this Jan 21, 2025
Copy link
Member

@nikolamajcen nikolamajcen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! Still, check the comments I've added.

Comment on lines +41 to +74
#if os(macOS)
ToolTableItem.navigation(
NavigationToolItem(
title: key,
didSelect: {
UserDefaultsToolDetailView(
viewModel: UserDefaultsToolDetailViewModel(
value: String(describing: value),
title: key,
userDefaults: userDefaults,
didDeleteProperty: { [unowned self] in sections = createSectionItems(with: userDefaults) }
),
selection: $0
)
}
)
)
#else
ToolTableItem.navigation(
NavigationToolItem(
title: key,
didSelect: {
UserDefaultsToolDetailView(
viewModel: UserDefaultsToolDetailViewModel(
value: String(describing: value),
title: key,
userDefaults: userDefaults,
didDeleteProperty: nil // onAppear will update the screen on iOS
)
)
}
)
)
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer moving didSelect into separate method, or just defining didDeleteProperty as a standalone variable and init the variable based on if-else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference between didSelect closures is messing up this one. The macOS one has a value provided in it which is then sent as the selection parameter, and the iOS one doesn't. Nothing comes to mind on how to handle this elegantly. Maybe you might think of something

#if os(macOS)
selection = nil
#else
presentationMode.wrappedValue.dismiss() // on macOS dismisses the whole window which isn't desired
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen this used multiple times; can we instead make an extension that will handle this case by calling it as a one liner on a calling side and define inner logic in the extension?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To extract this into a protocol or something we would still have to have if/else since the selection is hidden behind an if macos, and we would have to provide it somehow. It's called twice in the codebase, so for now, maybe we can leave it as is since macOS might be upped to version 13 so we can use NavigationStack

@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
@ObservedObject var viewModel: UserDefaultsToolDetailViewModel
#if os(macOS)
@Binding var selection: String?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this to the viewModel?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a view specific binding, I feel like we should keep it here

let title: String
let onValueChanged: (Bool) -> Void
let getter: () -> Bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which issue is fixed with adding a getter which is called on onAppear? Does item.loadStoredValue() not provide the correct value, and if not, in which cases?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was if we remove a value from the UserDefaultsTool which was in preferences, when we go back to the preferences it would keep the previous value since it was only instantiated once. This way we would check the value every time we enter the screen since it might have changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants