Posts now have denormalized creator username and name
This commit is contained in:
parent
84e2b63c49
commit
8ae1166c49
|
@ -8,6 +8,10 @@ export type Post = {
|
||||||
creatorId: string // User id
|
creatorId: string // User id
|
||||||
createdTime: number
|
createdTime: number
|
||||||
slug: string
|
slug: string
|
||||||
|
|
||||||
|
// denormalized user fields
|
||||||
|
creatorName: string
|
||||||
|
creatorUsername: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DateDoc = Post & {
|
export type DateDoc = Post & {
|
||||||
|
|
|
@ -100,6 +100,8 @@ export const createpost = newEndpoint({}, async (req, auth) => {
|
||||||
createdTime: Date.now(),
|
createdTime: Date.now(),
|
||||||
content: content,
|
content: content,
|
||||||
contractSlug,
|
contractSlug,
|
||||||
|
creatorName: creator.name,
|
||||||
|
creatorUsername: creator.username,
|
||||||
})
|
})
|
||||||
|
|
||||||
await postRef.create(post)
|
await postRef.create(post)
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { DocumentIcon } from '@heroicons/react/solid'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { Post } from 'common/post'
|
import { Post } from 'common/post'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import { useUserById } from 'web/hooks/use-user'
|
|
||||||
import { postPath } from 'web/lib/firebase/posts'
|
import { postPath } from 'web/lib/firebase/posts'
|
||||||
import { fromNow } from 'web/lib/util/time'
|
import { fromNow } from 'web/lib/util/time'
|
||||||
import { Avatar } from './avatar'
|
import { Avatar } from './avatar'
|
||||||
|
@ -17,13 +16,8 @@ export function PostCard(props: {
|
||||||
highlightOptions?: CardHighlightOptions
|
highlightOptions?: CardHighlightOptions
|
||||||
}) {
|
}) {
|
||||||
const { post, onPostClick, highlightOptions } = props
|
const { post, onPostClick, highlightOptions } = props
|
||||||
const creatorId = post.creatorId
|
|
||||||
|
|
||||||
const user = useUserById(creatorId)
|
|
||||||
const { itemIds: itemIds, highlightClassName } = highlightOptions || {}
|
const { itemIds: itemIds, highlightClassName } = highlightOptions || {}
|
||||||
|
|
||||||
if (!user) return <> </>
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative py-1">
|
<div className="relative py-1">
|
||||||
<Card
|
<Card
|
||||||
|
@ -33,14 +27,14 @@ export function PostCard(props: {
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex-shrink-0">
|
<div className="flex-shrink-0">
|
||||||
<Avatar className="h-12 w-12" username={user?.username} />
|
<Avatar className="h-12 w-12" username={post.creatorUsername} />
|
||||||
</div>
|
</div>
|
||||||
<div className="">
|
<div className="">
|
||||||
<div className="text-sm text-gray-500">
|
<div className="text-sm text-gray-500">
|
||||||
<UserLink
|
<UserLink
|
||||||
className="text-neutral"
|
className="text-neutral"
|
||||||
name={user?.name}
|
name={post.creatorName}
|
||||||
username={user?.username}
|
username={post.creatorUsername}
|
||||||
/>
|
/>
|
||||||
<span className="mx-1">•</span>
|
<span className="mx-1">•</span>
|
||||||
<span className="text-gray-500">{fromNow(post.createdTime)}</span>
|
<span className="text-gray-500">{fromNow(post.createdTime)}</span>
|
||||||
|
|
|
@ -52,7 +52,13 @@ export default function CreateDateDocPage() {
|
||||||
|
|
||||||
const newPost: Omit<
|
const newPost: Omit<
|
||||||
DateDoc,
|
DateDoc,
|
||||||
'id' | 'creatorId' | 'createdTime' | 'slug' | 'contractSlug'
|
| 'id'
|
||||||
|
| 'creatorId'
|
||||||
|
| 'createdTime'
|
||||||
|
| 'slug'
|
||||||
|
| 'contractSlug'
|
||||||
|
| 'creatorUsername'
|
||||||
|
| 'creatorName'
|
||||||
> & { question?: string } = removeUndefinedProps({
|
> & { question?: string } = removeUndefinedProps({
|
||||||
title,
|
title,
|
||||||
subtitle,
|
subtitle,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user