-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1389 from planetary-social/refactor-refresh
Refactor the New Notes Notification code
- Loading branch information
Showing
8 changed files
with
98 additions
and
124 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,36 +1,19 @@ | ||
import Foundation | ||
|
||
/// Defines a common interface for refreshing. | ||
@MainActor protocol RefreshController: Observable { | ||
/// Whether a refresh should begin or not. | ||
var shouldRefresh: Bool { get } | ||
@Observable @MainActor class RefreshController { | ||
/// Whether a refresh should start or not. When this is `true`, the view and data source will begin refreshing. | ||
var startRefresh: Bool | ||
|
||
/// The last time the view was refreshed. | ||
var lastRefreshDate: Date { get } | ||
|
||
/// Update the state of `shouldRefresh` to the given value. | ||
func setShouldRefresh(_: Bool) | ||
|
||
/// Updates the last refresh date to the given value. | ||
func setLastRefreshDate(_: Date) | ||
} | ||
|
||
/// The default implementation of `RefreshController`. | ||
@Observable @MainActor class DefaultRefreshController: RefreshController { | ||
var shouldRefresh: Bool | ||
|
||
var lastRefreshDate: Date | ||
|
||
init(shouldRefresh: Bool = false, lastRefreshDate: Date = .now) { | ||
self.shouldRefresh = shouldRefresh | ||
self.lastRefreshDate = lastRefreshDate | ||
} | ||
|
||
func setShouldRefresh(_ shouldRefresh: Bool) { | ||
self.shouldRefresh = shouldRefresh | ||
} | ||
|
||
func setLastRefreshDate(_ lastRefreshDate: Date) { | ||
|
||
/// Initializes a refresh controller with the given parameters. | ||
/// - Parameters: | ||
/// - startRefresh: Whether a refresh should start or not. Defaults to `false`. | ||
/// - lastRefreshDate: The last time the view was refreshed. Defaults to `.now`. | ||
init(startRefresh: Bool = false, lastRefreshDate: Date = .now) { | ||
self.startRefresh = startRefresh | ||
self.lastRefreshDate = lastRefreshDate | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.