From 2fef413d88a715b949224908205464eb76112b50 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Sat, 20 Aug 2022 13:46:14 -0500 Subject: [PATCH] Don't show fantasy football in newest sort --- functions/src/scripts/unlist-contracts.ts | 29 +++++++++++++++++++++++ web/components/contract-search.tsx | 4 ++++ 2 files changed, 33 insertions(+) create mode 100644 functions/src/scripts/unlist-contracts.ts diff --git a/functions/src/scripts/unlist-contracts.ts b/functions/src/scripts/unlist-contracts.ts new file mode 100644 index 00000000..12adcedd --- /dev/null +++ b/functions/src/scripts/unlist-contracts.ts @@ -0,0 +1,29 @@ +import * as admin from 'firebase-admin' + +import { initAdmin } from './script-init' +initAdmin() + +import { Contract } from '../../../common/contract' + +const firestore = admin.firestore() + +async function unlistContracts() { + console.log('Updating some contracts to be unlisted') + + const snapshot = await firestore + .collection('contracts') + .where('groupSlugs', 'array-contains', 'fantasy-football-stock-exchange') + .get() + const contracts = snapshot.docs.map((doc) => doc.data() as Contract) + + console.log('Loaded', contracts.length, 'contracts') + + for (const contract of contracts) { + const contractRef = firestore.doc(`contracts/${contract.id}`) + + console.log('Updating', contract.question) + await contractRef.update({ visibility: 'soft-unlisted' }) + } +} + +if (require.main === module) unlistContracts().then(() => process.exit()) diff --git a/web/components/contract-search.tsx b/web/components/contract-search.tsx index feb0de3b..5cb819a9 100644 --- a/web/components/contract-search.tsx +++ b/web/components/contract-search.tsx @@ -258,6 +258,10 @@ function ContractSearchControls(props: { filter === 'open' ? 'isResolved:false' : '', filter === 'closed' ? 'isResolved:false' : '', filter === 'resolved' ? 'isResolved:true' : '', + + // Newest sort requires public visibility. + sort === 'newest' ? 'visibility:public' : '', + pillFilter && pillFilter !== 'personal' && pillFilter !== 'your-bets' ? `groupLinks.slug:${pillFilter}` : '',