From eca2c8f4410665b13bd5237d9a7193216a19ac8a Mon Sep 17 00:00:00 2001 From: Pico2x Date: Mon, 29 Aug 2022 17:01:41 +0100 Subject: [PATCH] Rename group dashboard to 'About Post' --- common/group.ts | 2 +- firestore.rules | 2 +- ...oup-dashboard.tsx => group-about-post.tsx} | 60 +++++++++---------- web/lib/firebase/groups.ts | 2 - web/pages/group/[...slugs]/index.tsx | 24 ++++---- 5 files changed, 43 insertions(+), 47 deletions(-) rename web/components/groups/{group-dashboard.tsx => group-about-post.tsx} (64%) diff --git a/common/group.ts b/common/group.ts index c449f451..181ad153 100644 --- a/common/group.ts +++ b/common/group.ts @@ -10,7 +10,7 @@ export type Group = { anyoneCanJoin: boolean contractIds: string[] - dashboardId?: string + aboutPostId?: string chatDisabled?: boolean mostRecentChatActivityTime?: number mostRecentContractAddedTime?: number diff --git a/firestore.rules b/firestore.rules index 122ceed8..26aa52e0 100644 --- a/firestore.rules +++ b/firestore.rules @@ -160,7 +160,7 @@ service cloud.firestore { allow update: if request.auth.uid == resource.data.creatorId && request.resource.data.diff(resource.data) .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) && request.resource.data.diff(resource.data) .affectedKeys() diff --git a/web/components/groups/group-dashboard.tsx b/web/components/groups/group-about-post.tsx similarity index 64% rename from web/components/groups/group-dashboard.tsx rename to web/components/groups/group-about-post.tsx index 3d18140a..64336fde 100644 --- a/web/components/groups/group-dashboard.tsx +++ b/web/components/groups/group-about-post.tsx @@ -8,72 +8,72 @@ import { Group } from 'common/group' import { deleteFieldFromGroup, updateGroup } from 'web/lib/firebase/groups' import PencilIcon from '@heroicons/react/solid/PencilIcon' import { DocumentRemoveIcon } from '@heroicons/react/solid' -import { createDashboard } from 'web/lib/firebase/api' -import { Dashboard } from 'common/dashboard' -import { deleteDashboard, updateDashboard } from 'web/lib/firebase/dashboards' +import { createPost } from 'web/lib/firebase/api' +import { Post } from 'common/post' +import { deletePost, updatePost } from 'web/lib/firebase/posts' import { useRouter } from 'next/router' import { useState } from 'react' -export function GroupDashboard(props: { +export function GroupAboutPost(props: { group: Group isCreator: boolean - dashboard: Dashboard + post: Post }) { - const { group, isCreator, dashboard } = props + const { group, isCreator, post } = props const isAdmin = useAdmin() - if (group.dashboardId == null && !isCreator) { - return

No dashboard has been created

+ if (group.aboutPostId == null && !isCreator) { + return

No post has been created

} return (
{isCreator || isAdmin ? ( - + ) : ( - + )}
) } -function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) { - const { group, dashboard } = props +function RichEditGroupAboutPost(props: { group: Group; post: Post }) { + const { group, post } = props const [editing, setEditing] = useState(false) const [isSubmitting, setIsSubmitting] = useState(false) const router = useRouter() const { editor, upload } = useTextEditor({ - defaultValue: dashboard.content, + defaultValue: post.content, disabled: isSubmitting, }) - async function saveDashboard() { + async function savePost() { if (!editor) return - const newDashboard = { - name: group.name, + const newPost = { + title: group.name, content: editor.getJSON(), } - if (group.dashboardId == null) { - const result = await createDashboard(newDashboard).catch((e) => { + if (group.aboutPostId == null) { + const result = await createPost(newPost).catch((e) => { console.error(e) return e }) await updateGroup(group, { - dashboardId: result.dashboard.id, + aboutPostId: result.post.id, }) } else { - await updateDashboard(dashboard, { - content: newDashboard.content, + await updatePost(post, { + content: newPost.content, }) } await router.replace(router.asPath) } - async function deleteGroupDashboard() { - await deleteDashboard(dashboard) - await deleteFieldFromGroup(group, 'dashboardId') + async function deleteGroupAboutPost() { + await deletePost(post) + await deleteFieldFromGroup(group, 'aboutPostId') await router.replace(router.asPath) } @@ -85,7 +85,7 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) { +

) : ( @@ -126,7 +126,7 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) { color="gray" size="xs" onClick={() => { - deleteGroupDashboard() + deleteGroupAboutPost() }} > @@ -134,7 +134,7 @@ function RichEditGroupDashboard(props: { group: Group; dashboard: Dashboard }) { - + )} diff --git a/web/lib/firebase/groups.ts b/web/lib/firebase/groups.ts index 4815e430..28515a35 100644 --- a/web/lib/firebase/groups.ts +++ b/web/lib/firebase/groups.ts @@ -18,7 +18,6 @@ import { } from './utils' import { Contract } from 'common/contract' import { updateContract } from 'web/lib/firebase/contracts' -import * as admin from 'firebase-admin' export const groups = coll('groups') @@ -30,7 +29,6 @@ export function groupPath( | 'about' | typeof GROUP_CHAT_SLUG | 'leaderboards' - | 'dashboard' ) { return `/group/${groupSlug}${subpath ? `/${subpath}` : ''}` } diff --git a/web/pages/group/[...slugs]/index.tsx b/web/pages/group/[...slugs]/index.tsx index 05e14c47..3bb319ec 100644 --- a/web/pages/group/[...slugs]/index.tsx +++ b/web/pages/group/[...slugs]/index.tsx @@ -45,9 +45,9 @@ import { Button } from 'web/components/button' import { listAllCommentsOnGroup } from 'web/lib/firebase/comments' import { GroupComment } from 'common/comment' import { REFERRAL_AMOUNT } from 'common/economy' -import { GroupDashboard } from 'web/components/groups/group-dashboard' -import { getDashboard } from 'web/lib/firebase/dashboards' -import { Dashboard } from 'common/dashboard' +import { GroupAboutPost } from 'web/components/groups/group-about-post' +import { getPost } from 'web/lib/firebase/posts' +import { Post } from 'common/post' import { Spacer } from 'web/components/layout/spacer' export const getStaticProps = fromPropz(getStaticPropz) @@ -61,10 +61,8 @@ export async function getStaticPropz(props: { params: { slugs: string[] } }) { const contracts = (group && (await listContractsByGroupSlug(group.slug))) ?? [] - const dashboard = - group && - group.dashboardId != null && - (await getDashboard(group.dashboardId)) + const aboutPost = + group && group.aboutPostId != null && (await getPost(group.aboutPostId)) const bets = await Promise.all( contracts.map((contract: Contract) => listAllBets(contract.id)) ) @@ -91,7 +89,7 @@ export async function getStaticPropz(props: { params: { slugs: string[] } }) { creatorScores, topCreators, messages, - dashboard, + aboutPost, }, revalidate: 60, // regenerate after a minute @@ -130,7 +128,7 @@ export default function GroupPage(props: { creatorScores: { [userId: string]: number } topCreators: User[] messages: GroupComment[] - dashboard: Dashboard + aboutPost: Post }) { props = usePropz(props, getStaticPropz) ?? { group: null, @@ -149,7 +147,7 @@ export default function GroupPage(props: { topTraders, creatorScores, topCreators, - dashboard, + aboutPost, } = props const router = useRouter() @@ -187,11 +185,11 @@ export default function GroupPage(props: { const aboutTab = ( - {group.dashboardId != null || isCreator ? ( - ) : (