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 story pinned option #975

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

griseduardo
Copy link

@griseduardo griseduardo commented Oct 12, 2023

Motivation

Allow pin story and show first

Changes

  • Add story_pinned column in stories table
  • Allow editor and admin user to pin or unpin stories in stories dashboard and edit story dashboard
  • When a story is pinned, any other previous pinned is unpinned
  • Member user can only see the pin in pinned story but not update it
  • In home and dashboard show the pinned story first (if filters satisfy the condition to this story appear)

Screenshots

Stories dashboard (admin/editor):
admin-editor-stories

Stories dashboard (member):
user-stories

Story dashboard (admin/editor):
edit-story

Home page:
home-page

@rudokemper
Copy link
Member

This is great to see! Thanks so much.

A couple of things:

  1. The addition of these css assets are introducing a lot of unwanted styling artifacts on both the Rails dashboard and React sides.
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">

You can see this in the blue underlines in your GIFs above, as well as the the New button at the top right which is supposed to be orange background, and a bunch of other little things. And on React, the light blue link color at the bottom.

Can we find a better way to access the icons without importing a bunch of CSS we either don't need or is impacting the app style?

  1. For a story that's been "Pinned" can we add a permanently visible pin icon at the top right?

@griseduardo
Copy link
Author

griseduardo commented Oct 13, 2023

This is great to see! Thanks so much.

A couple of things:

1. The addition of these css assets are introducing a lot of unwanted styling artifacts on both the Rails dashboard and React sides.
    <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">

You can see this in the blue underlines in your GIFs above, as well as the the New button at the top right which is supposed to be orange background, and a bunch of other little things. And on React, the light blue link color at the bottom.

Can we find a better way to access the icons without importing a bunch of CSS we either don't need or is impacting the app style?

2. For a story that's been "Pinned" can we add a permanently visible pin icon at the top right?

Hello, the problem is that the exact "icon-pushpin" is only presented in version 3 of font-awesome: https://fontawesome.com/v3/icons/
It is a version that is no longer supported and it is only possible to use with bootstrap (like I tried before) or downloading a folder with font-awesome configs, that brings all icons from there (not separated by icon).
The icons presented in version 5/6 of font-awesome, they permit download the svg of free ones and they give support for them.
I removed the bootstrap inclusion on dashboard and react head, downloaded the similar icon of pushpin on version 6 and used it.
I updated the gifs in description to show how the icon appears.
What do you think about use this svg?
I updated to always show pin icon when the story is pinned

@julinvictus
Copy link
Contributor

@griseduardo You think you can rebase your branch so we dont have the conflicts?

Copy link
Contributor

@lauramosher lauramosher left a comment

Choose a reason for hiding this comment

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

Overall, this a great start! I do have a few concerns that I've outlined below.

I would also love to see tests added surrounding the actions for pinning and unpinning. While unlikely, it isn't impossible for pinned stories to get out of sync and result in a community having multiple stories pinned. With the way the code is right now, if that were to happen, we would only ever unpin the first found pinned story rather than all of them.

Thank you for your contribution and I apologize for the rather tardy review.

Comment on lines 48 to 57
if params[:story_pinned].present?
if params[:story_pinned]
@pinned_story = @stories.find_by(story_pinned: true)
@pinned_story&.update(story_pinned: !params[:story_pinned])
end

@story.update(story_pinned: params[:story_pinned])

return redirect_to action: "index"
end
Copy link
Contributor

Choose a reason for hiding this comment

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

For ease of maintaining and reducing complexity of this, I think we should split out this block to allow pinning/unpinning from non-form views as its own custom rails action. I might also suggest we create two, one for pinning and one for unpinning and trigger them using remote: true calls so we don't refresh the page on them. Another benefit of this will ensure the logic stays relatively simple:

def pin
  story = authorize community_stories.find(params[:id])
  community_stories.update_all(story_pinned: false)
  story.update(story_pinned: true)
end

def unpin
  story = authorize community_stories.find(params[:id])
  story.update(story_pinned: false)
end

Copy link
Author

