-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Basic support of custom post types #25157
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
Open
crazytonyli
wants to merge
12
commits into
trunk
Choose a base branch
from
prototype-custom-post-types
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,278
−49
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
73b4c22
Create WordPressClientFactory
crazytonyli 9575a99
Instantiate WordPressApiCache and service in WordPressClient
crazytonyli 25f9528
Show custom post types
crazytonyli 9f0aadd
Extract `CustomPostCollectionView`
crazytonyli 7ceda6b
Support searching custom posts
crazytonyli c97144c
Re-implement showing loading more states
crazytonyli 842a9cd
Adopt new GBK API
crazytonyli b6aa5cf
Simple post conflict detection
crazytonyli afd3954
Add a Filter type
crazytonyli 98df822
Update wordpress-rs
crazytonyli 014b963
Fix a compilation issue in unit tests
crazytonyli 5070ed6
Add a missing delegate function
crazytonyli 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import Foundation | ||
| import WordPressAPI | ||
| import WordPressAPIInternal | ||
| import WordPressApiCache | ||
|
|
||
| extension WordPressApiCache { | ||
| static func bootstrap() -> WordPressApiCache? { | ||
| let instance: WordPressApiCache? = .onDiskCache() ?? .memoryCache() | ||
| instance?.startListeningForUpdates() | ||
| return instance | ||
| } | ||
|
|
||
| private static func onDiskCache() -> WordPressApiCache? { | ||
| let cacheURL: URL | ||
| do { | ||
| cacheURL = try FileManager.default | ||
| .url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: true) | ||
| .appending(path: "app.sqlite") | ||
| } catch { | ||
| NSLog("Failed to create api cache file: \(error)") | ||
| return nil | ||
| } | ||
|
|
||
| if let cache = WordPressApiCache.onDiskCache(file: cacheURL) { | ||
| return cache | ||
| } | ||
|
|
||
| if FileManager.default.fileExists(at: cacheURL) { | ||
| do { | ||
| try FileManager.default.removeItem(at: cacheURL) | ||
|
|
||
| if let cache = WordPressApiCache.onDiskCache(file: cacheURL) { | ||
| return cache | ||
| } | ||
| } catch { | ||
| NSLog("Failed to delete sqlite database: \(error)") | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| private static func onDiskCache(file: URL) -> WordPressApiCache? { | ||
| let cache: WordPressApiCache | ||
| do { | ||
| cache = try WordPressApiCache(url: file) | ||
| } catch { | ||
| NSLog("Failed to create an instance: \(error)") | ||
| return nil | ||
| } | ||
|
|
||
| do { | ||
| _ = try cache.performMigrations() | ||
| } catch { | ||
| NSLog("Failed to migrate database: \(error)") | ||
| return nil | ||
| } | ||
|
|
||
| return cache | ||
| } | ||
|
|
||
| private static func memoryCache() -> WordPressApiCache? { | ||
| do { | ||
| let cache = try WordPressApiCache() | ||
| _ = try cache.performMigrations() | ||
| return cache | ||
| } catch { | ||
| NSLog("Failed to create memory cache: \(error)") | ||
| return nil | ||
| } | ||
| } | ||
| } |
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
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 |
|---|---|---|
| @@ -1,13 +1,38 @@ | ||
| import Foundation | ||
| import WordPressAPI | ||
| import WordPressAPIInternal | ||
| import WordPressApiCache | ||
|
|
||
| public actor WordPressClient { | ||
|
|
||
| public final actor WordPressClient: Sendable { | ||
| public let siteURL: URL | ||
| public let api: WordPressAPI | ||
| public let rootUrl: String | ||
|
|
||
| public init(api: WordPressAPI, rootUrl: ParsedUrl) { | ||
| private var _cache: WordPressApiCache? | ||
| public var cache: WordPressApiCache? { | ||
| get { | ||
| if _cache == nil { | ||
| _cache = WordPressApiCache.bootstrap() | ||
| } | ||
| return _cache | ||
| } | ||
| } | ||
|
|
||
| private var _service: WpSelfHostedService? | ||
| public var service: WpSelfHostedService? { | ||
| get { | ||
| if _service == nil, let cache { | ||
| do { | ||
| _service = try api.createSelfHostedService(cache: cache) | ||
| } catch { | ||
| NSLog("Failed to create service: \(error)") | ||
| } | ||
| } | ||
| return _service | ||
| } | ||
| } | ||
|
|
||
| public init(api: WordPressAPI, siteURL: URL) { | ||
| self.api = api | ||
| self.rootUrl = rootUrl.url() | ||
| self.siteURL = siteURL | ||
| } | ||
| } |
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
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
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
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
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
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.
(nit) would be nice to wrap this associated values in a struct