Skip to content

Commit

Permalink
[#26] Fix swiper and pagination bullets layout. Add button for upcomi…
Browse files Browse the repository at this point in the history
…ng survey detail link
  • Loading branch information
liamstevens111 committed Mar 20, 2023
1 parent 9f2c039 commit dfa1263
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const App = (): JSX.Element => {

return (
<div>
<main className="m-0 flex h-screen flex-col items-center justify-center p-0">{appRoutes}</main>
<main className="m-0 flex h-screen w-full flex-col items-center justify-center p-0">{appRoutes}</main>
</div>
);
};
Expand Down
3 changes: 3 additions & 0 deletions src/assets/images/arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 16 additions & 3 deletions src/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ body {
}

.survey-swiper {
width: 820px;
height: 100%;

.swiper-pagination-bullet {
width: 0.5rem;

Expand All @@ -48,4 +45,20 @@ body {
.swiper-pagination-bullet-active {
opacity: 1;
}

&.swiper-pagination {
bottom: 2rem !important;
}
}

.arrow-button {
width: 56px;
height: 56px;

border-radius: 9999px;

background-color: #fff;
background-image: url('../images/arrow.svg');
background-repeat: no-repeat;
background-position: center;
}
14 changes: 11 additions & 3 deletions src/components/Survey/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ type SurveyProps = {
function Survey({ title, description, coverImageUrl }: SurveyProps) {
return (
<div>
<img className="h-80 w-full" src={coverImageUrl} alt="cover" />
<p className="text-white"> {title}</p>
<p className="text-white opacity-60"> {description}</p>
<img className="my-4 max-h-80 w-full rounded-xl" src={coverImageUrl} alt="cover" />
<div className="mt-8 flex items-center justify-between">
<div>
<p className="text-white"> {title}</p>
<p className="text-white opacity-60"> {description}</p>
</div>
<div>
{/* TODO: Convert to Link for Survey Detail page */}
<button className="arrow-button"></button>
</div>
</div>
</div>
);
}
Expand Down
38 changes: 21 additions & 17 deletions src/components/SurveyList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Pagination } from 'swiper';
import { Swiper, SwiperSlide } from 'swiper/react';

// Styles
// import 'swiper/swiper.min.css';
import 'swiper/swiper-bundle.min.css';

import SurveyComponent from 'components/Survey';
Expand All @@ -12,21 +10,27 @@ type SurveyListProps = { surveys: Survey[] };

function SurveyList({ surveys }: SurveyListProps) {
return (
<Swiper
className="survey-swiper"
modules={[Pagination]}
speed={800}
pagination={{ clickable: true, dynamicBullets: true }}
slidesPerView={1}
>
{surveys.map((survey) => {
return (
<SwiperSlide key={survey.id}>
<SurveyComponent {...survey} />
</SwiperSlide>
);
})}
</Swiper>
<>
<Swiper
className="survey-swiper"
modules={[Pagination]}
speed={800}
spaceBetween={100}
pagination={{ el: '.swiper-pagination', clickable: true, dynamicBullets: true }}
slidesPerView={1}
>
{surveys.map((survey) => {
return (
<>
<SwiperSlide key={survey.id}>
<SurveyComponent {...survey} />
</SwiperSlide>
</>
);
})}
</Swiper>
<div className="survey-swiper swiper-pagination"></div>
</>
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/screens/Home/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ describe('HomeScreen', () => {
test('renders learn react link', () => {
render(<HomeScreen />);

const mainHeadingElement = screen.getByTestId('app-main-heading');
const surveyLoadingElement = screen.getByTestId('loading-surveys');

expect(mainHeadingElement).toBeInTheDocument();
expect(mainHeadingElement).toHaveTextContent('Home Screen');
expect(surveyLoadingElement).toBeInTheDocument();
expect(surveyLoadingElement).toHaveTextContent('Loading Surveys');
});
});
6 changes: 3 additions & 3 deletions src/screens/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const HomeScreen = (): JSX.Element => {
}, []);

if (!loaded) {
return <h3>Loading Surveys</h3>;
return <h3 data-test-id="loading-surveys">Loading Surveys</h3>;
}

return (
Expand All @@ -46,9 +46,9 @@ const HomeScreen = (): JSX.Element => {
<p className="text-3xl font-extrabold">Today</p>
</div>

<section className="h-full">
<div className="w-screen max-w-3xl">
<SurveyList surveys={surveys} />
</section>
</div>
</section>
);
};
Expand Down

0 comments on commit dfa1263

Please sign in to comment.