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

Add post title to Gutenberg Mobile #450

Merged
merged 40 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
8c89460
WIP: adding the post title to the editor component.
diegoreymendez Dec 26, 2018
6c5d701
WIP: The title is now properly formatted and the default block append…
diegoreymendez Dec 26, 2018
eb361cb
Lint fixes.
diegoreymendez Dec 26, 2018
d80dba6
WIP: stashing.
diegoreymendez Jan 3, 2019
b788654
Implements an initial version of post-title in gutenberg.
diegoreymendez Jan 4, 2019
16181fd
Updates the gutenberg submodule.
diegoreymendez Jan 4, 2019
739cf56
Updates the gutenberg submodule reference.
diegoreymendez Jan 4, 2019
ea8288c
Adds an interface for setting the post title from native.
diegoreymendez Jan 8, 2019
818325f
The title can now be set from the parent app.
diegoreymendez Jan 8, 2019
fc425ca
Adds initial title to the datasource.
diegoreymendez Jan 8, 2019
99fe984
Fixes an issue with the initial setup of the title.
diegoreymendez Jan 8, 2019
e4e4ed5
WIP: implementing js -> native title updates.
diegoreymendez Jan 9, 2019
dcca2c6
Now updates the title through provideToNative_Html.
diegoreymendez Jan 10, 2019
271da87
Fixes an issue that was causing the title not to report changes.
diegoreymendez Jan 10, 2019
469c3fc
Fixes a mistake in the previous commit.
diegoreymendez Jan 10, 2019
46a20ca
Improvements to set the title in our RN code.
diegoreymendez Jan 10, 2019
efceada
Fixes the appearance of the title and separator.
diegoreymendez Jan 10, 2019
b53123a
Updates the gutenberg submodule.
diegoreymendez Jan 10, 2019
ebaf39e
Merge branch 'master' into issue/372-add-title-to-gutenberg-mobile
diegoreymendez Jan 10, 2019
6f723db
Fixes some issues with the linting.
diegoreymendez Jan 10, 2019
e31e844
Updates the gutenberg submodule.
diegoreymendez Jan 10, 2019
7ca5656
Fixes some breaking unit tests.
diegoreymendez Jan 10, 2019
f487db8
Merges the latest from develop.
diegoreymendez Jan 10, 2019
bec3537
Adds NotoSerif to the demo project.
diegoreymendez Jan 10, 2019
e98f6fc
Regenerated the bundles.
diegoreymendez Jan 10, 2019
1e62bdd
Merges the latest from develop.
diegoreymendez Jan 11, 2019
10e112a
Updates to the latest changes in Gutenberg to handle title focusing.
diegoreymendez Jan 16, 2019
c29bdca
Updates the gutenberg submodule.
diegoreymendez Jan 17, 2019
87dfddf
Updates the gutenberg submodule.
diegoreymendez Jan 17, 2019
5c97308
Merges the latest from develop.
diegoreymendez Jan 17, 2019
21f39b6
Fixes a bug that was causing the title not to update anymore.
diegoreymendez Jan 17, 2019
1d64d25
WIP: Adds two symlinks to try and fix the breaking tests.
diegoreymendez Jan 17, 2019
1062340
Adds symlinks to fix issues with jest.
diegoreymendez Jan 17, 2019
1e6776a
Modify the interface for setting the content/title from native in the…
daniloercoli Jan 21, 2019
6968c62
Merge pull request #482 from wordpress-mobile/372-android-add-title-t…
diegoreymendez Jan 21, 2019
3293e97
Update RNAztecWrapper hash
daniloercoli Jan 22, 2019
0b5e9b1
Merged the latest from develop.
diegoreymendez Jan 23, 2019
e7b3b8f
[Android] - Make sure mContentChanged has the correct value when aski…
daniloercoli Jan 24, 2019
38ed202
Merge branch 'develop' of https://github.com/wordpress-mobile/gutenbe…
daniloercoli Jan 24, 2019
ec1418f
Update GB hash
daniloercoli Jan 24, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,773 changes: 896 additions & 877 deletions bundle/android/App.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/android/App.js.map

Large diffs are not rendered by default.

