From bcc011c1fdaba1b525f74bf003262acea56bd16b Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Wed, 9 Feb 2022 10:58:33 -0800 Subject: [PATCH] Allow admins to edit questions --- firestore.rules | 1 + web/components/contract-feed.tsx | 146 +++++++++++++++++++------------ web/hooks/use-admin.ts | 12 +++ web/pages/admin.tsx | 11 +-- 4 files changed, 104 insertions(+), 66 deletions(-) create mode 100644 web/hooks/use-admin.ts diff --git a/firestore.rules b/firestore.rules index 73eafb24..253d57f5 100644 --- a/firestore.rules +++ b/firestore.rules @@ -23,6 +23,7 @@ service cloud.firestore { allow read; allow update: if request.resource.data.diff(resource.data).affectedKeys() .hasOnly(['description', 'tags', 'lowercaseTags']); + allow update: if isAdmin(); allow delete: if resource.data.creatorId == request.auth.uid; } diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index f902ea4e..cf794f74 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -43,6 +43,7 @@ import { fromNow } from '../lib/util/time' import BetRow from './bet-row' import { parseTags } from '../../common/util/parse' import { Avatar } from './avatar' +import { useAdmin } from '../hooks/use-admin' function FeedComment(props: { activityItem: any @@ -154,21 +155,75 @@ function FeedBet(props: { activityItem: any }) { ) } +function EditContract(props: { + text: string + onSave: (newText: string) => void + buttonText: string +}) { + const [text, setText] = useState(props.text) + const [editing, setEditing] = useState(false) + const onSave = (newText: string) => { + setEditing(false) + setText(props.text) // Reset to original text + props.onSave(newText) + } + + return editing ? ( +
+