Add no result found message issue#53#56
Add no result found message issue#53#56Treora merged 1 commit intoWebMemex:masterfrom Chaitya62:noResult-patch-1
Conversation
|
|
||
| //if no result found display relavant message | ||
| if(searchResult.rows.length === 0){ | ||
| return <p className={styles.message}> |
There was a problem hiding this comment.
unless it is a project decision what do you think of the style (I've seen it most often because it keeps opening close lines)
return (
<p className={styles.message}>
No result found
</p>
)
There was a problem hiding this comment.
Sorry didn't get you? is it about the way I wrote the code or the css styling
There was a problem hiding this comment.
only about indentation, and only if you think my way is better, and only if my way doesn't violate the rest of the project. To show another big project on this style https://github.com/acdlite/redux-router/blob/master/examples/basic/index.js#L49 (line 49)
I normally don't put weight on style but I started like that with the return and it made my life much harder when the project grew
There was a problem hiding this comment.
@obsidianart okay got it! but the ul just below that had
return <ul className={styles.root }>
.
.
</ul>So I also did the same thing but yes we can surely choose one of the way to write it and include it somewhere in the project description Readme.md or coding guidlines page in the future.
There was a problem hiding this comment.
I ll wait for @Treora 's input in this will change it if necessary ! though I completely agree with you @obsidianart and yes I am also picky about coding styles at times it's doesn't matter at the early stage but helps a lot later on.
There was a problem hiding this comment.
This is one of those stylistic choices where I sway back and forth myself. I'd say keep it either way you like now, and we will restyle the whole codebase at some moment if we think it's better. Perhaps combined with a switch to indenting with only two spaces, I just use four because of old Python habits, but it may be less appreciated in the general javascript etiquette.
There was a problem hiding this comment.
I'm very free about style. I don't care about semicolon, spaces, and many other things. This is one of the few things I had a real issue with but the final choice for me is your.
| if(searchResult.rows.length === 0){ | ||
| return ( | ||
| <p className={styles.message}> | ||
| no result found |
There was a problem hiding this comment.
Talking about style, please do indent this line too. Also "no results found" sounds slightly wrong, I would either say "No results", or "No pages found" or something like that.
I now realise it would be good to make a special case for when the database is empty. "No results" is not a nice welcome message on a fresh install. Perhaps move the current code to the Overview instead of the ResultList, then test for both the length of searchResult and the existence of a query, and if both are empty show something nice, e.g. "This is your digital memory, watch it grow as you browse the web!"
There was a problem hiding this comment.
Cool I ll make the necessary changes
|
In the 4th commit I added a new method in Overview class though I am not proud of what I named it are there anyother suggestions? I could not come up with a better option. |
src/overview/components/Overview.jsx
Outdated
| > | ||
| </input> | ||
| <ResultList searchResult={this.props.searchResult} /> | ||
| {this.createResultList()} |
There was a problem hiding this comment.
this should probably be a component not a function.
I had the same approach at the beginning but the idea of JSX is towards composition.
I don't know if the current code structure allows 2 elements in the same page.
otherwise, the quickest
{isFirstVisit && <p className={styles.message}>This is your digital memory, watch it grow as you browse the web! </p>}
{!isFirstVisit && <ResultList searchResult={this.props.searchResult} />}
Again, that's my opinion, and React has many opinions, so the choice is yours
|
I didn't want to make a new component just for a special case maybe If not function the second approach you pointed out is a feasible solution |
|
|{isFirstVisit && <p className={styles.message}>This is your digital
memory, watch it grow as you browse the web! </p>} {!isFirstVisit &&
<ResultList searchResult={this.props.searchResult} />} |
Two tests? Probably it is not the cleanest solution either, but this
became my usual style in this project:
```
{
isFirstVisit
? <p>...</p>
: <ResultList .../>
}
```
But if the lines get too long, perhaps define the message as a string
constant up in the file.
Interesting how many styles there are indeed.. and how it seems one of
those things where humans are more fussy about than computers. :)
|
|
Made the changes ! |
|
Just curious where the original message went now, the one telling there are no results.. ;) |
Treora
left a comment
There was a problem hiding this comment.
Looks good; just some small style stuff:
- keep and add newlines at end of files
- give more meaningful names to the constants
- some indentation
src/overview/components/Overview.jsx
Outdated
| this.props.searchResult.rows.length === 0); | ||
|
|
||
| //message for first visit | ||
| const message = 'This is your digital memory, watch it grow as you browse the web!'; |
There was a problem hiding this comment.
Too generic name. firstVisitMessage perhaps?
src/overview/components/Overview.jsx
Outdated
|
|
||
| : <ResultList searchResult={this.props.searchResult} /> | ||
| } | ||
|
|
There was a problem hiding this comment.
I don't know an actually nice style for these things, but for consistency you could keep the indentation that the rest of the code used:
isFirstVisit
? <p>..</p>
: <ResultList ...>
And if the <p> component should take multiple lines:
isFirstVisit
? (
<p ...>
{...}
</p>
)
: <ResultList ...>
| color: inherit; | ||
| text-decoration: none; | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
You can leave that newline in its place, I think it was living quite happily there.
| const ResultList = ({searchResult}) => { | ||
|
|
||
| //if no results are found | ||
| const message = 'no result found'; |
|
Ok, looks ready to merge? I'll nitpick on some last whitespace myself. One question still: are you okay with waiving all your copyright on this code, so that the whole code base can be published in public domain? (see unlicense.org) |
|
Yes no problem at all. |
|
Hmm I just tried it out, and it shows the firstVisitMessage also when there are results but they are just loading still. Did you not notice? This would need a smarter way to test if there are really no items in the database. May be easier to finish this when the result loading indicator (#54) is done. |
|
Hmm I think I ll figure out some other way to eliminate that ! |
|
Okay made some changes added a isFetching flag have added comments to why I set it to false and true everywhere. Initially it is true as we fetch the db whlle we load overview for the first time.I have added a loading placeholder which can be replaced by a loader later on. |
src/overview/actions.js
Outdated
| filterVisitsByQuery({query}).then(searchResult => { | ||
|
|
||
| //set fetching results to true | ||
| ourState(getState()).isFetching = true; |
There was a problem hiding this comment.
this seems like direct state manipulation. is it the case?
|
Yes is it a bad practice? |
src/overview/reducer.js
Outdated
| const defaultState = { | ||
| searchResult: {rows: []}, | ||
| query: '', | ||
| isFetching: true, |
src/overview/reducer.js
Outdated
| } | ||
|
|
||
| function setQuery(state, {query}) { | ||
| state.isFetching = true; //will start fetching |
There was a problem hiding this comment.
I think the comment is incorrect, this doesn't trigger anything per se
There was a problem hiding this comment.
Actaully I think instead of will start fetching. I should elaborate a little while intializing default
src/overview/reducer.js
Outdated
| } | ||
|
|
||
| function setSearchResult(state, {searchResult}) { | ||
| state.isFetching = false; //will stop fetching |
There was a problem hiding this comment.
I think the comment is incorrect, this doesn't trigger anything per se
There was a problem hiding this comment.
What i mean was when we call setSearchResult means the database has returned a value now if the query is changed and we again make it true
There was a problem hiding this comment.
I understand, I think the problem is around the comment. this is the state of the fetching, not something which trigger a behaviour.
|
A the default is true because we are fetching from the database as soon as we start our app |
|
When you start fetching the flag is changed, the initial state is false regardless. The initial state is about what it is, and the fetching is trigger later on in the code. if it's not clear we can talk about it |
|
Yes intuitively it should be false initially but then the message that only firstVisitors should see appears I guess isLoading is a better name then isFetching but as we discussed I should wait for the loader issue to be resolved |
|
wouldn't it be changed to true immediately (stating the search starts straight away)? |
|
Yes but the component when default was false loads and goes away it look buggy where as when it's true initially the component loads with loading message |
|
ok good :) |
|
How about I add export isDatabaseEmpty = ()=>{
let isEmpty = false;
db.info().then((result)=>{
if(result.doc_count === 0){
isEmpty = true;
}
});
return isEmpty;
}in pouchdb.js ,to check database is empty or not? |
|
@Chaitya62: checking the database requires calling an asynchronous function, so it cannot be done while rendering and requires adding extra state. Seems too complicated to me. (your code always returns false by the way, promises don't work this way) For simplicity, should we perhaps forget about the first-time message again (sorry, I know it was my own suggestion), and just check in the ResultList if there is a query but no results? Then we can think about the first-use message later again, maybe also as part of a more elaborate introduction. |
|
@Treora just edited my previous message I realised that code won't work ! I ll just add the no result message and update the PR ! |
|
@Treora I think now the PR is ready ! please review it! |
|
Nice and simple, thanks! I made the message a bit more subtle in appearance, as it need not draw much attention. I like the fade-in, good idea! |
I added a simple if statement and a message style in ./ResultList.jsx and ./ResultList.css