Allo creators to unlist markets

This commit is contained in:
Ian Philips 2022-10-03 09:26:39 -06:00
parent 370edec890
commit f92f098f82
4 changed files with 29 additions and 19 deletions

View File

@ -64,6 +64,7 @@ export type Contract<T extends AnyContractType = AnyContractType> = {
likedByUserCount?: number
flaggedByUsernames?: string[]
openCommentBounties?: number
unlistedById?: string
} & T
export type BinaryContract = Contract & Binary

View File

@ -102,7 +102,7 @@ service cloud.firestore {
allow update: if request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['tags', 'lowercaseTags', 'groupSlugs', 'groupLinks']);
allow update: if request.resource.data.diff(resource.data).affectedKeys()
.hasOnly(['description', 'closeTime', 'question'])
.hasOnly(['description', 'closeTime', 'question', 'visibility', 'unlistedById'])
&& resource.data.creatorId == request.auth.uid;
allow update: if isAdmin();
match /comments/{commentId} {

View File

@ -19,7 +19,7 @@ import { deleteField } from 'firebase/firestore'
import ShortToggle from '../widgets/short-toggle'
import { DuplicateContractButton } from '../copy-contract-button'
import { Row } from '../layout/row'
import { BETTORS } from 'common/user'
import { BETTORS, User } from 'common/user'
import { Button } from '../button'
export const contractDetailsButtonClassName =
@ -27,9 +27,10 @@ export const contractDetailsButtonClassName =
export function ContractInfoDialog(props: {
contract: Contract
user: User | null | undefined
className?: string
}) {
const { contract, className } = props
const { contract, className, user } = props
const [open, setOpen] = useState(false)
const [featured, setFeatured] = useState(
@ -37,6 +38,10 @@ export function ContractInfoDialog(props: {
)
const isDev = useDev()
const isAdmin = useAdmin()
const isCreator = user?.id === contract.creatorId
const isUnlisted = contract.visibility === 'unlisted'
const wasUnlistedByCreator =
contract.unlistedById && contract.unlistedById === contract.creatorId
const formatTime = (dt: number) => dayjs(dt).format('MMM DD, YYYY hh:mm a')
@ -175,15 +180,19 @@ export function ContractInfoDialog(props: {
</td>
</tr>
)}
{isAdmin && (
{user &&
(isAdmin ||
(isCreator &&
(isUnlisted ? wasUnlistedByCreator : true))) && (
<tr>
<td>[ADMIN] Unlisted</td>
<td>{isAdmin ? '[ADMIN]' : ''} Unlisted</td>
<td>
<ShortToggle
enabled={contract.visibility === 'unlisted'}
setEnabled={(b) =>
updateContract(id, {
visibility: b ? 'unlisted' : 'public',
unlistedById: b ? user.id : '',
})
}
/>

View File

@ -35,7 +35,7 @@ export function ExtraContractActionsRow(props: { contract: Contract }) {
/>
</Button>
</Tooltip>
<ContractInfoDialog contract={contract} />
<ContractInfoDialog contract={contract} user={user} />
</Row>
)
}