-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mrkvon
committed
Dec 13, 2019
1 parent
41e12f5
commit c42509d
Showing
5 changed files
with
106 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import JoinButton from './JoinButton.component'; | ||
|
||
import getTribeBackground from './helpers/getTribeBackground'; | ||
|
||
/** | ||
* @TODO maybe rename to Tribe | ||
*/ | ||
export default function TribeItem({ tribe, user, onMembershipUpdated }) { | ||
const { t } = useTranslation('tribes'); | ||
|
||
const countInfo = (tribe.count === 0) | ||
? t('No members yet') | ||
: t('{{count}} members', { count: tribe.count }); | ||
|
||
return <div | ||
className="panel tribe tribe-image" | ||
style={getTribeBackground(tribe, { isProgressive: true, dimensions: '742x496' })} | ||
> | ||
<a href={`/tribes/${tribe.slug}`} className="tribe-link"> | ||
{tribe.new && <span className="tribe-new" aria-hidden={true}> | ||
<span className="label label-primary"> | ||
New tribe! | ||
</span> | ||
</span>} | ||
<div className={classnames('tribe-content', tribe.image_UUID ? 'is-image' : '')}> | ||
<h3 className="font-brand-light tribe-label">{tribe.label}</h3> | ||
<span className="tribe-meta">{countInfo}</span> | ||
</div> | ||
</a> | ||
<div className="tribe-actions"> | ||
{tribe && <JoinButton | ||
tribe={tribe} | ||
user={user} | ||
icon={true} | ||
onUpdated={onMembershipUpdated} | ||
/>} | ||
</div> | ||
</div>; | ||
} | ||
|
||
TribeItem.propTypes = { | ||
tribe: PropTypes.object.isRequired, | ||
user: PropTypes.object, | ||
onMembershipUpdated: PropTypes.func.isRequired | ||
}; |
44 changes: 44 additions & 0 deletions
44
modules/tribes/client/components/helpers/getTribeBackground.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* Generate background color + image styles for tribe panel | ||
* | ||
* usage in React: <div style={getTribeBackground(tribe, { quality: 'normal', dimensions: '742x496', isProgressive: true })}>...</div> | ||
* | ||
* @param {object} tribe - the tribe data | ||
* | ||
* @param {string} [dimensions=1024x768] - Set background image dimensions (width x height) | ||
* See https://uploadcare.com/documentation/cdn/#operation-scale-crop | ||
* | ||
* @param {string} [quality=lighter] - Set background image quality | ||
* Options: normal, better, best, lighter (default), lightest | ||
* See https://uploadcare.com/documentation/cdn/#operation-quality | ||
* | ||
* @param {boolean} [isProgressive=false] - Set progressive image loading | ||
* See https://uploadcare.com/documentation/cdn/#operation-progressive | ||
* | ||
* @returns {object} | ||
*/ | ||
export default function getTribeBackground(tribe, { quality='lighter', dimensions='1024x768', isProgressive=false }={}) { | ||
const style = {}; | ||
|
||
// Set background image | ||
// Uses Uploadcare.com to resize and deliver images | ||
if (tribe.image_UUID) { | ||
const progressive = isProgressive ? 'yes' : 'no'; | ||
|
||
const imgParams = [ | ||
`progressive/${progressive}`, | ||
`scale_crop/${dimensions}/center`, | ||
`quality/${quality}`, | ||
'format/jpeg' | ||
]; | ||
|
||
const imageUrl = `https://ucarecdn.com/${tribe.image_UUID}/-/${imgParams.join('/-/')}/`; | ||
style.backgroundImage = `url(${imageUrl})`; | ||
} | ||
|
||
if (tribe.color) { | ||
style.backgroundColor = tribe.color; | ||
} | ||
|
||
return style; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"No members yet": "No members yet", | ||
"{{count}} members": "One member", | ||
"{{count}} members_plural": "{{count}} members" | ||
} |