-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored component to add answers expanding functionality
- Loading branch information
1 parent
ddef871
commit bdf89e1
Showing
18 changed files
with
107 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
**/node_modules | ||
tests/ | ||
dist/ | ||
*test* | ||
|
||
node_modules/ | ||
# Logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,36 @@ | ||
import React from "react"; | ||
import React, { useState } from "react"; | ||
import { removeHTMLTags } from "../../utils" | ||
const AnswerList = ({ answers, expanded }) => { | ||
//TODO: Add expanded var into store & allow answers to be expanded | ||
|
||
return Object.keys(answers).map((id, index) => { | ||
if (index < 2) { | ||
return ( | ||
<span key={answers[id].id}> | ||
{index === 0 ? ( | ||
<p id="first-answer">A: {removeHTMLTags(answers[id].body)}</p> | ||
) : ( | ||
<p id="more-answers">{removeHTMLTags(answers[id].body)}</p> | ||
)} | ||
<sub id="answerer"> | ||
by {answers[id].answerer_name},{" "} | ||
{new Date(answers[id].date).toLocaleDateString("en-US", { | ||
dateStyle: "long" | ||
})} | ||
| Helpful? Yes {answers[id].helpfulness} | ||
| Report | ||
const AnswerList = ({ question }) => { | ||
let [expanded, setExpanded] = useState(false); | ||
return <div id="question-container" key={question.question_id} | ||
onClick={() => setExpanded(!expanded)}> | ||
<h2>Q: {removeHTMLTags(question.question_body)}</h2> | ||
<div> | ||
{Object.keys(question.answers).map((id, index) => { | ||
if (index < 2 || expanded) { | ||
return ( | ||
<span key={question.answers[id].id}> | ||
{index === 0 ? ( | ||
<p id="first-answer">A: {removeHTMLTags(question.answers[id].body)}</p> | ||
) : ( | ||
<p id="more-answers">{removeHTMLTags(question.answers[id].body)}</p> | ||
)} | ||
<sub id="answerer"> | ||
by {question.answers[id].answerer_name},{" "} | ||
{new Date(question.answers[id].date).toLocaleDateString("en-US", { | ||
dateStyle: "long" | ||
})} | ||
| Helpful? Yes {question.answers[id].helpfulness} | ||
| Report | ||
</sub> | ||
</span> | ||
); | ||
} | ||
}); | ||
</span> | ||
); | ||
} | ||
})} | ||
</div> | ||
</div> | ||
|
||
|
||
}; | ||
|
||
export default AnswerList; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import Redux from 'redux'; | ||
// import Redux from 'redux'; | ||
|
||
export default (state = null, action) => { | ||
switch (action.type) { | ||
case 'CHANGE_PRODUCT': | ||
return action.info; | ||
default: | ||
return state; | ||
case 'CHANGE_PRODUCT': | ||
return action.info; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import Redux from 'redux'; | ||
import { ADD_QUESTION_LIST } from '../actions/index' | ||
// import Redux from 'redux'; | ||
import { ADD_QUESTION_LIST } from '../actions/index'; | ||
|
||
export default (state = {}, action) => { | ||
switch (action.type) { | ||
case ADD_QUESTION_LIST: | ||
return action.questions | ||
default: | ||
return state; | ||
} | ||
switch (action.type) { | ||
case ADD_QUESTION_LIST: | ||
return action.questions; | ||
default: | ||
return state; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export const removeHTMLTags = (str) => { | ||
return str.replace(/(<([^>]+)>)/ig, ''); | ||
} | ||
return str.replace(/(<([^>]+)>)/ig, ''); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters