|
1 | | -import React, { useState, useEffect } from 'react'; |
2 | | -import axios from "axios"; |
| 1 | +import React from 'react'; |
3 | 2 | import sanitizeHtml from 'sanitize-html'; |
4 | 3 | import Accordion from '@material-ui/core/Accordion'; |
5 | 4 | import AccordionSummary from '@material-ui/core/AccordionSummary'; |
@@ -55,50 +54,27 @@ const SanitizedAnswer = ({ answer }) => { |
55 | 54 | }; |
56 | 55 |
|
57 | 56 | const AccordionSection = (props) => { |
58 | | - const [currentFaq, setCurrentFaq] = useState([]); |
59 | | - const [sendRequest, setSendRequest] = useState(false); |
60 | 57 | const classes = useStyles(); |
61 | 58 |
|
62 | | - useEffect(() => { |
63 | | - const incrementViewCount = async function () { |
64 | | - const requestBody = { |
65 | | - question: currentFaq.question, |
66 | | - answer: currentFaq.answer, |
67 | | - view_count: currentFaq.view_count, |
68 | | - }; |
69 | | - await axios.post(`${process.env.REACT_APP_API_URL}/api/faqs/${currentFaq.id}/increment_count/`, requestBody); |
70 | | - }; |
71 | | - if (sendRequest) { |
72 | | - // send the request |
73 | | - incrementViewCount() |
74 | | - setSendRequest(false); |
75 | | - } |
76 | | - }, [sendRequest, currentFaq]); |
77 | | - |
78 | 59 | return ( |
79 | 60 | <Grid item xs={12} sm={9} lg={11}> |
80 | 61 | {props.faqs.map((faq) => ( |
81 | 62 | <Box key={faq.id}> |
82 | 63 | <Accordion |
83 | 64 | className={classes.accordion} |
84 | 65 | expanded={props.expandedFaqs.indexOf(faq.id.toString()) > -1} |
85 | | - onClick={() => props.onFaqClick(faq.id)} |
| 66 | + onClick={() => props.onFaqClick(faq)} |
86 | 67 | > |
87 | 68 | <AccordionSummary |
88 | 69 | className={classes.summary} |
89 | 70 | data-cy='faq-question' |
90 | | - disabled={sendRequest} |
91 | 71 | expandIcon={<ExpandMoreRoundedIcon />} |
92 | | - onClick={() => { |
93 | | - setSendRequest(true); |
94 | | - setCurrentFaq(faq); |
95 | | - }} |
96 | 72 | > |
97 | 73 | <Typography variant='h6'>{faq.question}</Typography> |
98 | 74 | </AccordionSummary> |
99 | 75 | <Divider /> |
100 | 76 | <AccordionDetails data-cy='faq-answer' className={classes.detail}> |
101 | | - <Typography> |
| 77 | + <Typography onClick={(e) => e.stopPropagation()}> |
102 | 78 | <SanitizedAnswer answer={faq.answer} /> |
103 | 79 | </Typography> |
104 | 80 | </AccordionDetails> |
|
0 commit comments