Choose a reason for hiding this comment

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

Good idea separate in different actions.
Only one problem, related to use remote true, is that it doesn't change the icon color and reordenize the stories, that can pass the wrong idea that the pin or unpin action didn't worked.
I maintained the render behavior. What do you think about it?

rails/app/controllers/dashboard/stories_controller.rb Outdated Show resolved Hide resolved
rails/app/pages/stories_page.rb Outdated Show resolved Hide resolved
rails/app/pages/stories_page.rb Outdated Show resolved Hide resolved
rails/app/assets/stylesheets/cms/_cards.scss Outdated Show resolved Hide resolved
rails/app/assets/stylesheets/cms/_cards.scss Outdated Show resolved Hide resolved
rails/app/assets/stylesheets/cms/_icons.scss Show resolved Hide resolved
rails/app/assets/stylesheets/cms/layout.scss Outdated Show resolved Hide resolved
Comment on lines 17 to 36
<% if story.story_pinned %>
<div class="edit-icon-pinned">
<%= form_with model: @story, url: story_path(story.id), method: "patch", multipart: true, class: "form", data: {remote: false}, locale: true do |f| %>
<%= f.hidden_field :story_pinned, value: false %>
<%= f.button nil, class: "icon-pinned" do %>
<%= image_tag 'thumbtack-pinned.svg', alt: 'pinned-story', class: "image-pinned" %>
<% end %>
<% end %>
</div>
<% else %>
<div class="edit-icon-not-pinned">
<%= form_with model: @story, url: story_path(story.id), method: "patch", multipart: true, class: "form", data: {remote: false}, locale: true do |f| %>
<%= f.hidden_field :story_pinned, value: true %>
<%= f.button nil, class: "icon-not-pinned" do %>
<%= image_tag 'thumbtack-not-pinned.svg', alt: 'pinned-story', class: "image-pinned" %>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
Copy link
Contributor

Choose a reason for hiding this comment

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

One of the benefits of using an SVG over a standard image is the ability to store them as code rather than image assets. In our views, we have a shared/_icons.html.erb partial that defines shareable SVGs for use in this manner:

<svg hidden xmlns="http://www.w3.org/2000/svg">
<symbol id="icon-thumbtack" attributes="from svg">
  <path data />
</symbol>
</svg>

and then referenced like:

<svg><use href="#icon-name"></svg>

These can then be styled with classes as usual, with allowance for using "fill" and "stroke" to color the paths and strokes in.

With a few extra changes, these can also be loaded into the react code and referenced the same way.

Copy link
Author

Choose a reason for hiding this comment

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

Nice idea, I updated to use the svg this way in rails. Anyway I tried and doesn't find for now a way to use the same in React. I used the svg directly there. Do you have a suggestion for how to make it work?

rails/app/assets/images/thumbtack-not-pinned.svg Outdated Show resolved Hide resolved
Copy link
Contributor

@lauramosher lauramosher left a comment

Choose a reason for hiding this comment

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

Thanks for working through all of the feedback! This is looking great. A couple of additional comments in line.

I would also love to see some specs around the pinning and unpinning actions — both the individual pin/unpin endpoints as well as in the create and edit form. Are you able to add those for us?

rails/app/assets/stylesheets/cms/_cards.scss Outdated Show resolved Hide resolved
rails/app/assets/stylesheets/cms/_cards.scss Outdated Show resolved Hide resolved
rails/app/views/dashboard/stories/_stories.html.erb Outdated Show resolved Hide resolved
@griseduardo
Copy link
Author

griseduardo commented Dec 12, 2023

Thanks for working through all of the feedback! This is looking great. A couple of additional comments in line.

I would also love to see some specs around the pinning and unpinning actions — both the individual pin/unpin endpoints as well as in the create and edit form. Are you able to add those for us?

I will add the tests :)

@griseduardo
Copy link
Author

Hello @rudokemper and @lauramosher
I believe that now is ready to re-review, I worked in all suggestions.
The resolved ones I resolve here in pr, some I commented the implementation I followed and the reason :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants