Skip to content

Commit

Permalink
Add carousel to community page
Browse files Browse the repository at this point in the history
  • Loading branch information
iAdramelk committed Jan 21, 2020
1 parent 7ba0c16 commit 95f93b8
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 71 deletions.
11 changes: 11 additions & 0 deletions pages/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import { META_BASE_TITLE } from '../src/consts'

const HeadInjector = () => (
<Head>
<link
rel="stylesheet"
type="text/css"
charSet="UTF-8"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css"
/>
<link
rel="stylesheet"
type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css"
/>
<title>{META_BASE_TITLE}</title>
</Head>
)
Expand Down
36 changes: 36 additions & 0 deletions src/Community/Carousel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react'
import PropTypes from 'prop-types'
import Slider from 'react-slick'

import { OnlyDesktop, OnlyMobile } from '../../styles'

import { SliderWrapper } from './styles'

const imagesSliderProps = {
slidesToShow: 1,
slidesToScroll: 1,
initialSlide: 1,
adaptiveHeight: true,
infinite: true,
autoplay: true,
speed: 600,
dots: true,
arrows: false
}

export default function CommunityCarousel({ items }) {
return (
<>
<OnlyDesktop>{items}</OnlyDesktop>
<OnlyMobile>
<SliderWrapper>
<Slider {...imagesSliderProps}>{items}</Slider>
</SliderWrapper>
</OnlyMobile>
</>
)
}

CommunityCarousel.propTypes = {
items: PropTypes.array
}
5 changes: 5 additions & 0 deletions src/Community/Carousel/styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import styled from 'styled-components'

export const SliderWrapper = styled.div`
margin-bottom: 10px;
`
88 changes: 63 additions & 25 deletions src/Community/Learn/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import format from 'date-fns/format'

import CommunityBlock from '../Block'
import CommunityButton from '../Button'
import CommunityCarousel from '../Carousel'
import CommunitySection from '../Section'

import { pluralizeComments } from '../../utils/i18n'
Expand Down Expand Up @@ -67,7 +68,66 @@ CommunityBlogPost.propTypes = {
url: PropTypes.string
}

function CommunityUserContent({ url, title, author, date, color }) {
return (
<Line key={url}>
<Link color={color} href={url}>
{title}
</Link>
<Meta>
{author}{format(date, 'MMMM, d')}
</Meta>
</Line>
)
}

CommunityUserContent.propTypes = {
color: PropTypes.string,
author: PropTypes.string,
date: PropTypes.string,
title: PropTypes.string,
url: PropTypes.string
}

function CommunityDocumentation({ url, title, description, color }) {
return (
<Line key={url}>
<Link color={color} large href={url}>
{title}
</Link>
<Meta>{description}</Meta>
</Line>
)
}

CommunityDocumentation.propTypes = {
color: PropTypes.string,
description: PropTypes.string,
title: PropTypes.string,
url: PropTypes.string
}

