Skip to content

Commit

Permalink
Fix #972 Add country flags at username
Browse files Browse the repository at this point in the history
Display of flags for HowTos (List and detail) implemented

TODO: Create firestore trigger to update when user changes location
  • Loading branch information
alromh87 committed Sep 5, 2020
1 parent 372b225 commit dc4ad10
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 16 deletions.
11 changes: 9 additions & 2 deletions src/components/HowToCard/HowToCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import Text from 'src/components/Text'
import Flex from 'src/components/Flex'
import ModerationStatusText from 'src/components/ModerationStatusText'
import { Link } from 'src/components/Links'
import FlagIconEvents from 'src/components/Icons/FlagIcon/FlagIcon'
import TagDisplay from 'src/components/Tags/TagDisplay/TagDisplay'
import { IHowtoDB } from '../../models/howto.models'
import Heading from 'src/components/Heading'

interface IProps {
howto: IHowtoDB
}

export const HowToCard = (props: IProps) => (
<Flex
card
Expand Down Expand Up @@ -45,7 +45,14 @@ export const HowToCard = (props: IProps) => (
<Heading small clipped color={'black'}>
{props.howto.title}
</Heading>
<Text auxiliary>By {props.howto._createdBy}</Text>
<Flex alignItems="center">
{props.howto._creatorCountry && (
<FlagIconEvents code={props.howto._creatorCountry} />
)}
<Text auxiliary my={2} ml={1}>
By {props.howto._createdBy}
</Text>
</Flex>
<Flex mt={4}>
{props.howto.tags &&
Object.keys(props.howto.tags).map(tag => {
Expand Down
3 changes: 3 additions & 0 deletions src/mocks/howto.mock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const HOWTO_MOCK: IHowto[] = [
...MOCK_DB_META('howTo1'),
_createdBy: 'ExampleUser',
moderation: 'draft',
_creatorCountry: 'nl',
},
{
cover_image: exampleUploadImage,
Expand All @@ -62,6 +63,7 @@ export const HOWTO_MOCK: IHowto[] = [
...MOCK_DB_META('howTo2'),
_createdBy: 'ExampleUser',
moderation: 'awaiting-moderation',
_creatorCountry: 'fr',
},
{
cover_image: exampleUploadImage,
Expand All @@ -87,5 +89,6 @@ export const HOWTO_MOCK: IHowto[] = [
...MOCK_DB_META('howTo3'),
_createdBy: 'ExampleUser',
moderation: 'accepted',
_creatorCountry: 'es',
},
]
2 changes: 2 additions & 0 deletions src/models/howto.models.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ export interface IHowtoFormInput extends IModerable {
slug: string
// note, tags will remain optional as if populated {} will be stripped by db (firestore)
tags?: ISelectedTags
// Added to be able to recover on eddit by admin
_creatorCountry?: string
}
32 changes: 19 additions & 13 deletions src/pages/Howto/Content/Howto/HowtoDescription/HowtoDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IUser } from 'src/models/user.models'
import { isAllowToEditContent, emStringToPx } from 'src/utils/helpers'
import theme from 'src/themes/styled.theme'
import ArrowIcon from 'src/assets/icons/icon-arrow-select.svg'
import FlagIconEvents from 'src/components/Icons/FlagIcon/FlagIcon'

interface IProps {
howto: IHowtoDB
Expand Down Expand Up @@ -105,19 +106,24 @@ export default class HowtoDescription extends React.PureComponent<IProps, any> {
)}
</Flex>
<Box mt={3} mb={2}>
<Text inline auxiliary>
By{' '}
<Link
sx={{
textDecoration: 'underline',
color: 'inherit',
}}
to={'/u/' + howto._createdBy}
>
{howto._createdBy}
</Link>{' '}
| Published on {this.dateCreatedByText(howto)}
</Text>
<Flex alignItems="center">
{howto._creatorCountry && (
<FlagIconEvents code={howto._creatorCountry} />
)}
<Text inline auxiliary my={2} ml={1}>
By{' '}
<Link
sx={{
textDecoration: 'underline',
color: 'inherit',
}}
to={'/u/' + howto._createdBy}
>
{howto._createdBy}
</Link>{' '}
| Published on {this.dateCreatedByText(howto)}
</Text>
</Flex>
<Text auxiliary sx={{ color: '#b7b5b5 !important' }} mt={1} mb={2}>
{this.dateLastEditText(howto)}
</Text>
Expand Down
15 changes: 14 additions & 1 deletion src/stores/Howto/howto.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export class HowtoStore extends ModuleStore {
activeUser && howto._createdBy === activeUser.userName
const isAdminAndAccepted =
isAdmin &&
(howto.moderation !== 'draft' && howto.moderation !== 'rejected')
howto.moderation !== 'draft' &&
howto.moderation !== 'rejected'

return isHowToAccepted || wasCreatedByUser || isAdminAndAccepted
})
Expand Down Expand Up @@ -138,6 +139,18 @@ export class HowtoStore extends ModuleStore {
moderation: values.moderation
? values.moderation
: 'awaiting-moderation',
// Avoid replacing user flag on admin edit
_creatorCountry:
(values._createdBy && values._createdBy === user.userName) ||
!values._createdBy
? user.location
? user.location.countryCode
: user.country
? user.country.toLowerCase()
: ''
: values._creatorCountry
? values._creatorCountry
: '',
}
console.log('populating database', howTo)
// set the database document
Expand Down

0 comments on commit dc4ad10

Please sign in to comment.