feat: use cdn images for map pin calls

This commit is contained in:
Ben Furber
2024-09-02 14:44:12 +01:00
committed by benfurber
parent 7dfc3d29f3
commit 63b55300f2
6 changed files with 48 additions and 23 deletions

View File

@@ -4,7 +4,7 @@ import { Category } from '../Category/Category'
import { MemberBadge } from '../MemberBadge/MemberBadge' import { MemberBadge } from '../MemberBadge/MemberBadge'
import { Username } from '../Username/Username' import { Username } from '../Username/Username'
import type { IProfileCreator } from './types' import type { IProfileCreator } from 'oa-shared'
interface IProps { interface IProps {
creator: IProfileCreator creator: IProfileCreator

View File

@@ -4,7 +4,7 @@ import { Category } from '../Category/Category'
import { MemberBadge } from '../MemberBadge/MemberBadge' import { MemberBadge } from '../MemberBadge/MemberBadge'
import { Username } from '../Username/Username' import { Username } from '../Username/Username'
import type { IProfileCreator } from './types' import type { IProfileCreator } from 'oa-shared'
interface IProps { interface IProps {
creator: IProfileCreator creator: IProfileCreator

View File

@@ -1,23 +1,4 @@
import type { ProfileTypeName } from 'oa-shared' import type { IProfileCreator, ProfileTypeName } from 'oa-shared'
type UserBadges = {
verified: boolean
supporter: boolean
}
export interface IProfileCreator {
_id: string
_lastActive: string
about?: string
badges?: UserBadges
countryCode: string
coverImage?: string
displayName: string
isContactableByPublic: boolean
profileType: ProfileTypeName
subType?: string
userImage?: string
}
export interface ListItem { export interface ListItem {
_id: string _id: string

View File

@@ -1,3 +1,10 @@
import type { ProfileTypeName } from './user'
type UserBadges = {
verified: boolean
supporter: boolean
}
export interface IBoundingBox { export interface IBoundingBox {
_northEast: ILatLng _northEast: ILatLng
_southWest: ILatLng _southWest: ILatLng
@@ -23,3 +30,17 @@ export interface IMapPinDetail {
shortDescription: string shortDescription: string
verifiedBadge?: boolean verifiedBadge?: boolean
} }
export interface IProfileCreator {
_id: string
_lastActive: string
about?: string
badges?: UserBadges
countryCode: string
coverImage?: string
displayName: string
isContactableByPublic: boolean
profileType: ProfileTypeName
subType?: string
userImage?: string
}

View File

@@ -3,6 +3,7 @@ import type {
IMapPinDetail, IMapPinDetail,
IModerationStatus, IModerationStatus,
IPinGrouping, IPinGrouping,
IProfileCreator,
ProfileTypeName, ProfileTypeName,
} from 'oa-shared' } from 'oa-shared'
import type { WorkspaceType } from './userPreciousPlastic.models' import type { WorkspaceType } from './userPreciousPlastic.models'
@@ -31,6 +32,7 @@ export interface IMapPin {
verified: boolean verified: boolean
subType?: IMapPinSubtype subType?: IMapPinSubtype
comments?: string comments?: string
creator?: IProfileCreator
} }
/** /**

View File

@@ -3,6 +3,7 @@ import { collection, getDocs, query, where } from 'firebase/firestore'
import { API_URL } from 'src/config/config' import { API_URL } from 'src/config/config'
import { logger } from 'src/logger' import { logger } from 'src/logger'
import { DB_ENDPOINTS } from 'src/models/dbEndpoints' import { DB_ENDPOINTS } from 'src/models/dbEndpoints'
import { cdnImageUrl } from 'src/utils/cdnImageUrl'
import { firestore } from 'src/utils/firebase' import { firestore } from 'src/utils/firebase'
import type { IMapPin } from '../../models' import type { IMapPin } from '../../models'
@@ -18,7 +19,7 @@ const getMapPins = async () => {
const response = await fetch(API_URL + '/map-pins') const response = await fetch(API_URL + '/map-pins')
const mapPins = await response.json() const mapPins = await response.json()
return mapPins return _transformCreatorImagesToCND(mapPins)
} catch (error) { } catch (error) {
logger.error('Failed to fetch map pins', { error }) logger.error('Failed to fetch map pins', { error })
return [] return []
@@ -57,6 +58,26 @@ const getMapPinSelf = async (userId: string) => {
return userMapPin.data() as IMapPin return userMapPin.data() as IMapPin
} }
const _transformCreatorImagesToCND = (pins: IMapPin[]) => {
return pins.map((pin) => {
if (!pin.creator) {
return pin
}
return {
...pin,
creator: {
...pin.creator,
...(pin.creator.coverImage
? { coverImage: cdnImageUrl(pin.creator.coverImage, { width: 500 }) }
: {}),
...(pin.creator.userImage
? { userImage: cdnImageUrl(pin.creator.userImage, { width: 300 }) }
: {}),
},
}
})
}
export const MapPinServiceContext = createContext<IMapPinService | null>(null) export const MapPinServiceContext = createContext<IMapPinService | null>(null)
export const mapPinService: IMapPinService = { export const mapPinService: IMapPinService = {