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 Block: Chat #1632

Closed
wants to merge 7 commits into from
Closed

Add Block: Chat #1632

wants to merge 7 commits into from

Conversation

swissspidy
Copy link
Member

Just like in the mockups, I added different colors for various speakers / chat participants. The whole parsing is super simple for now. Perhaps that would need to be improved in the future to account for different kinds of chat transcripts (e.g. containing time stamps and whatnot).

I also added a "compact view" toggle that makes the whole chat transcript a bit more … compact.

Feedback welcome.

Screenshots:

screen shot 2017-07-01 at 15 43 27

screen shot 2017-07-01 at 15 43 17

screen shot 2017-07-01 at 15 44 55

Fixes #954.

@swissspidy swissspidy added the [Feature] Blocks Overall functionality of blocks label Jul 1, 2017
@swissspidy
Copy link
Member Author

OK, so the last build failed because of a bus error. A restart would help.

Also, I just noticed that I can't properly edit an existing chat block now, because the textarea will show all the markup. I assume I need to change this to an <Editable>?

import { uniq } from 'lodash';

export default function ChatTranscript( props ) {
const { value, compact } = props;
Copy link
Contributor

Choose a reason for hiding this comment

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

You can deconstruct directly inside the function declaration.

message = msg.join( ':' ).trim();

lastAuthor = getAuthor( author );
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think we could split the logic of this into two parts?

// Normalize data
const transcript = normalizeTranscript( value ); // returns { authors: [], messages: [ { message, authorIndex } ] }

// Render
return messages.map( ... )

This would make unit-testing the normalizing logic easier.

/**
* External dependencies
*/
import TextareaAutosize from 'react-autosize-textarea';
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, should we move the external dependencies above?

</Placeholder>
),
! focus && (
<ChatTranscript value={ content } compact={ compact } />
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably use the className of the block here (for the root element)

@@ -0,0 +1,20 @@
.editor-visual-editor__block[data-type="core/chat"] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we rely on the base classname instead? wp-block-chat

Copy link
Member Author

Choose a reason for hiding this comment

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

From what I've seen, other blocks use .editor-visual-editor__block… in style.scss and wp-block-… in block.scss, so I chose to follow that pattern.

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 we should always use wp-block- unless we need to change something in the parent wrapper (which is unlikely to happen, it's needed for float alignments essentially)

min-height: 10em;
text-align: left;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we create a block.scss for frontend styling too, and extract the common styles applied for the editor and for frontend into the block.scss file?

Copy link
Member Author

Choose a reason for hiding this comment

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

There already is such a file or am I missing something?

Copy link
Contributor

Choose a reason for hiding this comment

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

Each block should create its own block.scss (which are extracted and loaded in frontend too). See #1590 (we did this for other blocks)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's why blocks/library/chat/block.scss exists. What else is needed?

Okay, that's enough. No internet for you anymore!
Alexa: 💔
Google Home: 😔
Siri: 📴
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 there's a problem here unless I'm missing something.

If I understand the code, this value will be parsed and reserialized differently (using HTML ...).
What happens if I try to re-edit the block again? The parser will fail?
Anyway, The source value and the serialized value should be the same (aside some spacing differences maybe) which makes me think we should store the raw value in the comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's a problem I still need to address, see #1632 (comment).

You can edit the block, but you will see all the HTML markup in the textarea.

I would love to store only the raw value, but then how can it be rendered on the front end?

Feedback last week was that it should be stored with (as little as possible) markup in the database and then we'll see from there.

Copy link
Contributor

@youknowriad youknowriad Jul 3, 2017

Choose a reason for hiding this comment

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

Ok Maybe instead of storing the value in its currenf format, we should extract a more "normalized" value, something like:

content: query( 'p', {
  authorId: attr( 'class' ),
  author: html( '.chat-author' ),
  message: hmlt( '.chat-message' ),
} )

which I think should return something like:

const content = [
  { authorId, author, message }
];

And when typing in the text area, parsing the textarea value to the format above before calling the setAttributes

value.split( '\n' ).map( ( line ) => {
line = line.trim();

const messageParts = line.split( ':' );
Copy link
Member

Choose a reason for hiding this comment

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

This should add a limit param, so like line.split( ':', 2 ). Otherwise it will choke on a line like:

John: I really like the ratio 1:1.

Copy link
Member

Choose a reason for hiding this comment

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

Then the message = messageParts.join( ':' ).trim() part below can be replaced with:

message = messageParts.shift().trim()

/**
* WordPress dependencies
*/
import { Placeholder } from 'components';
Copy link
Member

Choose a reason for hiding this comment

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

Note with #2172, these need to be updated to prefix the dependencies with @wordpress/. You will need to perform a rebase against the latest version of master and apply your changes:

git fetch origin
git rebase origin/master

@karmatosed
Copy link
Member

Can we either close this or update the PR please?

@karmatosed karmatosed closed this Nov 7, 2017
@karmatosed karmatosed reopened this Nov 7, 2017
@swissspidy
Copy link
Member Author

Since #954 was closed, I guess this PR can be closed as well. It's far from done anyway (compared to the pagination block PR, for example).

@gziolo
Copy link
Member

gziolo commented Jan 27, 2018

@swissspidy, let's close it as you said. Feel free to reopen as soon as you get back to this one. Thanks for spending time exploring this block 👍

@gziolo gziolo closed this Jan 27, 2018
@gziolo gziolo deleted the add/chat-block branch January 27, 2018 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants