Skip to content

Commit

Permalink
[#26] SurveyList to only display a single Survey depending on position
Browse files Browse the repository at this point in the history
  • Loading branch information
liamstevens111 committed Mar 13, 2023
1 parent 6171a2e commit 3fcc5ff
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/components/Survey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ function Survey({ title, description, coverImageUrl }: SurveyProps) {
return (
<>
<img src={coverImageUrl} alt="cover" />
<p> {title}</p>
<p> {description}</p>
<p className="text-white"> {title}</p>
<p className="text-white"> {description}</p>
</>
);
}
Expand Down
20 changes: 11 additions & 9 deletions src/components/SurveyList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { useState } from 'react';

import Button from 'components/Button';
import SurveyComponent from 'components/Survey';
import { Survey } from 'types/Survey';

type SurveyListProps = { surveys: Survey[] };

function SurveyList({ surveys }: SurveyListProps) {
const [index, setIndex] = useState(0);

return (
<div>
{surveys.map((survey) => {
return (
<li key={survey.id}>
<SurveyComponent {...survey} />
</li>
);
})}
</div>
<>
<SurveyComponent {...surveys[index]} />

{/* TODO: For testing */}
<Button type="button" onButtonClick={() => setIndex(index + 1)} text="Next" />
</>
);
}

Expand Down
6 changes: 5 additions & 1 deletion src/screens/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ const HomeScreen = (): JSX.Element => {
Today - Monday, June 15
</div>

{surveys.length > 0 && <SurveyList surveys={surveys} />}
{surveys.length > 0 && (
<section>
<SurveyList surveys={surveys} />
</section>
)}
</>
);
};
Expand Down

0 comments on commit 3fcc5ff

Please sign in to comment.