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

Сверстал страницу события #52

Merged
merged 4 commits into from
Jan 27, 2020
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
Binary file added app/asset/communityFallbackAvatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/asset/curl.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/asset/userFallbackAvatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 47 additions & 29 deletions app/components/Activity/Activity.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React, { useEffect } from 'react'
import useStoreon from 'storeon/react'

import { Spin, Row, Col, Icon } from 'antd'
import './style.css'

import { Spin, Icon } from 'antd'
import { Breadcrumbs, Tags, Button, Curl } from '../UI'
import { ActivityAuthor, CommunityAvatar, Participants } from './atoms'

import {
LIKE,
Expand Down Expand Up @@ -30,7 +34,7 @@ const Activity = ({
const dispatchEvent = (event, id) => {
dispatch(event, { id, event: GET_BY_ID_RELOAD_BY_LU })
}
const onHandlerClick = (userId, activity) => {
const toggleLike = (userId, activity) => {
if (!userId) {
return history.push('/login')
}
Expand All @@ -40,41 +44,55 @@ const Activity = ({
return dispatchEvent(LIKE, activity.id)
}

const { activity, likes } = activityInfo.data
const { activity = {}, likes = [] } = activityInfo.data
const { tags = [], resource = {}, ts = '' } = activity

return (
<div>
<Row>
<Col span={16}>
<h2>
{activity.name}{' '}
<main className="Activity">
<div className="Activity__Breadcrumbs">
<Breadcrumbs />
</div>
<div className="Activity__Wrapper">
<section className="Activity__Content">
<h1 className="Activity__Header">
{activity.name}
{userId && userId === activity.user.id && (
<Icon
type="edit"
onClick={() => history.push(`/activity/${activity.id}/edit`)}
style={{ color: '#1890ff' }}
/>
)}
</h2>
<div style={{ whiteSpace: 'pre-line' }}>{activity.description}</div>
<span
style={{ cursor: 'pointer' }}
onClick={() => onHandlerClick(userId, activity)}
>
<Icon
type="like-o"
style={{ color: activity.likes.isLike ? '#1890ff' : '' }}
/>{' '}
{activity.likes.count}
</span>
</Col>
<Col span={8}>
<h3>Участники</h3>
{likes.map(item => (
<div key={item.id}>{item.user.name}</div>
))}
</Col>
</Row>
</div>
</h1>
<div className="Activity__Tags">
<Tags data={tags} />
</div>
<p className="Activity__Description">{activity.description}</p>
<ActivityAuthor
user={resource.user.name}
community={resource.community.name}
createdAt={ts}
/>
</section>
<section className="Activity__Meta">
<div className="Activity__Community">
<h2 className="Activity__SecondaryHeader">Сообщество</h2>
<CommunityAvatar name={resource.community.name} />
</div>
<div className="Activity__Participants">
<h2 className="Activity__SecondaryHeader">Участники</h2>
<Participants data={likes} />
</div>
</section>
</div>
<Button
onClick={() => toggleLike(userId, activity)}
text={
activity.likes.isLike ? 'Передумал участвовать' : 'Хочу участвовать!'
}
/>
<Curl />
</main>
)
}

Expand Down
28 changes: 28 additions & 0 deletions app/components/Activity/atoms/ActivityAuthor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'

import './style.css'

import Avatar from '../../../UI/Avatar'

export const ActivityAuthor = ({ user, community, createdAt }) => {
const dateObj = new Date(createdAt)
const date = dateObj.toLocaleDateString()
const time = dateObj.toLocaleTimeString()
return (
<div className="ActivityAuthor">
<Avatar
type="user"
size="xs"
alt={user}
className="ActivityAuthor__Avatar"
/>
<div>
<p className="ActivityAuthor__Name">
{user}
{community && `, ${community}`}
</p>
<p className="ActivityAuthor__Date">{`Создано ${date} в ${time}`}</p>
</div>
</div>
)
}
22 changes: 22 additions & 0 deletions app/components/Activity/atoms/ActivityAuthor/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.ActivityAuthor {
display: flex;
align-items: center;
font-size: 12px;
line-height: 19px;
}

.ActivityAuthor__Avatar {
flex-shrink: 0;
margin-right: 10px;
}

.ActivityAuthor__Name {
padding: 0;
margin: 0;
}

.ActivityAuthor__Date {
padding: 0;
margin: 0;
color: #9e9e9e;
}
16 changes: 16 additions & 0 deletions app/components/Activity/atoms/CommunityAvatar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

import './style.css'
import Avatar from '../../../UI/Avatar'

export const CommunityAvatar = ({ name }) => (
<div className="CommunityAvatar">
<Avatar
alt="name"
type="community"
size="m"
className="CommunityAvatar__Avatar"
/>
<p className="CommunityAvatar__Description">{name}</p>
</div>
)
18 changes: 18 additions & 0 deletions app/components/Activity/atoms/CommunityAvatar/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.CommunityAvatar {
display: flex;
align-items: center;
}

.CommunityAvatar__Avatar {
flex-shrink: 0;
margin-right: 16px;
}

.CommunityAvatar__Description {
padding: 0;
margin: 0;
font-size: 16px;
line-height: 19px;
font-weight: 700;
color: #2a2a2a;
}
15 changes: 15 additions & 0 deletions app/components/Activity/atoms/Participants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'
import Avatar from '../../../UI/Avatar'

import './style.css'

export const Participants = ({ data }) =>
data.length > 0 && (
mike1pol marked this conversation as resolved.
Show resolved Hide resolved
<ul className="Participants">
{data.map(({ id }) => (
<li className="Participants__Item" key={id}>
<Avatar type="user" size="s" alt={id} />
</li>
))}
</ul>
)
15 changes: 15 additions & 0 deletions app/components/Activity/atoms/Participants/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.Participants {
margin: 0;
padding: 0;
list-style: none;
display: flex;
flex-wrap: wrap;
}

.Participants__Item {
margin-right: 12px;
}

.Participants__Item:nth-child(4n) {
margin-right: 0;
}
3 changes: 3 additions & 0 deletions app/components/Activity/atoms/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { ActivityAuthor } from './ActivityAuthor'
export { CommunityAvatar } from './CommunityAvatar'
export { Participants } from './Participants'
56 changes: 56 additions & 0 deletions app/components/Activity/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
.Activity {
max-width: 1180px;
padding-top: 60px;
}

.Activity__Breadcrumbs {
margin-bottom: 24px;
}

.Activity__Wrapper {
display: flex;
width: 100%;
margin-bottom: 50px;
}

.Activity__Content {
flex-grow: 1;
padding-right: 100px;
border-right: 2px solid #ababab;
}

.Activity__Meta {
box-sizing: border-box;
min-width: 380px;
padding-left: 100px;
padding-top: 20px;
}

.Activity__Community {
margin-bottom: 50px;
}

.Activity__Header {
font-size: 36px;
line-height: 40px;
font-family: 'PlayfairDisplay', serif;
font-weight: 700;
}

.Activity__SecondaryHeader {
padding: 0;
margin: 0;
margin-bottom: 10px;
font-size: 16px;
line-height: 19px;
font-weight: normal;
}

.Activity__Tags {
margin-bottom: 30px;
}

.Activity__Description {
padding-bottom: 36px;
white-space: pre-line;
}
21 changes: 0 additions & 21 deletions app/components/UI/Avatar.js

This file was deleted.

15 changes: 15 additions & 0 deletions app/components/UI/Avatar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

import './style.css'

const Avatar = ({ type = 'user', size = 'l', src, alt, className = '' }) => {
return (
<img
src={src}
alt={alt}
className={`Avatar Avatar_size_${size} Avatar_type_${type} ${className}`}
/>
)
}

export default Avatar
42 changes: 42 additions & 0 deletions app/components/UI/Avatar/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.Avatar {
display: block;
border-radius: 50%;
background-color: rgba(42, 42, 42, 0.1);
overflow: hidden;
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
}

.Avatar_size_xs {
width: 32px;
height: 32px;
}

.Avatar_size_s {
width: 48px;
height: 48px;
}

.Avatar_size_m {
width: 60px;
height: 60px;
}

.Avatar_size_l {
width: 80px;
height: 80px;
}

.Avatar_size_xl {
width: 180px;
height: 180px;
}

.Avatar_type_user {
background-image: url(../../../asset/userFallbackAvatar.png);
}

.Avatar_type_community {
background-image: url(../../../asset/communityFallbackAvatar.png);
}
11 changes: 11 additions & 0 deletions app/components/UI/Breadcrumbs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

import { Breadcrumb } from 'antd'

export const Breadcrumbs = () => (
<Breadcrumb>
<Breadcrumb.Item>
<a href="#">/Программа</a>
</Breadcrumb.Item>
</Breadcrumb>
)
Loading