export default function CommunityLearn({ posts, theme }) {
const postItems = posts.map(post => (
<CommunityBlogPost {...post} key={post.url} color={theme.color} />
))

const userContentItems = userContent.map(userContent => (
<CommunityUserContent
{...userContent}
key={userContent.url}
color={theme.color}
/>
))

const documentationItems = documentation.map(documentation => (
<CommunityDocumentation
{...documentation}
key={documentation.url}
color={theme.color}
/>
))

return (
<Wrapper>
<CommunitySection
Expand All @@ -90,14 +150,7 @@ export default function CommunityLearn({ posts, theme }) {
}
icon="/static/img/community/documentation.svg"
>
{documentation.map(({ url, title, description }) => (
<Line key={url}>
<Link color={theme.color} large href={url}>
{title}
</Link>
<Meta>{description}</Meta>
</Line>
))}
<CommunityCarousel items={documentationItems} />
</CommunityBlock>
</Item>
<Item>
Expand All @@ -113,13 +166,7 @@ export default function CommunityLearn({ posts, theme }) {
icon="/static/img/community/blog.svg"
>
{posts.length ? (
posts.map(post => (
<CommunityBlogPost
{...post}
key={post.url}
color={theme.color}
/>
))
<CommunityCarousel items={postItems} />
) : (
<Placeholder>Blog is unavailable right now</Placeholder>
)}
Expand All @@ -130,16 +177,7 @@ export default function CommunityLearn({ posts, theme }) {
title="User Content"
icon="/static/img/community/user_content.svg"
>
{userContent.map(({ url, title, author, date }) => (
<Line key={url}>
<Link color={theme.color} href={url}>
{title}
</Link>
<Meta>
{author}{format(date, 'MMMM, d')}
</Meta>
</Line>
))}
<CommunityCarousel items={userContentItems} />
</CommunityBlock>
</Item>
</Items>
Expand Down
106 changes: 60 additions & 46 deletions src/Community/Meet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import formatDistanceToNow from 'date-fns/formatDistanceToNow'

import CommunityBlock from '../Block'
import CommunityCarousel from '../Carousel'
import CommunityButton from '../Button'
import CommunitySection from '../Section'

Expand All @@ -25,7 +26,64 @@ import {
Wrapper
} from '../styles'

function CommunityTopic({ url, title, date, comments, color }) {
return (
<Line>
<Link color={color} href={url} target="_blank" rel="norefferer nofollow">
{title}
</Link>
<Meta>
<Comments href={url} target="_blank" rel="norefferer nofollow">
{pluralizeComments(comments)}
</Comments>
&nbsp; last activity {formatDistanceToNow(new Date(date), 'MMMM, d')}{' '}
ago
</Meta>
</Line>
)
}

CommunityTopic.propTypes = {
url: PropTypes.string,
title: PropTypes.string,
date: PropTypes.string,
comments: PropTypes.number,
color: PropTypes.string
}

function CommunityIssue({ url, title, date, comments, color }) {
return (
<Line>
<Link color={color} href={url} target="_black" rel="noreferrer nofollow">
{title}
</Link>
<Meta>
<Comments href={url} target="_black" rel="noreferrer nofollow">
{pluralizeComments(comments)}
</Comments>
&nbsp;opened {formatDistanceToNow(new Date(date), 'MMMM, d')} ago
</Meta>
</Line>
)
}

CommunityIssue.propTypes = {
url: PropTypes.string,
title: PropTypes.string,
date: PropTypes.string,
comments: PropTypes.number,
color: PropTypes.string
}

export default function CommunityMeet({ issues, theme, topics }) {
const topicsItems = topics.map(topic => (
<CommunityTopic {...topic} key={topic.url} color={theme.color} />
))

const issuesItems = issues.map(issue => (
<CommunityIssue {...issue} key={issue.url} color={theme.color} />
))

return (
<Wrapper>
<CommunitySection
Expand Down Expand Up @@ -77,29 +135,7 @@ export default function CommunityMeet({ issues, theme, topics }) {
icon="/static/img/community/discourse.svg"
>
{topics.length ? (
topics.map(({ url, title, date, comments }) => (
<Line key={url}>
<Link
color={theme.color}
href={url}
target="_blank"
rel="norefferer nofollow"
>
{title}
</Link>
<Meta>
<Comments
href={url}
target="_blank"
rel="norefferer nofollow"
>
{pluralizeComments(comments)}
</Comments>
&nbsp; last activity{' '}
{formatDistanceToNow(new Date(date), 'MMMM, d')} ago
</Meta>
</Line>
))
<CommunityCarousel items={topicsItems} />
) : (
<Placeholder>Forum is unavailable right now</Placeholder>
)}
Expand All @@ -118,29 +154,7 @@ export default function CommunityMeet({ issues, theme, topics }) {
icon="/static/img/community/github.svg"
>
{issues.length ? (
issues.map(({ url, title, date, comments }) => (
<Line key={url}>
<Link
color={theme.color}
href={url}
target="_black"
rel="noreferrer nofollow"
>
{title}
</Link>
<Meta>
<Comments
href={url}
target="_black"
rel="noreferrer nofollow"
>
{pluralizeComments(comments)}
</Comments>
&nbsp;opened{' '}
{formatDistanceToNow(new Date(date), 'MMMM, d')} ago
</Meta>
</Line>
))
<CommunityCarousel items={issuesItems} />
) : (
<Placeholder>Github is unavailable right now</Placeholder>
)}
Expand Down

0 comments on commit 95f93b8

Please sign in to comment.