View this post on Hive: Steemit Condenser Contributions: Follow button behaviour
There was a enhancement request made in regards to the Follow button from a user profile.
Feature request about follows: It appears to me that condenser defaults to "Follow" before it knows if you follow another user or not. Then, after updating the page, it decides if you're following or not, then updates the UI. I think it should not show the button unless it knows for sure if you're following or not. Then, if it knows you're following, clicking on "Unfollow," I think it should show a modal and ask if you really intend to unfollow (just like twitter).
The work done
It sounded simple enough for me to handle during my daily commute so I had a look at it and although it was indeed simple, it was not as simple as I expected. The complexity came from the fact that the code needed to work for client side but also server side rendering.
After testing various ideas of implementation, I realised that it was actually very simple:
- When a user load an author profile page, the server does not know about their login status and does not need to generate the HTML code for the button.
- In the browser, if the user is not logged in, the button appears and will say
Follow, this allows an anonymous user to still want to follow a great author but the dApp will invite him/her to login or create an account before being able to do so.
- However, if the user is logged in, the button appears and will say
Followdepending on whether the user is following the author or not.
- Line 90 - 93: if server side (
windowis undefined) then return
- Line 94 - 104 (existing code): if user is not logged in then display a
- Line 118 - 131: if the user is logged in, then don't display anything until we know if the user is following the author (via API ajax call). Display the correct button accordingly.
Steemit Condenser Pull Request
This feature is not out yet, a pull request has been created:
If approved and merged, it will be available in a future release by Steemit Inc.
Vote for my witness
On Steem, Witnesses are playing the important role of providing a performant and safe network for all of us. You have the power to choose 30 trusty witnesses to package transactions and sign the blocks that will go in the Steem blockchain. Vote for me via SteemConnect to help me do more useful projects for the communities.