From c3822fb0ba0bc9c89c84ce077a52e118591a8cb0 Mon Sep 17 00:00:00 2001 From: mrkvon Date: Wed, 27 Nov 2019 20:24:22 +0100 Subject: [PATCH] migrated the tribe panel --- .../client/components/TribeItem.component.js | 50 +++++++++++++++++++ .../components/helpers/getTribeBackground.js | 44 ++++++++++++++++ modules/tribes/client/less/tribes-grid.less | 2 +- .../client/views/tribes-list.client.view.html | 38 +++----------- public/locales/en/tribes.json | 5 ++ 5 files changed, 106 insertions(+), 33 deletions(-) create mode 100644 modules/tribes/client/components/TribeItem.component.js create mode 100644 modules/tribes/client/components/helpers/getTribeBackground.js create mode 100644 public/locales/en/tribes.json diff --git a/modules/tribes/client/components/TribeItem.component.js b/modules/tribes/client/components/TribeItem.component.js new file mode 100644 index 0000000000..2555fef5f2 --- /dev/null +++ b/modules/tribes/client/components/TribeItem.component.js @@ -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
+ + {tribe.new && + + New tribe! + + } +
+

{tribe.label}

+ {countInfo} +
+
+
+ {tribe && } +
+
; +} + +TribeItem.propTypes = { + tribe: PropTypes.object.isRequired, + user: PropTypes.object, + onMembershipUpdated: PropTypes.func.isRequired +}; diff --git a/modules/tribes/client/components/helpers/getTribeBackground.js b/modules/tribes/client/components/helpers/getTribeBackground.js new file mode 100644 index 0000000000..cea62dcb9b --- /dev/null +++ b/modules/tribes/client/components/helpers/getTribeBackground.js @@ -0,0 +1,44 @@ +/** + * Generate background color + image styles for tribe panel + * + * usage in React:
...
+ * + * @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; +} diff --git a/modules/tribes/client/less/tribes-grid.less b/modules/tribes/client/less/tribes-grid.less index 6db794241b..810a82241c 100644 --- a/modules/tribes/client/less/tribes-grid.less +++ b/modules/tribes/client/less/tribes-grid.less @@ -7,7 +7,7 @@ background-color: @brand-primary; background-size: cover; height: 250px; - width: 288px; + width: 100%; margin: 0; padding: 0; color: #fff; diff --git a/modules/tribes/client/views/tribes-list.client.view.html b/modules/tribes/client/views/tribes-list.client.view.html index 1a7044e0fe..0a3dc97060 100644 --- a/modules/tribes/client/views/tribes-list.client.view.html +++ b/modules/tribes/client/views/tribes-list.client.view.html @@ -29,38 +29,12 @@

Discover Tribes

ag-grid-width="288" ag-gutter-size="10" ag-refresh-on-img-load="false"> -
  • - - -
    -

    - -
    -
    -
    - -
    +
  • +
  • diff --git a/public/locales/en/tribes.json b/public/locales/en/tribes.json new file mode 100644 index 0000000000..2969e0447c --- /dev/null +++ b/public/locales/en/tribes.json @@ -0,0 +1,5 @@ +{ + "No members yet": "No members yet", + "{{count}} members": "One member", + "{{count}} members_plural": "{{count}} members" +}