Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1385 heading faq #1457

Merged
merged 6 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 56 additions & 7 deletions client/components/main/Faqs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import Button from '@material-ui/core/Button';
import useContentful from '../../hooks/useContentful';

const useStyles = makeStyles(theme => ({
flexContainer: {
display: 'flex',
justifyContent: 'space-between',
},
textHeading: {
fontWeight: theme.typography.fontWeightBold,
},
Expand All @@ -22,6 +26,8 @@ const useStyles = makeStyles(theme => ({
},
contentQuestion: {
fontWeight: theme.typography.fontWeightMedium,
minWidth: '920px',
cursor: 'pointer',
},
searchBar: {
display: 'flex',
Expand All @@ -44,6 +50,9 @@ const useStyles = makeStyles(theme => ({
fontSize: '18px',
fontWeight: theme.typography.fontWeightBold,
},
expand: {
cursor: 'pointer',
},
}));

const query = `
Expand All @@ -67,6 +76,28 @@ const Faqs = () => {
}, [errors]);

const [searchFormState, setSearchFormState] = React.useState('');
const [expanded, setExpanded] = React.useState({});
const [allExpanded, setAllExpanded] = React.useState(false);

const handleExpand = id => {
setExpanded(prevState => ({
...prevState,
[id]: !prevState[id],
}));
};

const handleExpandAll = () => {
setAllExpanded(prevAllExpanded => !prevAllExpanded);
setExpanded(
data.faqCollection.items.reduce(
(prevExpanded, item) => ({
...prevExpanded,
[item.sys.id]: !allExpanded,
}),
{},
),
);
};

const handleSubmit = e => {
e.preventDefault();
Expand Down Expand Up @@ -117,7 +148,7 @@ const Faqs = () => {
</form>
</TextHeadingFAQ>
<ContentBody maxWidth="md">
{ data
{data
&& (
<Grid container>
<Grid item>
Expand All @@ -126,16 +157,34 @@ const Faqs = () => {
Frequently Asked Questions
</Typography>
</div>

<div
className={classes.marginBottomLarge}
onClick={handleExpandAll}
onKeyDown={event => {
if (event.key === 'Enter' || event.key === ' ') {
handleExpandAll();
}
}}
role="button"
tabIndex={0}
>
<Typography variant="h6" className={`${classes.contentTitle} ${classes.expand}`}>
{allExpanded ? 'Collapse All' : 'Expand All'}
</Typography>
</div>
<div className={classes.marginTop5}>
{ data.faqCollection.items.map(item => (
{data.faqCollection.items.map(item => (
<Box key={item.sys.id} style={{ marginBottom: '3em' }}>
<Typography variant="h6" className={classes.contentQuestion}>
<Typography variant="h6" className={`${classes.contentQuestion} ${classes.flexContainer}`} onClick={() => handleExpand(item.sys.id)}>
{item.question}
{expanded[item.sys.id] && (<i className="fa-solid fa-angle-up" />)}
{!expanded[item.sys.id] && (<i className="fa-solid fa-angle-down" />)}
</Typography>
<ReactMarkdown>
{item.answer}
</ReactMarkdown>
{expanded[item.sys.id] && (
<ReactMarkdown>
{item.answer}
</ReactMarkdown>
)}
</Box>
))}
</div>
Expand Down
50 changes: 29 additions & 21 deletions client/public/index.html
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="canonical" href="https://www.311-data.org/">

<!-- Google Analytics -->
<!-- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-166263401-1"></script>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="canonical" href="https://www.311-data.org/">

<!-- Google Analytics -->
<!-- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-166263401-1"></script>
<script>
const devHostname = window.location.hostname === 'localhost' || window.location.hostname === '0.0.0.0';
window['ga-disable-UA-166263401-1'] = devHostname;
window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-166263401-1');
</script>
<script src="https://www.googleoptimize.com/optimize.js?id=OPT-WHKV393"></script> -->

<!-- Hotjar -->
<!-- <script> (function(h,o,t,j,a,r){ h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)}; h._hjSettings={hjid:1881395,hjsv:6}; a=o.getElementsByTagName('head')[0]; r=o.createElement('script');r.async=1; r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv; a.appendChild(r); })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv='); </script> -->
<!-- Hotjar -->
<!-- <script> (function(h,o,t,j,a,r){ h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)}; h._hjSettings={hjid:1881395,hjsv:6}; a=o.getElementsByTagName('head')[0]; r=o.createElement('script');r.async=1; r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv; a.appendChild(r); })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv='); </script> -->

<!-- Icon -->
<script src="https://kit.fontawesome.com/da508b7350.js" crossorigin="anonymous"></script>
<!-- Stylesheets -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css"
integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@600&display=swap" rel="stylesheet">
<link href='https://api.mapbox.com/mapbox-gl-js/v2.1.1/mapbox-gl.css' rel='stylesheet' />

<!-- Webpack injected tags -->
<title>
<%= htmlWebpackPlugin.options.title %>
</title>

<!-- Stylesheets -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Oswald:wght@600&display=swap" rel="stylesheet">
<link href='https://api.mapbox.com/mapbox-gl-js/v2.1.1/mapbox-gl.css' rel='stylesheet' />
</head>

<!-- Webpack injected tags -->
<title><%= htmlWebpackPlugin.options.title %></title>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>

</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>