-
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 #1436 from planetary-social/note-composer-preview
Note Composer Preview
- Loading branch information
Showing
19 changed files
with
445 additions
and
122 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
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
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import CoreData | ||
|
||
/// Provides a mechanism to store and retrieve an `Event` meant to be used to | ||
/// preview a note the user is composing. | ||
protocol PreviewEventRepository { | ||
/// Creates a preview event object in the database. | ||
/// - Parameters | ||
/// - jsonEvent: JSONEvent object that holds the preview data. | ||
/// - context: Managed object context that will hold the Preview event. | ||
func createPreviewEvent(from jsonEvent: JSONEvent, in context: NSManagedObjectContext) throws -> Event? | ||
|
||
/// Deletes the preview event object from the database. | ||
/// - Parameters | ||
/// - event: Preview event to delete from the database. | ||
/// - context: Managed object context that holds the Preview event. | ||
func deletePreviewEvent(_ event: Event, in context: NSManagedObjectContext) throws | ||
} | ||
|
||
/// Uses `CoreData` to store and retrieve an `Event` meant to be used to | ||
/// preview a note the user is composing. | ||
struct DefaultPreviewEventRepository: PreviewEventRepository { | ||
func createPreviewEvent(from jsonEvent: JSONEvent, in context: NSManagedObjectContext) throws -> Event? { | ||
if let oldPreviewEvent = Event.find(by: Event.previewIdentifier, context: context) { | ||
try deletePreviewEvent(oldPreviewEvent, in: context) | ||
} | ||
var updatedJSONEvent = jsonEvent | ||
updatedJSONEvent.id = Event.previewIdentifier | ||
let newPreviewEvent = try EventProcessor.parse( | ||
jsonEvent: updatedJSONEvent, | ||
from: nil, | ||
in: context, | ||
skipVerification: true | ||
) | ||
try context.saveIfNeeded() | ||
return newPreviewEvent | ||
} | ||
|
||
func deletePreviewEvent(_ event: Event, in context: NSManagedObjectContext) throws { | ||
context.delete(event) | ||
try context.saveIfNeeded() | ||
} | ||
} |
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
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
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.