create account

[HapRamp Web App] Adding User Search Feature by singhpratyush

View this thread on: hive.blogpeakd.comecency.com
· @singhpratyush · (edited)
$48.07
[HapRamp Web App] Adding User Search Feature
#### Repository

https://github.com/hapramp/alpha-web

----

# 1. Introduction

<center>
https://steemitimages.com/0x0/https://cdn.steemitimages.com/DQmbMbThuxMcJuETQZAokJRNrd6R85Nc2iwLy6UkhTuMvm3/hapramp%20logo.png
</center>
[Hapramp](https://hapramp.com/) is a Steem powered social media that rewards you for sharing value with the community.

In a recent [blog post](https://steemit.com/utopian-io/@singhpratyush/open-sourcing-hapramp-alpha-web-app-and-adding-travis-ci), I introduced the alpha web application for the platform.

In this blog post, I will be sharing how I added user search feature to the web app.

---

# 2. The Feature - User Search

<center>
![Screenshot from 2018-07-14 04-00-56.png](https://ipfs.busy.org/ipfs/QmZg5Ys6U2dFP1zixH5WBpJ5eTv1AabYzYrGwdaSdNwTvo)
</center>

The user search feature would enable users on HapRamp to look for other users using their username.

---

# 3. Implementation Details

## 3.1. Data Flow

The search is triggered using Steem JS SDK with value in the search bar as a parameter. When the action completes, a `redux` state is updated and the component which displays result is updated with new user search results.

## 3.2. The Search Bar

The [`SearchBar` component](https://github.com/hapramp/alpha-web/blob/7dc1d90f9038f922b557d6fc095372b570904ae2/src/search/SearchBar/SearchBar.component.js) takes `onSearch` as an optional prop and calls it with the search text when clicking on the search button or pressing `Enter` key. It gets focussed automatically when the user navigates to the search page and uses `state` to store search query.

## 3.3. Search Results

The [`SearchResults` component]() takes an array of usernames as input and renders the list of users with their profile picture and username. On clicking the user card, one can navigate to the user's blog.

![Screenshot from 2018-07-14 11-02-35.png](https://ipfs.busy.org/ipfs/QmQDK4o9ivx41pCYKdeuMZ36bHT7FeE1Ymfb1AkCHEhLpV)

## 3.4. Getting the search working

### 3.4.1. The action and reducer

[The action creator](https://github.com/hapramp/alpha-web/blob/26bc201c7bdeb8f76625cfdac47c08b777c362b0/src/search/search.actions.js) uses steem JS SDK to search for users based on the input text and dispatches an action accordingly. This action is utilized by the [search reducer](https://github.com/hapramp/alpha-web/blob/7dc1d90f9038f922b557d6fc095372b570904ae2/src/search/search.reducer.js) to determine the next state.

### 3.4.2. Putting the `SearchBar` and `SearchResults` together

The `index.js` for search declares a component which binds the two components with Redux so they work smoothly. It also renders errors and ensures that two searches are not triggered concurrently.

---

**Pull Request** - https://github.com/hapramp/alpha-web/pull/33.
**Commit** - https://github.com/hapramp/alpha-web/pull/33/commits/26bc201c7bdeb8f76625cfdac47c08b777c362b0
**Github Account** - https://github.com/singhpratyush

---

<a href="https://discord.gg/PkgCv8j"> <center> https://pbs.twimg.com/media/DhaADYzXcAACLGd.jpg:large
### Learn more - Join the conversation on Discord </center> </a>
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorsinghpratyush
permlinkhapramp-web-app-adding-user-search-feature
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.2","format":"markdown","tags":["utopian-io","development","steem","hapramp","blockchain"],"users":["singhpratyush"],"links":["https://github.com/hapramp/alpha-web","https://hapramp.com/","https://steemit.com/utopian-io/@singhpratyush/open-sourcing-hapramp-alpha-web-app-and-adding-travis-ci","https://github.com/hapramp/alpha-web/blob/7dc1d90f9038f922b557d6fc095372b570904ae2/src/search/SearchBar/SearchBar.component.js","#","https://github.com/hapramp/alpha-web/blob/26bc201c7bdeb8f76625cfdac47c08b777c362b0/src/search/search.actions.js","https://github.com/hapramp/alpha-web/blob/7dc1d90f9038f922b557d6fc095372b570904ae2/src/search/search.reducer.js","https://github.com/hapramp/alpha-web/pull/33","https://github.com/hapramp/alpha-web/pull/33/commits/26bc201c7bdeb8f76625cfdac47c08b777c362b0","https://github.com/singhpratyush"],"image":["https://steemitimages.com/0x0/https://cdn.steemitimages.com/DQmbMbThuxMcJuETQZAokJRNrd6R85Nc2iwLy6UkhTuMvm3/hapramp%20logo.png","https://ipfs.busy.org/ipfs/QmZg5Ys6U2dFP1zixH5WBpJ5eTv1AabYzYrGwdaSdNwTvo","https://ipfs.busy.org/ipfs/QmQDK4o9ivx41pCYKdeuMZ36bHT7FeE1Ymfb1AkCHEhLpV","https://pbs.twimg.com/media/DhaADYzXcAACLGd.jpg:large"]}
created2018-07-14 05:50:45
last_update2018-07-14 05:53:03
depth0
children5
last_payout2018-07-21 05:50:45
cashout_time1969-12-31 23:59:59
total_payout_value36.252 HBD
curator_payout_value11.820 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,110
author_reputation7,035,648,262,478
root_title"[HapRamp Web App] Adding User Search Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id64,613,210
net_rshares21,054,709,189,858
author_curate_reward""
vote details (33)
@gregory.latinier · (edited)
$3.29
Hi! I remember your project from when you added SteemConnect. It's great to review your work again.

Let's go for the review:

- For React component you declare your propTypes and defaultProps outside the component like for stateless function. Any reason for this choice?

- Why the search is outside the folder structure? In the root directory I really wonder what's its purpose it first.

- `alpha-web/src/search/SearchBar/SearchBar.component.js` => This displacement of folder leads to weird naming. Why a component is outside the components folder?

- [Here](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0) is an article by Dan Abramov that explains the difference between components and containers 

- Except for the weird folder choice, you're doing a good use of redux :)

- `alpha-web/src/components/` => Why do you have cases difference in the same folder ? 

- Nice to see the service worker for the PWA stuffs.

- like most people you got a few `console.log` that are only here for debug purpose.

- For clarity I would have 1 property per line but that's my preference.
![](https://cdn.steemitimages.com/DQmZBMDBHY2rUbtXMQBSQFv7bxjVdVkf8vija99zbPwZz9t/image.png)

- You should improve your readme.md with install stuff, roadmap, etc.

I'll stop here :) You added one new feature but it doesn't follow your folder structure that's a litlle sad. Any reason why it was coded like that?

So now what's coming next??? Good luck and keep up the work ;)


Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/3/2332213).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , ,
properties (23)
authorgregory.latinier
permlinkre-singhpratyush-hapramp-web-app-adding-user-search-feature-20180715t224103331z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"image":["https://cdn.steemitimages.com/DQmZBMDBHY2rUbtXMQBSQFv7bxjVdVkf8vija99zbPwZz9t/image.png"],"links":["https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0","https://join.utopian.io/guidelines","https://review.utopian.io/result/3/2332213","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-07-15 22:41:03
last_update2018-07-15 22:43:45
depth1
children2
last_payout2018-07-22 22:41:03
cashout_time1969-12-31 23:59:59
total_payout_value2.471 HBD
curator_payout_value0.816 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,974
author_reputation34,278,323,818,021
root_title"[HapRamp Web App] Adding User Search Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id64,803,639
net_rshares1,537,643,402,027
author_curate_reward""
vote details (5)
@singhpratyush ·
Hey @gregory.latinier

Thanks for reviewing the submission :)

The different folder structure is because I will be moving on from the flat directory structure. So once I am done with the refactoring, everything should be consistent.

We are planning to release the Android app on Google Play in August. We are also planning a small local meetup this weekend. Hoping to get a good response for the same.

Cheers!
properties (22)
authorsinghpratyush
permlinkre-gregorylatinier-re-singhpratyush-hapramp-web-app-adding-user-search-feature-20180717t070803879z
categoryutopian-io
json_metadata{"community":"busy","app":"busy/2.5.2","format":"markdown","tags":["utopian-io"],"users":["gregory.latinier"],"links":["/@gregory.latinier"],"image":[]}
created2018-07-17 07:08:03
last_update2018-07-17 07:08:03
depth2
children0
last_payout2018-07-24 07:08:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length411
author_reputation7,035,648,262,478
root_title"[HapRamp Web App] Adding User Search Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id64,958,528
net_rshares0
@utopian-io ·
Hey @gregory.latinier
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

**Contributing on Utopian**
Learn how to contribute on <a href="https://join.utopian.io">our website</a>.

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for Utopian Witness!</a>
πŸ‘  
properties (23)
authorutopian-io
permlink20180716t100512523z
categoryutopian-io
json_metadata{"tags":["utopian.tip"],"app":"utopian-io"}
created2018-07-16 10:05:12
last_update2018-07-16 10:05:12
depth2
children0
last_payout2018-07-23 10:05:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length416
author_reputation152,955,367,999,756
root_title"[HapRamp Web App] Adding User Search Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id64,851,298
net_rshares5,254,553,552
author_curate_reward""
vote details (1)
@steemitboard ·
Congratulations @singhpratyush! You have completed the following achievement on Steemit and have been rewarded with new badge(s) :

[![](https://steemitimages.com/70x80/http://steemitboard.com/notifications/votes.png)](http://steemitboard.com/@singhpratyush) Award for the number of upvotes

<sub>_Click on the badge to view your Board of Honor._</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



> Do you like [SteemitBoard's project](https://steemit.com/@steemitboard)? Then **[Vote for its witness](https://v2.steemconnect.com/sign/account-witness-vote?witness=steemitboard&approve=1)** and **get one more award**!
properties (22)
authorsteemitboard
permlinksteemitboard-notify-singhpratyush-20180816t014357000z
categoryutopian-io
json_metadata{"image":["https://steemitboard.com/img/notify.png"]}
created2018-08-16 01:43:57
last_update2018-08-16 01:43:57
depth1
children0
last_payout2018-08-23 01:43:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length680
author_reputation38,975,615,169,260
root_title"[HapRamp Web App] Adding User Search Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id68,333,732
net_rshares0
@utopian-io ·
Hey @singhpratyush
**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
πŸ‘  
properties (23)
authorutopian-io
permlinkre-hapramp-web-app-adding-user-search-feature-20180718t053010z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-07-18 05:30:12
last_update2018-07-18 05:30:12
depth1
children0
last_payout2018-07-25 05:30:12
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length305
author_reputation152,955,367,999,756
root_title"[HapRamp Web App] Adding User Search Feature"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id65,075,286
net_rshares5,254,553,552
author_curate_reward""
vote details (1)