1,785 changes: 902 additions & 883 deletions bundle/ios/App.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bundle/ios/App.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gutenberg
Submodule gutenberg updated 429 files
33 changes: 33 additions & 0 deletions ios/gutenberg.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
F151983C2100DC3D000F6E97 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F15198392100DC3D000F6E97 /* AppDelegate.swift */; };
F151983D2100DC3D000F6E97 /* MediaProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = F151983A2100DC3D000F6E97 /* MediaProvider.swift */; };
F19CFDA821021EB100EAB240 /* Aztec.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = F1289ECA2100E4320091E81D /* Aztec.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F1EE6F7821E7F0A500241744 /* NotoSerif-BoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F1EE6F7421E7F0A500241744 /* NotoSerif-BoldItalic.ttf */; };
F1EE6F7921E7F0A500241744 /* NotoSerif-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F1EE6F7521E7F0A500241744 /* NotoSerif-Regular.ttf */; };
F1EE6F7A21E7F0A500241744 /* NotoSerif-Italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F1EE6F7621E7F0A500241744 /* NotoSerif-Italic.ttf */; };
F1EE6F7B21E7F0A500241744 /* NotoSerif-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F1EE6F7721E7F0A500241744 /* NotoSerif-Bold.ttf */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -423,6 +427,10 @@
F15198372100DC3C000F6E97 /* gutenberg-Bridging-Header.h */ = {isa = PBXFileReference; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = "gutenberg-Bridging-Header.h"; sourceTree = "<group>"; tabWidth = 1; };
F15198392100DC3D000F6E97 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = gutenberg/AppDelegate.swift; sourceTree = "<group>"; tabWidth = 1; };
F151983A2100DC3D000F6E97 /* MediaProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; name = MediaProvider.swift; path = gutenberg/MediaProvider.swift; sourceTree = "<group>"; tabWidth = 1; usesTabs = 0; };
F1EE6F7421E7F0A500241744 /* NotoSerif-BoldItalic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSerif-BoldItalic.ttf"; sourceTree = "<group>"; };
F1EE6F7521E7F0A500241744 /* NotoSerif-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSerif-Regular.ttf"; sourceTree = "<group>"; };
F1EE6F7621E7F0A500241744 /* NotoSerif-Italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSerif-Italic.ttf"; sourceTree = "<group>"; };
F1EE6F7721E7F0A500241744 /* NotoSerif-Bold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "NotoSerif-Bold.ttf"; sourceTree = "<group>"; };
F619623252704B46A619C33C /* RNTAztecView.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNTAztecView.xcodeproj; path = "../react-native-aztec/ios/RNTAztecView.xcodeproj"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -678,6 +686,7 @@
isa = PBXGroup;
children = (
13B07FAE1A68108700A75B9A /* gutenberg */,
F1EE6F7221E7F0A500241744 /* resources */,
832341AE1AAA6A7D00B99B32 /* Libraries */,
00E356EF1AD99517003FC87E /* gutenbergTests */,
83CBBA001A601CBA00E9B192 /* Products */,
Expand Down Expand Up @@ -744,6 +753,26 @@
name = Products;
sourceTree = "<group>";
};
F1EE6F7221E7F0A500241744 /* resources */ = {
isa = PBXGroup;
children = (
F1EE6F7321E7F0A500241744 /* fonts */,
);
name = resources;
path = ../resources;
sourceTree = "<group>";
};
F1EE6F7321E7F0A500241744 /* fonts */ = {
isa = PBXGroup;
children = (
F1EE6F7421E7F0A500241744 /* NotoSerif-BoldItalic.ttf */,
F1EE6F7521E7F0A500241744 /* NotoSerif-Regular.ttf */,
F1EE6F7621E7F0A500241744 /* NotoSerif-Italic.ttf */,
F1EE6F7721E7F0A500241744 /* NotoSerif-Bold.ttf */,
);
path = fonts;
sourceTree = "<group>";
};
FFEDF6EF21241BDF007FCC6D /* Products */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1266,7 +1295,11 @@
buildActionMask = 2147483647;
files = (
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
F1EE6F7B21E7F0A500241744 /* NotoSerif-Bold.ttf in Resources */,
F1EE6F7921E7F0A500241744 /* NotoSerif-Regular.ttf in Resources */,
F1EE6F7A21E7F0A500241744 /* NotoSerif-Italic.ttf in Resources */,
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
F1EE6F7821E7F0A500241744 /* NotoSerif-BoldItalic.ttf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 10 additions & 3 deletions ios/gutenberg/GutenbergViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ class GutenbergViewController: UIViewController {

extension GutenbergViewController: GutenbergBridgeDelegate {
func gutenbergDidLoad() {

}

func gutenbergDidProvideHTML(_ html: String, changed: Bool) {
print("Did receive HTML: \(html) changed: \(changed)")
func gutenbergDidProvideHTML(title: String, html: String, changed: Bool) {
print("didProvideHTML:")
print("↳ Content changed: \(changed)")
print("↳ Title: \(title)")
print("↳ HTML: \(html)")
}

func gutenbergDidRequestMediaPicker(with callback: @escaping MediaPickerDidPickMediaCallback) {
Expand All @@ -47,6 +50,10 @@ extension GutenbergViewController: GutenbergBridgeDataSource {
func gutenbergInitialContent() -> String? {
return nil
}

func gutenbergInitialTitle() -> String? {
return nil
}

func aztecAttachmentDelegate() -> TextViewAttachmentDelegate {
return ExampleAttachmentDelegate()
Expand Down
8 changes: 7 additions & 1 deletion ios/gutenberg/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIAppFonts</key>
<array>
<string>NotoSerif-BoldItalic.ttf</string>
<string>NotoSerif-Regular.ttf</string>
<string>NotoSerif-Italic.ttf</string>
<string>NotoSerif-Bold.ttf</string>
</array>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
Expand Down Expand Up @@ -41,7 +48,6 @@
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSAppTransportSecurity</key>
<!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
<dict>
<key>NSExceptionDomains</key>
<dict>
Expand Down
1 change: 1 addition & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ jest.mock( '../react-native-gutenberg-bridge', () => {
removeEventListener: jest.fn(),
subscribeParentGetHtml: jest.fn(),
subscribeParentToggleHTMLMode: jest.fn(),
subscribeSetTitle: jest.fn(),
subscribeUpdateHtml: jest.fn(),
};
} );
Expand Down
4 changes: 4 additions & 0 deletions react-native-gutenberg-bridge/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function subscribeParentToggleHTMLMode( callback ) {
return gutenbergBridgeEvents.addListener( 'toggleHTMLMode', callback );
}

export function subscribeSetTitle( callback ) {
return gutenbergBridgeEvents.addListener( 'setTitle', callback );
}

export function subscribeUpdateHtml( callback ) {
return gutenbergBridgeEvents.addListener( 'updateHtml', callback );
}
Expand Down
20 changes: 16 additions & 4 deletions react-native-gutenberg-bridge/ios/Gutenberg.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ public class Gutenberg: NSObject {
}()

private var initialProps: [String: String]? {
guard let initialContent = dataSource.gutenbergInitialContent() else {
return nil
var initialProps = [String: String]()

if let initialContent = dataSource.gutenbergInitialContent() {
initialProps["initialData"] = initialContent
}
return ["initialData": initialContent]

if let initialTitle = dataSource.gutenbergInitialTitle() {
initialProps["initialTitle"] = initialTitle
}

return initialProps
}

public init(dataSource: GutenbergBridgeDataSource) {
Expand All @@ -56,8 +63,12 @@ public class Gutenberg: NSObject {
bridgeModule.sendEvent(withName: EventName.toggleHTMLMode, body: nil)
}

public func setTitle(_ title: String) {
bridgeModule.sendEvent(withName: EventName.setTitle, body: ["title": title])
}

public func updateHtml(_ html: String) {
bridgeModule.sendEvent(withName: EventName.updateHtml, body: [ "html": html ])
bridgeModule.sendEvent(withName: EventName.updateHtml, body: ["html": html])
}
}

Expand All @@ -77,6 +88,7 @@ extension Gutenberg: RCTBridgeDelegate {
extension Gutenberg {
enum EventName {
static let requestHTML = "requestGetHtml"
static let setTitle = "setTitle"
static let toggleHTMLMode = "toggleHTMLMode"
static let updateHtml = "updateHtml"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ public protocol GutenbergBridgeDataSource: class {
///
/// - Returns: The HTML initial content or nil.
func gutenbergInitialContent() -> String?

/// Asks the data source for the initial title to be presented by the editor.
/// Return `nil` to show the example content.
///
/// - Returns: The HTML initial title or nil.
func gutenbergInitialTitle() -> String?

/// Asks the data source for an object conforming to `TextViewAttachmentDelegate`
/// to handle media loading.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ public protocol GutenbergBridgeDelegate: class {
/// You can request HTML content by calling `requestHTML()` on a Gutenberg bridge instance.
///
/// - Parameters:
/// - html: The current HTML presented by the editor.
/// - changed: True if the given HTML presents changes from the last request or initial value.
func gutenbergDidProvideHTML(_ html: String, changed: Bool)
/// - title: the title as shown by the editor.
/// - html: The current HTML presented by the editor.
/// - changed: True if the given HTML presents changes from the last request or initial value.
func gutenbergDidProvideHTML(title: String, html: String, changed: Bool)

/// Tells the delegate that an image block requested an image from the media picker.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

@interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject)

RCT_EXTERN_METHOD(provideToNative_Html:(NSString *)html changed:(BOOL)changed)
RCT_EXTERN_METHOD(provideToNative_Html:(NSString *)html title:(NSString*)title changed:(BOOL)changed)
RCT_EXTERN_METHOD(onMediaLibraryPress:(RCTResponseSenderBlock)callback)
RCT_EXTERN_METHOD(editorDidLayout)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter {
// MARK: - Messaging methods

@objc
func provideToNative_Html(_ html: String, changed: Bool) {
func provideToNative_Html(_ html: String, title: String, changed: Bool) {
DispatchQueue.main.async {
self.delegate?.gutenbergDidProvideHTML(html, changed: changed)
self.delegate?.gutenbergDidProvideHTML(title: title, html: html, changed: changed)
}
}

Expand Down Expand Up @@ -36,6 +36,7 @@ extension RNReactNativeGutenbergBridge {
return [
Gutenberg.EventName.requestHTML,
Gutenberg.EventName.toggleHTMLMode,
Gutenberg.EventName.setTitle,
Gutenberg.EventName.updateHtml
]
}
Expand Down
Binary file added resources/fonts/NotoSerif-Bold.ttf
Binary file not shown.
Binary file added resources/fonts/NotoSerif-BoldItalic.ttf
Binary file not shown.
Binary file added resources/fonts/NotoSerif-Italic.ttf
Binary file not shown.
Binary file added resources/fonts/NotoSerif-Regular.ttf
Binary file not shown.
13 changes: 11 additions & 2 deletions src/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ if ( ! __DEV__ ) {
type PropsType = {
initialData: string,
initialHtmlModeEnabled: boolean,
initialTitle: string,
};

const AppProvider = ( { initialData, initialHtmlModeEnabled }: PropsType ) => {
const AppProvider = ( { initialTitle, initialData, initialHtmlModeEnabled }: PropsType ) => {
if ( initialData === undefined ) {
initialData = initialHtml;
}

if ( initialTitle === undefined ) {
initialTitle = 'Welcome to Gutenberg!';
}

return (
<AppContainer initialHtml={ initialData } initialHtmlModeEnabled={ initialHtmlModeEnabled } />
<AppContainer
initialHtml={ initialData }
initialHtmlModeEnabled={ initialHtmlModeEnabled }
title={ initialTitle } />
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/app/App.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe( 'App', () => {
.forEach( ( blockHolder ) => {
if ( 'core/heading' === blockHolder.props.name ) {
const aztec = blockHolder.findByType( 'RCTAztecView' );
expect( aztec.props.text.text ).toBe( '<h2>Welcome to Gutenberg</h2>' );
expect( aztec.props.text.text ).toBe( '<h2>What is Gutenberg?</h2>' );
}
} );
} );
Expand Down
28 changes: 25 additions & 3 deletions src/app/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ type PropsType = {
onSelect: string => mixed,
clearSelectedBlock: void => void,
onAttributesUpdate: ( string, mixed ) => mixed,
title: string,
initialHtml: string,
setupEditor: ( mixed, ?mixed ) => mixed,
clientId: string,
};

class AppContainer extends React.Component<PropsType> {
type StateType = {
title: string,
};

class AppContainer extends React.Component<PropsType, StateType> {
lastHtml: ?string;
lastTitle: ?string;

constructor( props: PropsType ) {
super( props );
Expand All @@ -47,8 +53,13 @@ class AppContainer extends React.Component<PropsType> {
type: 'draft',
};

this.props.setupEditor( post );
this.state = {
title: props.title,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think instead of holding title in current component's state we might need to update the central store with the new title and inject it into props within withSelect just like we do for isBlockSelected, selectedBlockIndex, blocks etc.
In order to achieve that we can imitate what web is doing in components/post-title/index.js, looks like they are calling editPost function from 'core/editor' with a parameter like { title: "new Title" } whenever a title is updated. They are making use of withDispatch to inject onUpdate method to props.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This brings up two questions in my head.

The first one is: As I understand, this is to keep in line with the rest of the architecture, or is there a technical reason why this is necessary before merging the PR?

The second question is related to the first one: Is this urgent or can I work on it incrementally? I'd like if possible to work on more atomic PRs to avoid monolithic ones which can become very complex very fast.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the number of lines would probably decrease after using the store because we'll be getting rid of propagating title change through props and we'll remove the state, and considering that it'll require same tests it doesn't look like an incremental change to me. The technical reason could be that currently the store doesn't know about the title at all, so I feel like we'll need to address this sooner or later but I don't want to block or get in the way of anything. Maybe other reviewers have other opinions on this.

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 the number of lines would probably decrease after using the store because we'll be getting rid of propagating title change through props and we'll remove the state, and considering that it'll require same tests it doesn't look like an incremental change to me.

Working incrementally is 100% about simplifying the steps.

My reasoning is:

  • The PR is working right now, all the way to WPiOS.
  • I can deliver something today and work to make it better. I commit to this!
  • We can close 3 PRs and avoid having to keep resolving conflicts meanwhile.

The technical reason could be that currently the store doesn't know about the title at all, so I feel like we'll need to address this sooner or later but I don't want to block or get in the way of anything. Maybe other reviewers have other opinions on this.

Right now, Aztec is being able to query the title as it is.

Again, I'm definitely not advocating to do things the wrong way... just proposing that we split the steps. It's only a difference in methodology.

From what I can tell, we should also get the feature sooner this way.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can open a separate issue and move fwd on this I think. And It'd be good to have opinion of @hypest also. I'll keep on reviewing this in parallel I couldn't finish it yet.

Copy link
Contributor

Choose a reason for hiding this comment

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

👋. I think it's OK to work by splitting to separate steps, even if a step will actually revise code written from a previous step. Reason is that it can help scope down the change (note, not the same as minimizing lines-of-code change) and review it easier/faster.

What I would recommend though is to at least add some inline comments in the places that we're pretty sure we'll touch in a follow up PR. For example, a suitable comment in this case is that we'd like to move the state to the Redux Store (data) so, this local state is only a intermediate step. Hope this makes sense!

Copy link
Contributor Author

@diegoreymendez diegoreymendez Jan 16, 2019

Choose a reason for hiding this comment

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

I still don't have the knowledge to know what'll need to be changed or where. Sorry about that!

But since we'll need to wait a bit on the Android part I'll try branching off this PR and pushing forward the changes in parallel.

Sounds good?

Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't have the knowledge to know what'll need to be changed or where. Sorry about that!

No prob! Let's just handle the cases already commented about, cool?

@Tug , can you have a look at the Gutenberg-web codebase to figure out where is the post title stored? Is it in the Redux store or elsewhere? @diegoreymendez let's add a comment about this when Tug gets insight on this one, cool?

But since we'll need to wait a bit on the Android part I'll try branching off this PR and pushing forward the changes in parallel.

Sounds good?

That's fine, sure. I'm mainly trying to care about the points already brought up during this review so we don't lose sight of them. We can always handle/fix/update things in follow up PRs.

Copy link
Contributor

@Tug Tug Jan 17, 2019

Choose a reason for hiding this comment

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

the title is part of the post:

const post = {
	id: 1,
	title: {
		raw: props.title,
	},
	content: {
		raw: props.initialHtml,
	},
	status: 'draft',
};
props.setupEditor( post );

We don't need to use the component state for that, it's in the global store.

We can then access/modify it using getEditedPostAttribute( 'title' ) and editPost( { title } ) and it's added to the list of edits!
See the exemple here: https://github.com/WordPress/gutenberg/tree/master/packages/editor/src/components/post-title/index.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @Tug. While I didn't tackle this in this PR, I'm now opening a new one to take care of it.

This was very valuable and insightful.

};

props.setupEditor( post );
this.lastHtml = serialize( parse( props.initialHtml ) );
this.lastTitle = props.title;

if ( props.initialHtmlModeEnabled && ! props.showHtml ) {
// enable html mode if the initial mode the parent wants it but we're not already in it
Expand Down Expand Up @@ -91,15 +102,24 @@ class AppContainer extends React.Component<PropsType> {
if ( this.props.showHtml ) {
this.parseBlocksAction( this.props.editedPostContent );
}

const html = serialize( this.props.blocks );
RNReactNativeGutenbergBridge.provideToNative_Html( html, this.lastHtml !== html );
const hasChanges = this.state.title !== this.lastTitle || this.lastHtml !== html;
Copy link
Contributor

Choose a reason for hiding this comment

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

Noticed that hasChanges is returned to the Android (wp-android) side as false, even if i changed the content of the post in the editor. The first time the native side calls the method to retrieve the content from RN, true is returned, and then the next calls to retrieve the content return false.

Copy link
Contributor Author

@diegoreymendez diegoreymendez Jan 24, 2019

Choose a reason for hiding this comment

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

Is this a regression or is this a problem with the original logic (before my changes) too?

The reason I'm asking is that the condition and logic haven't changed much in terms of what happens when you edit the content, and if this issue was part of the original logic, fixing it is outside of the purpose of this PR.


RNReactNativeGutenbergBridge.provideToNative_Html( html, this.state.title, hasChanges );

this.lastTitle = this.state.title;
this.lastHtml = html;
};

toggleHtmlModeAction = () => {
this.props.onToggleBlockMode( this.props.rootClientId );
};

setTitleAction = ( title: string ) => {
this.setState( { title: title } );
};

updateHtmlAction = ( html: string ) => {
this.parseBlocksAction( html );
};
Expand All @@ -122,9 +142,11 @@ class AppContainer extends React.Component<PropsType> {
createBlockAction={ this.createBlockAction }
serializeToNativeAction={ this.serializeToNativeAction }
toggleHtmlModeAction={ this.toggleHtmlModeAction }
setTitleAction={ this.setTitleAction }
updateHtmlAction={ this.updateHtmlAction }
mergeBlocksAction={ this.mergeBlocksAction }
isBlockSelected={ this.props.isBlockSelected }
title={ this.state.title }
/>
);
}
Expand Down
10 changes: 10 additions & 0 deletions src/app/MainApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react';
import {
subscribeParentGetHtml,
subscribeParentToggleHTMLMode,
subscribeSetTitle,
subscribeUpdateHtml,
} from 'react-native-gutenberg-bridge';

Expand All @@ -25,6 +26,7 @@ type PropsType = {
createBlockAction: ( string, BlockType ) => mixed,
serializeToNativeAction: void => void,
toggleHtmlModeAction: void => void,
setTitleAction: string => void,
updateHtmlAction: string => void,
mergeBlocksAction: ( string, string ) => mixed,
blocks: Array<BlockType>,
Expand All @@ -37,6 +39,7 @@ type StateType = {};
export default class MainScreen extends React.Component<PropsType, StateType> {
subscriptionParentGetHtml: ?EmitterSubscription;
subscriptionParentToggleHTMLMode: ?EmitterSubscription;
subscriptionParentSetTitle: ?EmitterSubscription;
subscriptionParentUpdateHtml: ?EmitterSubscription;

componentDidMount() {
Expand All @@ -48,6 +51,10 @@ export default class MainScreen extends React.Component<PropsType, StateType> {
this.props.toggleHtmlModeAction();
} );

this.subscriptionParentSetTitle = subscribeSetTitle( ( payload ) => {
this.props.setTitleAction( payload.title );
} );

this.subscriptionParentUpdateHtml = subscribeUpdateHtml( ( payload ) => {
this.props.updateHtmlAction( payload.html );
} );
Expand All @@ -60,6 +67,9 @@ export default class MainScreen extends React.Component<PropsType, StateType> {
if ( this.subscriptionParentToggleHTMLMode ) {
this.subscriptionParentToggleHTMLMode.remove();
}
if ( this.subscriptionParentSetTitle ) {
this.subscriptionParentSetTitle.remove();
}
if ( this.subscriptionParentUpdateHtml ) {
this.subscriptionParentUpdateHtml.remove();
}
Expand Down
Loading