Updating search results

This commit is contained in:
Sharyn 2018-07-17 15:06:53 +02:00
parent 33469cd86c
commit bd7a3d5b14
4 changed files with 33 additions and 6 deletions

View File

@ -0,0 +1,13 @@
@mixin hasRedUnderline() {
&::before {
content: '';
width: 100%;
height: calculateRem(1);
background-color: $red;
position: absolute;
bottom: 0;
left: 0;
z-index: -1;
}
}

View File

@ -24,6 +24,6 @@ $primary-font: 'Roboto Mono', monospace;
$secondary-font: 'bebas_neuebold', sans-serif; $secondary-font: 'bebas_neuebold', sans-serif;
// layout // layout
$container-width: 750; $container-width: 600;
$browse-left-width: 180; $browse-left-width: 180;
$container-padding: 24; $container-padding: 24;

View File

@ -27,7 +27,7 @@ const SearchResults = (props) => {
return text.replace(regex, `<span>${cleanTerm}</span>`); return text.replace(regex, `<span>${cleanTerm}</span>`);
}; };
const processText = (text, length = 1500) => highlightTerm(trimText(text, length)); const processText = (text, length = 500) => highlightTerm(trimText(text, length));
const findFirstQuestion = (interview) => { const findFirstQuestion = (interview) => {
let { answer } = interview.interview[interview.matchedIndex]; let { answer } = interview.interview[interview.matchedIndex];
@ -48,6 +48,10 @@ const SearchResults = (props) => {
}; };
}; };
const interviewNameContainsTerm = (name, searchTerm) => {
return name.toLowerCase().includes(searchTerm.toLowerCase());
};
return ( return (
<div className="search-results"> <div className="search-results">
<ul> <ul>
@ -58,12 +62,15 @@ const SearchResults = (props) => {
key={interview.id} key={interview.id}
onClick={props.toggleSingleInterview} onClick={props.toggleSingleInterview}
> >
<h3>{ interview.name }</h3> <h3 className={interviewNameContainsTerm(interview.name, props.term) ? 'matched-name' : ''}>
{ Parser(interview.name) }
</h3>
<h5>{interview.matchedIndex + 1})&nbsp; <h5>{interview.matchedIndex + 1})&nbsp;
{ findFirstQuestion(interview).question } { findFirstQuestion(interview).question }
</h5> </h5>
<p>{ Parser(findFirstQuestion(interview).answer) } <div>
</p> { Parser(findFirstQuestion(interview).answer) }
</div>
</li> </li>
)) ))
} }

View File

@ -7,9 +7,15 @@
cursor: pointer; cursor: pointer;
h3 { h3 {
font-size: calculateRem(18); font-size: calculateRem(24);
margin-bottom: calculateRem(8); margin-bottom: calculateRem(8);
color: #fff; color: #fff;
display: inline-block;
&.matched-name {
@include hasRedUnderline;
position: relative;
}
} }
h5 { h5 {
@ -20,6 +26,7 @@
p { p {
font-size: calculateRem(14); font-size: calculateRem(14);
display: inline;
span { span {
position: relative; position: relative;