|
| 1 | +import { |
| 2 | + GET_USER_RECIPES_VARIABLES, |
| 3 | + GET_USER_SUBSCRIBED_RECIPES_VARIABLES, |
| 4 | + GET_SHARED_RECIPES_VARIABLES, |
| 5 | + GET_USER_COOKBOOKS_VARIABLES, |
| 6 | + GET_USER_SUBSCRIBED_COOKBOOKS_VARIABLES, |
| 7 | + GET_SHARED_COOKBOOKS_VARIABLES, |
| 8 | +} from 'renderer/graphql/variables'; |
| 9 | +import { Language } from 'renderer/lib/constants'; |
| 10 | +import { LanguageEnumeration } from 'renderer/types/assistantTypes'; |
| 11 | +import { useFilters } from '../components/FiltersContext'; |
| 12 | + |
| 13 | +type QueryTypes = |
| 14 | + | 'home' |
| 15 | + | 'my-snippets' |
| 16 | + | 'favorite-snippets' |
| 17 | + | 'team-snippets' |
| 18 | + | 'my-cookbooks' |
| 19 | + | 'favorite-cookbooks' |
| 20 | + | 'team-cookbooks'; |
| 21 | + |
| 22 | +export default function useQueryVariables(query: QueryTypes) { |
| 23 | + const filters = useFilters(); |
| 24 | + |
| 25 | + switch (query) { |
| 26 | + case 'home': |
| 27 | + return { |
| 28 | + howmany: 100, |
| 29 | + skip: 0, |
| 30 | + languages: |
| 31 | + filters.language && filters.language !== Language.ALL_LANGUAGES |
| 32 | + ? ([filters.language] as LanguageEnumeration[]) |
| 33 | + : null, |
| 34 | + dependencies: filters.library ? [filters.library] : null, |
| 35 | + term: filters.searchTerm || null, |
| 36 | + tags: filters.tags ? [filters.tags] : null, |
| 37 | + onlyPrivate: filters.privacy === 'private' ? true : null, |
| 38 | + onlyPublic: filters.privacy === 'public' ? true : null, |
| 39 | + onlySubscribed: filters.isSubscribed || null, |
| 40 | + }; |
| 41 | + |
| 42 | + case 'my-snippets': |
| 43 | + return { |
| 44 | + ...GET_USER_RECIPES_VARIABLES, |
| 45 | + name: filters.searchTerm || null, |
| 46 | + language: |
| 47 | + filters.language && filters.language !== Language.ALL_LANGUAGES |
| 48 | + ? filters.language |
| 49 | + : null, |
| 50 | + tag: filters.tags || null, |
| 51 | + }; |
| 52 | + |
| 53 | + case 'favorite-snippets': |
| 54 | + return { |
| 55 | + ...GET_USER_SUBSCRIBED_RECIPES_VARIABLES, |
| 56 | + name: filters.searchTerm || null, |
| 57 | + }; |
| 58 | + |
| 59 | + case 'team-snippets': |
| 60 | + return { |
| 61 | + ...GET_SHARED_RECIPES_VARIABLES, |
| 62 | + name: filters.searchTerm || null, |
| 63 | + languages: |
| 64 | + filters.language && filters.language !== Language.ALL_LANGUAGES |
| 65 | + ? [filters.language] |
| 66 | + : null, |
| 67 | + tag: filters.tags || null, |
| 68 | + }; |
| 69 | + |
| 70 | + case 'my-cookbooks': |
| 71 | + return { |
| 72 | + ...GET_USER_COOKBOOKS_VARIABLES, |
| 73 | + name: filters.searchTerm || null, |
| 74 | + }; |
| 75 | + |
| 76 | + case 'favorite-cookbooks': |
| 77 | + return { |
| 78 | + ...GET_USER_SUBSCRIBED_COOKBOOKS_VARIABLES, |
| 79 | + name: filters.searchTerm || null, |
| 80 | + }; |
| 81 | + |
| 82 | + case 'team-cookbooks': |
| 83 | + return { |
| 84 | + ...GET_SHARED_COOKBOOKS_VARIABLES, |
| 85 | + name: filters.searchTerm || null, |
| 86 | + }; |
| 87 | + |
| 88 | + default: |
| 89 | + return {}; |
| 90 | + } |
| 91 | +} |
0 commit comments