Skip to content

Commit

Permalink
Merge pull request #3248 from ONEARMY/master
Browse files Browse the repository at this point in the history
🤖 Release PR
  • Loading branch information
thisislawatts authored Feb 1, 2024
2 parents 4984941 + ae3d3f3 commit 3f762f0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/pages/User/content/SpaceProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ export const SpaceProfile = ({ user, docs }: IProps) => {
flexDirection: ['column', 'column', 'row'],
justifyContent: 'space-between',
alignItems: 'flex-start',
gap: [0, 0, 6],
}}
>
<Box
Expand Down
51 changes: 51 additions & 0 deletions src/stores/Discussions/discussionEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { logger } from 'src/logger'

import type { IDiscussion } from 'src/models'
import type { DatabaseV2 } from '../databaseV2'
import type { DBEndpoint } from '../databaseV2/endpoints'

type DiscussionEndpoints = Extract<
DBEndpoint,
'howtos' | 'research' | 'questions'
>

export const updateDiscussionMetadata = (
db: DatabaseV2,
discussion: IDiscussion,
) => {
const collectionName = getCollectionName(discussion.sourceType)

if (!collectionName) {
logger.trace(
`Unable to find collection. Discussion metadata was not updated. sourceType: ${discussion.sourceType}`,
)
return
}

const commentCount = discussion.comments.length
const latestCommentDate = new Date(
Math.max(
...discussion.comments.map((comment) =>
new Date(comment._created).valueOf(),
),
),
)

return db
.collection(collectionName)
.doc(discussion.sourceId)
.update({ commentCount, latestCommentDate })
}

const getCollectionName = (sourceType: string): DiscussionEndpoints | null => {
switch (sourceType) {
case 'question':
return 'questions'
case 'howto':
return 'howtos'
case 'research':
return 'research'
default:
return null
}
}
3 changes: 3 additions & 0 deletions src/stores/Discussions/discussions.store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getUserCountry } from 'src/utils/getUserCountry'
import { hasAdminRights, randomID } from 'src/utils/helpers'

import { ModuleStore } from '../common/module.store'
import { updateDiscussionMetadata } from './discussionEvents'

import type { IUserPPDB } from 'src/models'
import type {
Expand Down Expand Up @@ -209,6 +210,8 @@ export class DiscussionStore extends ModuleStore {
) {
await dbRef.set({ ...cloneDeep(discussion) })

updateDiscussionMetadata(this.db, discussion)

return toJS(dbRef.get())
}

Expand Down

0 comments on commit 3f762f0

Please sign in to comment.