Rename group dashboard to 'About Post'
This commit is contained in:
parent
6372d262cb
commit
eca2c8f441
|
@ -10,7 +10,7 @@ export type Group = {
|
||||||
anyoneCanJoin: boolean
|
anyoneCanJoin: boolean
|
||||||
contractIds: string[]
|
contractIds: string[]
|
||||||
|
|
||||||
dashboardId?: string
|
aboutPostId?: string
|
||||||
chatDisabled?: boolean
|
chatDisabled?: boolean
|
||||||
mostRecentChatActivityTime?: number
|
mostRecentChatActivityTime?: number
|
||||||
mostRecentContractAddedTime?: number
|
mostRecentContractAddedTime?: number
|
||||||
|
|
|
@ -160,7 +160,7 @@ service cloud.firestore {
|
||||||
allow update: if request.auth.uid == resource.data.creatorId
|
allow update: if request.auth.uid == resource.data.creatorId
|
||||||
&& request.resource.data.diff(resource.data)
|
&& request.resource.data.diff(resource.data)
|
||||||
.affectedKeys()
|
.affectedKeys()
|
||||||
.hasOnly(['name', 'about', 'contractIds', 'memberIds', 'anyoneCanJoin', 'dashboardId' ]);
|
.hasOnly(['name', 'about', 'contractIds', 'memberIds', 'anyoneCanJoin', 'aboutPostId' ]);
|
||||||
allow update: if (request.auth.uid in resource.data.memberIds || resource.data.anyoneCanJoin)
|
allow update: if (request.auth.uid in resource.data.memberIds || resource.data.anyoneCanJoin)
|
||||||
&& request.resource.data.diff(resource.data)
|
&& request.resource.data.diff(resource.data)
|
||||||
.affectedKeys()
|
.affectedKeys()
|
||||||
|
|
|
@ -8,72 +8,72 @@ import { Group } from 'common/group'
|
||||||
import { deleteFieldFromGroup, updateGroup } from 'web/lib/firebase/groups'
|
import { deleteFieldFromGroup, updateGroup } from 'web/lib/firebase/groups'
|
||||||
import PencilIcon from '@heroicons/react/solid/PencilIcon'
|
import PencilIcon from '@heroicons/react/solid/PencilIcon'
|
||||||
import { DocumentRemoveIcon } from '@heroicons/react/solid'
|
import { DocumentRemoveIcon } from '@heroicons/react/solid'
|
||||||
import { createDashboard } from 'web/lib/firebase/api'
|
import { createPost } from 'web/lib/firebase/api'
|
||||||
import { Dashboard } from 'common/dashboard'
|
import { Post } from 'common/post'
|
||||||
import { deleteDashboard, updateDashboard } from 'web/lib/firebase/dashboards'
|
import { deletePost, updatePost } from 'web/lib/firebase/posts'
|
||||||
import { useRouter } from 'next/router'
|
import { useRouter } from 'next/router'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
|
||||||
export function GroupDashboard(props: {
|
export function GroupAboutPost(props: {
|
||||||
group: Group
|
group: Group
|
||||||
isCreator: boolean
|
isCreator: boolean
|
||||||
dashboard: Dashboard
|
post: Post
|
||||||
}) {
|
}) {
|
||||||
const { group, isCreator, dashboard } = props
|
const { group, isCreator, post } = props
|
||||||
const isAdmin = useAdmin()
|
const isAdmin = useAdmin()
|
||||||
|
|
||||||
if (group.dashboardId == null && !isCreator) {
|
if (group.aboutPostId == null && !isCreator) {
|
||||||
return <p className="text-center">No dashboard has been created </p>
|
return <p className="text-center">No post has been created </p>
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-md bg-white p-4">
|
<div className="rounded-md bg-white p-4">
|
||||||
{isCreator || isAdmin ? (
|
{isCreator || isAdmin ? (
|
||||||
<RichEditGroupDashboard group={group} dashboard={dashboard} />
|
<RichEditGroupAboutPost group={group} post={post} />
|
||||||
) : (
|
) : (
|
||||||
<Content content={dashboard.content} />
|
<Content content={post.content} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) {
|
function RichEditGroupAboutPost(props: { group: Group; post: Post }) {
|
||||||
const { group, dashboard } = props
|
const { group, post } = props
|
||||||
const [editing, setEditing] = useState(false)
|
const [editing, setEditing] = useState(false)
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
const { editor, upload } = useTextEditor({
|
const { editor, upload } = useTextEditor({
|
||||||
defaultValue: dashboard.content,
|
defaultValue: post.content,
|
||||||
disabled: isSubmitting,
|
disabled: isSubmitting,
|
||||||
})
|
})
|
||||||
|
|
||||||
async function saveDashboard() {
|
async function savePost() {
|
||||||
if (!editor) return
|
if (!editor) return
|
||||||
const newDashboard = {
|
const newPost = {
|
||||||
name: group.name,
|
title: group.name,
|
||||||
content: editor.getJSON(),
|
content: editor.getJSON(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.dashboardId == null) {
|
if (group.aboutPostId == null) {
|
||||||
const result = await createDashboard(newDashboard).catch((e) => {
|
const result = await createPost(newPost).catch((e) => {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
return e
|
return e
|
||||||
})
|
})
|
||||||
await updateGroup(group, {
|
await updateGroup(group, {
|
||||||
dashboardId: result.dashboard.id,
|
aboutPostId: result.post.id,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
await updateDashboard(dashboard, {
|
await updatePost(post, {
|
||||||
content: newDashboard.content,
|
content: newPost.content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await router.replace(router.asPath)
|
await router.replace(router.asPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteGroupDashboard() {
|
async function deleteGroupAboutPost() {
|
||||||
await deleteDashboard(dashboard)
|
await deletePost(post)
|
||||||
await deleteFieldFromGroup(group, 'dashboardId')
|
await deleteFieldFromGroup(group, 'aboutPostId')
|
||||||
await router.replace(router.asPath)
|
await router.replace(router.asPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) {
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
await saveDashboard()
|
await savePost()
|
||||||
setEditing(false)
|
setEditing(false)
|
||||||
setIsSubmitting(false)
|
setIsSubmitting(false)
|
||||||
}}
|
}}
|
||||||
|
@ -99,12 +99,12 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) {
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{group.dashboardId == null ? (
|
{group.aboutPostId == null ? (
|
||||||
<div className="text-center text-gray-500">
|
<div className="text-center text-gray-500">
|
||||||
<p className="text-sm">
|
<p className="text-sm">
|
||||||
No dashboard has been created yet.
|
No post has been added yet.
|
||||||
<Spacer h={2} />
|
<Spacer h={2} />
|
||||||
<Button onClick={() => setEditing(true)}>Create a dashboard</Button>
|
<Button onClick={() => setEditing(true)}>Add a post</Button>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
@ -126,7 +126,7 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) {
|
||||||
color="gray"
|
color="gray"
|
||||||
size="xs"
|
size="xs"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
deleteGroupDashboard()
|
deleteGroupAboutPost()
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DocumentRemoveIcon className="inline h-4 w-4" />
|
<DocumentRemoveIcon className="inline h-4 w-4" />
|
||||||
|
@ -134,7 +134,7 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) {
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Content content={dashboard.content} />
|
<Content content={post.content} />
|
||||||
<Spacer h={2} />
|
<Spacer h={2} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
|
@ -18,7 +18,6 @@ import {
|
||||||
} from './utils'
|
} from './utils'
|
||||||
import { Contract } from 'common/contract'
|
import { Contract } from 'common/contract'
|
||||||
import { updateContract } from 'web/lib/firebase/contracts'
|
import { updateContract } from 'web/lib/firebase/contracts'
|
||||||
import * as admin from 'firebase-admin'
|
|
||||||
|
|
||||||
export const groups = coll<Group>('groups')
|
export const groups = coll<Group>('groups')
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ export function groupPath(
|
||||||
| 'about'
|
| 'about'
|
||||||
| typeof GROUP_CHAT_SLUG
|
| typeof GROUP_CHAT_SLUG
|
||||||
| 'leaderboards'
|
| 'leaderboards'
|
||||||
| 'dashboard'
|
|
||||||
) {
|
) {
|
||||||
return `/group/${groupSlug}${subpath ? `/${subpath}` : ''}`
|
return `/group/${groupSlug}${subpath ? `/${subpath}` : ''}`
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,9 +45,9 @@ import { Button } from 'web/components/button'
|
||||||
import { listAllCommentsOnGroup } from 'web/lib/firebase/comments'
|
import { listAllCommentsOnGroup } from 'web/lib/firebase/comments'
|
||||||
import { GroupComment } from 'common/comment'
|
import { GroupComment } from 'common/comment'
|
||||||
import { REFERRAL_AMOUNT } from 'common/economy'
|
import { REFERRAL_AMOUNT } from 'common/economy'
|
||||||
import { GroupDashboard } from 'web/components/groups/group-dashboard'
|
import { GroupAboutPost } from 'web/components/groups/group-about-post'
|
||||||
import { getDashboard } from 'web/lib/firebase/dashboards'
|
import { getPost } from 'web/lib/firebase/posts'
|
||||||
import { Dashboard } from 'common/dashboard'
|
import { Post } from 'common/post'
|
||||||
import { Spacer } from 'web/components/layout/spacer'
|
import { Spacer } from 'web/components/layout/spacer'
|
||||||
|
|
||||||
export const getStaticProps = fromPropz(getStaticPropz)
|
export const getStaticProps = fromPropz(getStaticPropz)
|
||||||
|
@ -61,10 +61,8 @@ export async function getStaticPropz(props: { params: { slugs: string[] } }) {
|
||||||
const contracts =
|
const contracts =
|
||||||
(group && (await listContractsByGroupSlug(group.slug))) ?? []
|
(group && (await listContractsByGroupSlug(group.slug))) ?? []
|
||||||
|
|
||||||
const dashboard =
|
const aboutPost =
|
||||||
group &&
|
group && group.aboutPostId != null && (await getPost(group.aboutPostId))
|
||||||
group.dashboardId != null &&
|
|
||||||
(await getDashboard(group.dashboardId))
|
|
||||||
const bets = await Promise.all(
|
const bets = await Promise.all(
|
||||||
contracts.map((contract: Contract) => listAllBets(contract.id))
|
contracts.map((contract: Contract) => listAllBets(contract.id))
|
||||||
)
|
)
|
||||||
|
@ -91,7 +89,7 @@ export async function getStaticPropz(props: { params: { slugs: string[] } }) {
|
||||||
creatorScores,
|
creatorScores,
|
||||||
topCreators,
|
topCreators,
|
||||||
messages,
|
messages,
|
||||||
dashboard,
|
aboutPost,
|
||||||
},
|
},
|
||||||
|
|
||||||
revalidate: 60, // regenerate after a minute
|
revalidate: 60, // regenerate after a minute
|
||||||
|
@ -130,7 +128,7 @@ export default function GroupPage(props: {
|
||||||
creatorScores: { [userId: string]: number }
|
creatorScores: { [userId: string]: number }
|
||||||
topCreators: User[]
|
topCreators: User[]
|
||||||
messages: GroupComment[]
|
messages: GroupComment[]
|
||||||
dashboard: Dashboard
|
aboutPost: Post
|
||||||
}) {
|
}) {
|
||||||
props = usePropz(props, getStaticPropz) ?? {
|
props = usePropz(props, getStaticPropz) ?? {
|
||||||
group: null,
|
group: null,
|
||||||
|
@ -149,7 +147,7 @@ export default function GroupPage(props: {
|
||||||
topTraders,
|
topTraders,
|
||||||
creatorScores,
|
creatorScores,
|
||||||
topCreators,
|
topCreators,
|
||||||
dashboard,
|
aboutPost,
|
||||||
} = props
|
} = props
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
@ -187,11 +185,11 @@ export default function GroupPage(props: {
|
||||||
|
|
||||||
const aboutTab = (
|
const aboutTab = (
|
||||||
<Col>
|
<Col>
|
||||||
{group.dashboardId != null || isCreator ? (
|
{group.aboutPostId != null || isCreator ? (
|
||||||
<GroupDashboard
|
<GroupAboutPost
|
||||||
group={group}
|
group={group}
|
||||||
isCreator={!!isCreator}
|
isCreator={!!isCreator}
|
||||||
dashboard={dashboard}
|
post={aboutPost}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div></div>
|
<div></div>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user