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

feat(list): disallow selection of archived or pending items #751

Merged
merged 2 commits into from
May 22, 2023

Conversation

dskuza
Copy link
Contributor

@dskuza dskuza commented May 22, 2023

Disallows the selection of archived items that contain no offline data, or are pending. Additionally, automatically reloads the current Saves list when the network status changes to show the latest state of the items.

References

IN-1308

Implementation Details

Adds a helper function, isItemDisabled, that returns true if:

  • the user is offline, and an archived item has no article data
  • the user is offline, and an item is pending
  • the user is online, and an item is pending

This is then used to initialize item presenters appropriately for the required state by adding a isDisabled argument. This is because determining whether or not an item is disabled required use of network monitoring, which is outside the scope of a SavedItem.

Additionally, a network monitor is used to determine when to reload the Saves list as to show the most up-to-date status of items. On monitor change, we send an updated snapshot, reloading the item identifiers representing the visible cells (as to not reload the whole list). This will update the item(s) to their correct coloring.

Test Steps

  • Save an item that will have no article components (e.g a google search). Archive the item.
  • Enter airplane mode, and view your archive. The saved item should be greyed out, and tapping it should do nothing.
  • Leave airplane mode, and view your archive. The saved item should not be greyed out, and tapping it should open in web view.

PR Checklist:

  • Added Unit / UI tests
  • Self Review (review, clean up, documentation, run tests)
  • Basic Self QA

@dskuza dskuza requested a review from a team as a code owner May 22, 2023 20:02
@dskuza dskuza requested review from nzeltzer and cyndichin and removed request for a team May 22, 2023 20:02
@pocket-ci
Copy link
Contributor

Messages
📖 No SwiftLint violations! 🎉
📖 Project coverage: 76.03%
📖 Checking XCode Environment Variables
📖 Edited 6 files
📖 Created 0 files

PocketKit: Coverage: 76.2

File Coverage
ItemsListViewModel.swift 50.0% ⚠️
SavedItemsListViewModel.swift 83.75%
ItemsListItemPresenter.swift 83.33%
PocketItem.swift 86.96%
ItemsListViewController.swift 79.73%

Generated by 🚫 Danger Swift against 0dc8c97

Copy link
Collaborator

@Gio2018 Gio2018 left a comment

Choose a reason for hiding this comment

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

Works as described @dskuza ! Just a couple of optional comments, other than that
:shipit: !

Comment on lines 842 to 847
if networkStatus == .unsatisfied {
if item.isArchived {
return !(item.item?.hasArticleComponents ?? false)
} else {
return item.isPending
}
}

return item.isPending
}
Copy link
Collaborator

@Gio2018 Gio2018 May 22, 2023

Choose a reason for hiding this comment

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

maybe we can simplify the conditions here with something like this, wdyt?

guard networkStatus == .unsatisfied, item.isArchived else {
   return item.isPending
}
return !(item.item?.hasArticleComponents ?? false)


init(item: ItemsListItem) {
init(item: ItemsListItem, isDisabled: Bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks like in the existing calls, isDisabled is predominantly set to false: maybe we can add a default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that'd clean up the unit tests a lot, specifically (which is mainly where the additions are).

@dskuza dskuza requested a review from Gio2018 May 22, 2023 21:01
David Skuza added 2 commits May 22, 2023 16:13
Automatically reloads the current Saves list when the network status changes
@dskuza dskuza force-pushed the disable-archive-cells branch from bd43cfc to 7046e8a Compare May 22, 2023 21:13
@dskuza dskuza enabled auto-merge (squash) May 22, 2023 21:13
@dskuza dskuza merged commit 44e4649 into develop May 22, 2023
@dskuza dskuza deleted the disable-archive-cells branch May 22, 2023 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants