Skip to content

Commit

Permalink
feat: update architectural design
Browse files Browse the repository at this point in the history
  • Loading branch information
benfurber committed Oct 22, 2024
1 parent 33c2a14 commit cf1eed6
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 24 deletions.
9 changes: 6 additions & 3 deletions functions/src/userUpdates/updateMapPins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { db } from '../Firebase/firestoreDB'
import {
getCreatorImage,
getFirstCoverImage,
getValidTags,
hasDetailsForMapPinChanged,
} from './utils'

Expand Down Expand Up @@ -32,14 +33,15 @@ export const updateMapPins = async (prevUser: IUserDB, user: IUserDB) => {
coverImages,
displayName,
isContactableByPublic,
location,
profileType,
workspaceType,
userImage,
location,
workspaceType,
} = user
const creatorImage = getCreatorImage(userImage)
const coverImage = getFirstCoverImage(coverImages)
const countryCode = location?.countryCode || country || ''
const tags = user.tags ? getValidTags(user.tags) : []

const creator = {
_lastActive,
Expand All @@ -50,8 +52,9 @@ export const updateMapPins = async (prevUser: IUserDB, user: IUserDB) => {
displayName,
isContactableByPublic,
profileType,
workspaceType,
tags,
userImage: creatorImage,
workspaceType,
}

// Only one expected
Expand Down
15 changes: 14 additions & 1 deletion functions/src/userUpdates/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { profileTags } from 'oa-shared'

import { valuesAreDeepEqual } from '../Utils'

import type { IUserDB } from 'oa-shared/models/user'
import type { ISelectedTags, ITag, IUserDB } from 'oa-shared'

export const hasDetailsChanged = (
prevUser: IUserDB,
Expand Down Expand Up @@ -81,3 +83,14 @@ export const getCreatorImage = (userImage: IUserDB['userImage']) => {
export const getFirstCoverImage = (coverImages: IUserDB['coverImages']) => {
return coverImages?.[0]?.downloadUrl || null
}

// For ease, duplicated from src/utils/getValidTags.ts
export const getValidTags = (tagIds: ISelectedTags) => {
const selectedTagIds = Object.keys(tagIds).filter((id) => tagIds[id] === true)
const tags: ITag[] = selectedTagIds
.map((id) => profileTags.find(({ _id }) => id === _id))
.filter((tag): tag is ITag => !!tag)
.filter(({ _deleted }) => _deleted !== true)

return tags
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const CardDetailsSpaceProfile = ({ creator, isLink }: IProps) => {
/>
)}

{tags && <ProfileTagsList tagIds={tags} />}
{tags && <ProfileTagsList tags={tags} />}

{about && (
<Text variant="quiet" sx={{ fontSize: 2 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ export default {

export const Default: StoryFn<typeof ProfileTagsList> = () => (
<ProfileTagsList
tagIds={{ uCzWZbz3aVKyx2keoqRi: true, J3LF7fMsDfniYT2ZX3rf: false }}
tags={[
{
_id: 'hwh',
_created: 'today',
_deleted: false,
label: 'Any old thing',
},
{
_id: 'a45397uh',
_created: 'yesterday',
_deleted: false,
label: 'Any old thing',
},
]}
/>
)
16 changes: 3 additions & 13 deletions packages/components/src/ProfileTagsList/ProfileTagsList.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import { profileTags } from 'oa-shared'
import { Flex } from 'theme-ui'

import { Category } from '../Category/Category'

import type { ISelectedTags } from 'oa-shared'
import type { ITag } from 'oa-shared'

export interface IProps {
tagIds: ISelectedTags
tags: ITag[]
}

export const ProfileTagsList = ({ tagIds }: IProps) => {
const selectedTagIds = Object.keys(tagIds).filter((id) => tagIds[id] === true)
const tags = selectedTagIds
.map((id) => profileTags.find(({ _id }) => id === _id))
.filter((tag) => tag !== undefined)

if (tags.length === 0) {
return null
}

export const ProfileTagsList = ({ tags }: IProps) => {
return (
<Flex sx={{ gap: 2, flexWrap: 'wrap' }}>
{tags.map(
Expand Down
4 changes: 2 additions & 2 deletions shared/models/maps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ILatLng } from './common'
import type { IModerationStatus } from './moderation'
import type { ISelectedTags } from './tags'
import type { ITag } from './tags'
import type { IUserBadges, ProfileTypeName, WorkspaceType } from './user'

/**
Expand Down Expand Up @@ -69,7 +69,7 @@ export interface IProfileCreator {
displayName: string
isContactableByPublic: boolean
profileType: ProfileTypeName
tags?: ISelectedTags
tags?: ITag[]
workspaceType?: string
userImage?: string
}
Expand Down
18 changes: 18 additions & 0 deletions src/common/ProfileTags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ProfileTagsList } from 'oa-components'
import { getValidTags } from 'src/utils/getValidTags'

import type { ISelectedTags } from 'oa-shared'

interface IProps {
tagIds: ISelectedTags
}

export const ProfileTags = ({ tagIds }: IProps) => {
const tags = getValidTags(tagIds)

if (tags.length === 0) {
return null
}

return <ProfileTagsList tags={tags} />
}
4 changes: 2 additions & 2 deletions src/pages/User/content/SpaceProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
ImageGallery,
MemberBadge,
ProfileTagsList,
Tab,
TabPanel,
Tabs,
Expand All @@ -19,6 +18,7 @@ import PPIcon from 'src/assets/images/plastic-types/pp.svg'
import PSIcon from 'src/assets/images/plastic-types/ps.svg'
import PVCIcon from 'src/assets/images/plastic-types/pvc.svg'
import { AuthWrapper } from 'src/common/AuthWrapper'
import { ProfileTags } from 'src/common/ProfileTags'
import { isPreciousPlastic } from 'src/config/config'
import { cdnImageUrl } from 'src/utils/cdnImageUrl'
import { formatImagesForGallery } from 'src/utils/formatImageListForGallery'
Expand Down Expand Up @@ -247,7 +247,7 @@ export const SpaceProfile = ({ user, docs }: IProps) => {
width: ['100%', '100%', '80%'],
}}
>
{tags && <ProfileTagsList tagIds={tags} />}
{tags && <ProfileTags tagIds={tags} />}
{about && <Paragraph>{about}</Paragraph>}

{profileType === ProfileTypeList.COLLECTION_POINT &&
Expand Down
3 changes: 2 additions & 1 deletion src/stores/Maps/maps.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { action, makeObservable, observable } from 'mobx'
import { IModerationStatus, ProfileTypeList } from 'oa-shared'
import { logger } from 'src/logger'
import { DEFAULT_PUBLIC_CONTACT_PREFERENCE } from 'src/pages/UserSettings/constants'
import { getValidTags } from 'src/utils/getValidTags'
import {
hasAdminRights,
isAllowedToPin,
Expand Down Expand Up @@ -180,7 +181,6 @@ export class MapsStore extends ModuleStore {
location,
profileType,
userImage,
tags,
verified,
workspaceType,
} = user
Expand All @@ -193,6 +193,7 @@ export class MapsStore extends ModuleStore {

const isMember = type === ProfileTypeList.MEMBER
const subType = !isMember && workspaceType
const tags = user.tags && getValidTags(user.tags)

// Member pins do not require moderation.
if (isMember) {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/getValidTags.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, expect, it } from 'vitest'

import { getValidTags } from "./getValidTags"

describe('getValidTags', () => {
it('returns only true valid tags', () => {
const tagIds = {
'uCzWZbz3aVKyx2keoqRi': true, // A valid tag
'J3LF7fMsDfniYT2ZX3rf': false, // A valid tag
'not-a-tag': false,
}
const tags = getValidTags(tagIds)
expect(tags.length).toEqual(1)
expect(tags[0]._id).toEqual('uCzWZbz3aVKyx2keoqRi')
})
})
15 changes: 15 additions & 0 deletions src/utils/getValidTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { profileTags } from 'oa-shared'

import type { ISelectedTags, ITag } from 'oa-shared'

// For ease, duplicated from functions/src/uperUpdates/utils.ts
export const getValidTags = (tagIds: ISelectedTags): ITag[] => {
const selectedTagIds = Object.keys(tagIds).filter((id) => tagIds[id] === true)

const tags: ITag[] = selectedTagIds
.map((id) => profileTags.find(({ _id }) => id === _id))
.filter((tag): tag is ITag => !!tag)
.filter(({ _deleted }) => _deleted !== true)

return tags
}

0 comments on commit cf1eed6

Please sign in to comment.