From b9ae919fdacfe66892afe4f1a5500d2277aa389a Mon Sep 17 00:00:00 2001 From: James Grugett Date: Thu, 8 Sep 2022 16:59:05 -0500 Subject: [PATCH 1/2] Add staleTime option for prefetching --- web/hooks/use-contracts.ts | 7 +++++-- web/hooks/use-portfolio-history.ts | 12 ++++++++---- web/hooks/use-user-bets.ts | 7 ++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/web/hooks/use-contracts.ts b/web/hooks/use-contracts.ts index 4d7d2f79..2f3bea7b 100644 --- a/web/hooks/use-contracts.ts +++ b/web/hooks/use-contracts.ts @@ -13,6 +13,7 @@ import { getUserBetContractsQuery, } from 'web/lib/firebase/contracts' import { useQueryClient } from 'react-query' +import { MINUTE_MS } from 'common/util/time' export const useContracts = () => { const [contracts, setContracts] = useState() @@ -96,8 +97,10 @@ export const useUpdatedContracts = (contracts: Contract[] | undefined) => { export const usePrefetchUserBetContracts = (userId: string) => { const queryClient = useQueryClient() - return queryClient.prefetchQuery(['contracts', 'bets', userId], () => - getUserBetContracts(userId) + return queryClient.prefetchQuery( + ['contracts', 'bets', userId], + () => getUserBetContracts(userId), + { staleTime: 5 * MINUTE_MS } ) } diff --git a/web/hooks/use-portfolio-history.ts b/web/hooks/use-portfolio-history.ts index 1945eb7a..6cc1a84e 100644 --- a/web/hooks/use-portfolio-history.ts +++ b/web/hooks/use-portfolio-history.ts @@ -1,6 +1,6 @@ import { useQueryClient } from 'react-query' import { useFirestoreQueryData } from '@react-query-firebase/firestore' -import { DAY_MS, HOUR_MS } from 'common/util/time' +import { DAY_MS, HOUR_MS, MINUTE_MS } from 'common/util/time' import { getPortfolioHistory, getPortfolioHistoryQuery, @@ -15,8 +15,10 @@ const getCutoff = (period: Period) => { export const usePrefetchPortfolioHistory = (userId: string, period: Period) => { const queryClient = useQueryClient() const cutoff = getCutoff(period) - return queryClient.prefetchQuery(['portfolio-history', userId, cutoff], () => - getPortfolioHistory(userId, cutoff) + return queryClient.prefetchQuery( + ['portfolio-history', userId, cutoff], + () => getPortfolioHistory(userId, cutoff), + { staleTime: 15 * MINUTE_MS } ) } @@ -24,7 +26,9 @@ export const usePortfolioHistory = (userId: string, period: Period) => { const cutoff = getCutoff(period) const result = useFirestoreQueryData( ['portfolio-history', userId, cutoff], - getPortfolioHistoryQuery(userId, cutoff) + getPortfolioHistoryQuery(userId, cutoff), + {}, + { staleTime: 15 * MINUTE_MS } ) return result.data } diff --git a/web/hooks/use-user-bets.ts b/web/hooks/use-user-bets.ts index 8f0bd9f7..3731fb07 100644 --- a/web/hooks/use-user-bets.ts +++ b/web/hooks/use-user-bets.ts @@ -7,10 +7,15 @@ import { getUserBetsQuery, listenForUserContractBets, } from 'web/lib/firebase/bets' +import { MINUTE_MS } from 'common/util/time' export const usePrefetchUserBets = (userId: string) => { const queryClient = useQueryClient() - return queryClient.prefetchQuery(['bets', userId], () => getUserBets(userId)) + return queryClient.prefetchQuery( + ['bets', userId], + () => getUserBets(userId), + { staleTime: MINUTE_MS } + ) } export const useUserBets = (userId: string) => { From 8aeb544f7efc79b3bb55338b19f6a20816edb19c Mon Sep 17 00:00:00 2001 From: marsteralex Date: Thu, 8 Sep 2022 18:38:48 -0700 Subject: [PATCH 2/2] add commander category (#861) * fix https * add beasts * Remove extra file * Prettier-ify code * Prettier-ify * add basic land guesser also added fetcher to filter all cards instead of only unique art * default to original makes basic better * added set symbol to basics added set symbol to the basics game mode. Changed name to "How Basic" * cleanup * changed some pixels * only load set data if needed * hacked fix for removing image from name * removed check from original * remove check from original * sort names by set instead of by set symbol * include battlebond * update cards for categories update for dominaria united * added commander category commander category * update basic land art * can use double feature * removing racist cards upstream this way we don't have to store the cards in the json Co-authored-by: Austin Chen --- web/public/mtg/app.js | 6 ++- web/public/mtg/importCards.py | 22 ++++++----- web/public/mtg/index.html | 55 +++++++++++++++++++++++--- web/public/mtg/jsons/basic.json | 2 +- web/public/mtg/jsons/beast.json | 2 +- web/public/mtg/jsons/burn.json | 2 +- web/public/mtg/jsons/commander.json | 1 + web/public/mtg/jsons/counterspell.json | 2 +- web/public/mtg/jsons/set.json | 2 +- 9 files changed, 73 insertions(+), 21 deletions(-) create mode 100644 web/public/mtg/jsons/commander.json diff --git a/web/public/mtg/app.js b/web/public/mtg/app.js index a2f7679b..2708896a 100644 --- a/web/public/mtg/app.js +++ b/web/public/mtg/app.js @@ -64,6 +64,8 @@ function putIntoMapAndFetch(data) { document.getElementById('guess-type').innerText = 'Finding Fantastic Beasts' } else if (whichGuesser === 'basic') { document.getElementById('guess-type').innerText = 'How Basic' + } else if (whichGuesser === 'commander') { + document.getElementById('guess-type').innerText = 'General Knowledge' } setUpNewGame() } @@ -156,8 +158,8 @@ function determineIfSkip(card) { if (card.flavor_name) { return true } - // don't include racist cards - return card.content_warning + + return false } function putIntoMap(data) { diff --git a/web/public/mtg/importCards.py b/web/public/mtg/importCards.py index 14266c18..17a5e2c2 100644 --- a/web/public/mtg/importCards.py +++ b/web/public/mtg/importCards.py @@ -3,7 +3,7 @@ import requests import json # add category name here -allCategories = ['counterspell', 'beast', 'burn'] #, 'terror', 'wrath'] +allCategories = ['counterspell', 'beast', 'burn', 'commander'] #, 'terror', 'wrath'] specialCategories = ['set', 'basic'] @@ -23,10 +23,12 @@ def generate_initial_query(category): '%2Fcontroller%28%5C.%7C+%29%2F%29+or+o%3A%2F~+deals+%28.%7C..%29+damage+to+%28any+target%7C' \ '.*player%28%5C.%7C+or+planeswalker%29%7C.*opponent%28%5C.%7C+or+planeswalker%29%29%2F%29' \ '+%28type%3Ainstant+or+type%3Asorcery%29+not%3Aadventure' + elif category == 'commander': + string_query += '-banned%3Acommander+is%3Acommander' # add category string query here string_query += '+-%28set%3Asld+%28%28cn>%3D231+cn<%3D233%29+or+%28cn>%3D321+cn<%3D324%29+or+%28cn>%3D185+cn' \ '<%3D189%29+or+%28cn>%3D138+cn<%3D142%29+or+%28cn>%3D364+cn<%3D368%29+or+cn%3A669+or+cn%3A670%29' \ - '%29+-name%3A%2F%5EA-%2F+not%3Adfc+not%3Asplit+-set%3Acmb2+-set%3Acmb1+-set%3Aplist+-set%3Adbl' \ + '%29+-name%3A%2F%5EA-%2F+not%3Adfc+not%3Asplit+-set%3Acmb2+-set%3Acmb1+-set%3Aplist' \ '+language%3Aenglish&order=released&dir=asc&unique=prints&page=' print(string_query) return string_query @@ -51,7 +53,7 @@ def fetch_and_write_all(category, query): response = fetch(query, count) will_repeat = response['has_more'] count+=1 - to_compact_write_form(all_cards, art_names, response, category) + to_compact_write_form(all_cards, art_names, response) with open('jsons/' + category + '.json', 'w') as f: json.dump(all_cards, f) @@ -88,12 +90,14 @@ def fetch_special(query): return response -def to_compact_write_form(smallJson, art_names, response, category): - fieldsInCard = ['name', 'image_uris', 'content_warning', 'flavor_name', 'reprint', 'frame_effects', 'digital', - 'set_type'] +def to_compact_write_form(smallJson, art_names, response): + fieldsInCard = ['name', 'image_uris', 'flavor_name', 'reprint', 'frame_effects', 'digital', 'set_type'] data = [] # write all fields needed in card for card in response['data']: + # do not include racist cards + if 'content_warning' in card and card['content_warning'] == True: + continue # do not repeat art if 'illustration_id' not in card or card['illustration_id'] in art_names: continue @@ -152,9 +156,9 @@ def write_image_uris(card_image_uris): if __name__ == "__main__": - # for category in allCategories: - # print(category) - # fetch_and_write_all(category, generate_initial_query(category)) + for category in allCategories: + print(category) + fetch_and_write_all(category, generate_initial_query(category)) for category in specialCategories: print(category) fetch_and_write_all_special(category, generate_initial_special_query(category)) diff --git a/web/public/mtg/index.html b/web/public/mtg/index.html index b58cc627..bfb324c1 100644 --- a/web/public/mtg/index.html +++ b/web/public/mtg/index.html @@ -17,6 +17,14 @@ f.parentNode.insertBefore(j, f) })(window, document, 'script', 'dataLayer', 'GTM-M3MBVGG') +