club-soda / club-soda-guide

Mindful Drinking Movement - Club Soda MVP 2.0
https://club-soda-guide-staging.herokuapp.com
17 stars 0 forks source link

Line breaks in description boxes #628

Closed jessyclubsoda closed 5 years ago

jessyclubsoda commented 5 years ago

We are having some problems inserting line breaks into text boxes.

It says in the guide that we should be able to use break tags to do so for venue descriptions (and I assumed other text boxes across the site).

However, these don't seem to be working on the staging or live site.

Normally this isn't a problem because venue description boxes accept the enter key but brand description boxes do not, and they won't accept break tags either.

Some images below: Kolibri with enter in text box Here I just tried to use the enter key in the text box in the way that we can with venue descriptions But no breaks came up Kolibri with no breaks

Here I tried to use break tags

Kolibri with break tags

But no breaks came up Kolibri with no breaks after tagging

I'm not sure if this is either because 1. I'm using break tags wrong or 2. The text boxes aren't accepting them Ideally it would be best if the brand description boxes just accepted the enter key in the way they do for venues but otherwise it'd be great if they could have some paragraphing possible

Either way it doesn't currently seem to be working as the guide suggests it would

SimonLab commented 5 years ago

A few paths in mind to investigate:

SimonLab commented 5 years ago

Now looking at how venues do this conversion (maybe with text_to_html function ?) and how to apply the same logic to brands and drinks:

The add_line_breaks function is used to convert new line to <br> tag in the venue: https://github.com/club-soda/club-soda-guide/blob/4eafe921cc0dbbebfee559270b03d60852493e62/lib/cs_guide_web/templates/venue/info.html.eex#L25

and the function is implemented here: https://github.com/club-soda/club-soda-guide/blob/4eafe921cc0dbbebfee559270b03d60852493e62/lib/cs_guide_web/views/venue_view.ex#L58-L60

For the brand description we can use directly the text_to_html function:

<p class="pv3 lh5"><%= raw text_to_html(@brand.description) %></p

However for the drinks, the description is displayed with Elm, so we need to find a way to display new lines with Elm. Instead of rewriting all the Elm code for the description we could use another solution with css: image https://developer.mozilla.org/en-US/docs/Web/CSS/white-space

Applying this style to the description will display the new line correctly with Elm

jessyclubsoda commented 5 years ago

Thanks for taking a look at this @SimonLab

Looking on staging it seems that we can still only do one line break e.g. we can't create paragraphs Amaizedrinks with enter Here even though I've used the enter button twice it only gives me one break Amaizedrinks no dice with enter

Similarly < br > tags seem to have no effect

SimonLab commented 5 years ago

Thanks for spotting that @jessyclubsoda . This is due to the text_to_html function(https://hexdocs.pm/phoenix_html/Phoenix.HTML.Format.html#text_to_html/2) image

So new paragraphs (

tags) are created if there are 2 or more consecutive lines. This means that empty paragraph are removed. If you add a space in front of the new line then a new paragraph will be created to only display the space.

I think that's why the add_line_breaks helper function is used for the venues' description and not the text_to_html function: https://github.com/club-soda/club-soda-guide/blob/75a3446dd2814bf15a7210a2533a0146311f99aa/lib/cs_guide_web/views/venue_view.ex#L58-L60 I'll do a bit more test but I think the solution is to reuse the add_line_breaks function